Python Gstreamer录制来自麦克风的音频并立即播放 [英] Python Gstreamer record audio from mic and play immediately

查看:107
本文介绍了Python Gstreamer录制来自麦克风的音频并立即播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想录制来自麦克风的音频,并立即使用gstreamer从同一台PC的扬声器播放音频.换句话说;在输入和输出之间建立连线几个样本,然后立即播放.我可以使用以下代码将音频记录到ogg文件中:

I want to record audio from mic and play it immediately from same pc's speakers using gstreamer. In other words; make a wire between input and output record a few samples and play them back immediately. I can record audio to an ogg file with this code:

#!/usr/bin/env python
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst, Gtk
GObject.threads_init()
Gst.init(None)

pipeline = Gst.Pipeline()

autoaudiosrc = Gst.ElementFactory.make("autoaudiosrc", "autoaudiosrc")
audioconvert = Gst.ElementFactory.make("audioconvert", "audioconvert")
vorbisenc = Gst.ElementFactory.make("vorbisenc", "vorbisenc")
oggmux = Gst.ElementFactory.make("oggmux", "oggmux")
filesink = Gst.ElementFactory.make("filesink", "filesink")
url = "1.ogg"
filesink.set_property("location",url)
pipeline.add( autoaudiosrc)
pipeline.add( audioconvert)
pipeline.add( vorbisenc)
pipeline.add( oggmux)
pipeline.add( filesink)

autoaudiosrc.link( audioconvert)
audioconvert.link( vorbisenc)
vorbisenc.link( oggmux)
oggmux.link( filesink)

pipeline.set_state(Gst.State.PLAYING)
Gtk.main()

但是在录制时如何播放音频?

But how can i play the audio while recording?

推荐答案

音频转换后,您可以添加一个T恤并排队以拥有一个新的分支.您可以拥有类似的东西:

After audioconvert, you can add a tee and queue to have a new branch. You can have something like that:

autoaudiosrc ! audioconvert ! tee name="source" ! queue ! vorbisenc ! oggmux ! filesink location=file.ogg source. ! queue ! audioconvert ! alsasink

这篇关于Python Gstreamer录制来自麦克风的音频并立即播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆