Python 使用解码器和加法器
我试图创建一个音频流,它有一个恒定的音频源(在本例中为audiotestsrc),我可以偶尔通过play_file()方法向其中添加来自文件(各种格式,这就是为什么我使用decodebin)的声音。为此我使用加法器。但是,由于某些原因,我无法正确添加第二个声音。程序不仅错误地播放声音,而且完全停止了原始的audiotestsrc。以下是我目前的代码:Python 使用解码器和加法器,python,gstreamer,Python,Gstreamer,我试图创建一个音频流,它有一个恒定的音频源(在本例中为audiotestsrc),我可以偶尔通过play_file()方法向其中添加来自文件(各种格式,这就是为什么我使用decodebin)的声音。为此我使用加法器。但是,由于某些原因,我无法正确添加第二个声音。程序不仅错误地播放声音,而且完全停止了原始的audiotestsrc。以下是我目前的代码: import gst; import gobject; gobject.threads_init() pipe = gst.Pipeline()
import gst; import gobject; gobject.threads_init()
pipe = gst.Pipeline()
adder = gst.element_factory_make("adder", "adder")
first_sink = adder.get_request_pad('sink%d')
pipe.add(adder)
test = gst.element_factory_make("audiotestsrc", "test")
test.set_property('freq', 100)
pipe.add(test)
testsrc = test.get_pad("src")
testsrc.link(first_sink)
output = gst.element_factory_make("alsasink", "output")
pipe.add(output)
adder.link(output)
pipe.set_state(gst.STATE_PLAYING)
raw_input('Press key to play sound')
def play_file(filename):
adder_sink = adder.get_request_pad('sink%d')
audiofile = gst.element_factory_make('filesrc', 'audiofile')
audiofile.set_property('location', filename)
decoder = gst.element_factory_make('decodebin', 'decoder')
def on_new_decoded_pad(element, pad, last):
pad.link(adder_sink)
decoder.connect('new-decoded-pad', on_new_decoded_pad)
pipe.add(audiofile)
pipe.add(decoder)
audiofile.link(decoder)
pipe.set_state(gst.STATE_PAUSED)
pipe.set_state(gst.STATE_PLAYING)
play_file('sample.wav')
while True:
pass
多亏了moch on#gstreamer,我意识到所有加法器源都应该具有相同的格式。我修改了上面的脚本,使caps“audio/x-raw-int,endianness=(int)1234,channels=(int)1,width=(int)16,depth=(int)16,signed=(boolean)true,rate=(int)11025”
(示例)在加法器中的每个输入之前