当我们在 Python 代码中使用图片时,PIL 可以帮助我们获取可以作为列表访问的 RGB 值。我想通过在 Python 中使用 GStreamer 来做类似的事情(从给定信号中获取数值)。我看攻略对了here但他只字不提在管道中保存信号或从中获取数值。
Gstreamer 能做到吗?如果是这样:谁能给我提供一个从 Gstreamer 获取数值的简短教程?
请您参考如下方法:
这是从另一个 SO 答案中截取的代码,它使用 python 播放给定一些 URL 的流音频
import pygst
import gst
def on_tag(bus, msg):
taglist = msg.parse_tag()
print 'on_tag:'
for key in taglist.keys():
print '\t%s = %s' % (key, taglist[key])
#our stream to play
music_stream_uri = 'http://mp3channels.webradio.antenne.de/chillout'
#creates a playbin (plays media form an uri)
player = gst.element_factory_make("playbin", "player")
#set the uri
player.set_property('uri', music_stream_uri)
#start playing
player.set_state(gst.STATE_PLAYING)
#listen for tags on the message bus; tag event might be called more than once
bus = player.get_bus()
bus.enable_sync_message_emission()
bus.add_signal_watch()
bus.connect('message::tag', on_tag)
#wait and let the music play
raw_input('Press enter to stop playing...')
here is the SO answer where this was nicked from
这会让你开始......然后就是找到什么 API 调用可以让你访问流式音频缓冲区
.... audioread看起来充满希望
来自其文档
with audioread.audio_open(filename) as f:
print(f.channels, f.samplerate, f.duration)
for buf in f:
do_something(buf)
