[英]Windows (XP to Windows 7) audio playback with python?
Anyone have experience playing audio (right now specifically mp3s) with python using a any libs? 任何人都有使用任何库使用python播放音频(现在是mp3)的经验吗?
Details: 细节:
Use is in a wxPython app (yes I have tried wx.media.MediaCtrl) 使用在wxPython应用程序中(是的,我已经尝试过wx.media.MediaCtrl)
Ok now is here things I have tried. 好了,现在是我尝试过的东西。
tried code like http://www.daniweb.com/software-development/python/code/216465/play-mp3-files-via-pythons-win32com-support 尝试过的代码,例如http://www.daniweb.com/software-development/python/code/216465/play-mp3-files-via-pythons-win32com-support
Doesn't work (no audio what so ever) 不起作用(以前没有声音)
tried wxPython MediaCtrl: Works sometimes but recently only file playback works, urls play for a couple seconds and then no audio (but track keeps going, I know the file is downloaded fully also so it isn't the media not being downloaded). 尝试了wxPython MediaCtrl:有时可以工作,但是最近只能播放文件,url播放了几秒钟,然后没有音频(但是音轨一直在继续,我知道文件也已完全下载,因此不是未下载媒体)。 I was able to fix this with restarting then it worked for a bit then broke, tried restarting again and this time that didn't fix it, however other player that use windows media apis (a C# .NET app) work just fine and so does Windows Media Player.
我能够通过重新启动来解决此问题,然后重新工作了一段时间,然后坏了,尝试再次重新启动,这次没有解决问题,但是使用Windows Media API(C#.NET应用程序)的其他播放器工作正常,因此Windows Media Player。 So it is some bug in the wxWidgets libs I guess
所以我猜这是wxWidgets库中的一些错误
tried using mplayer, example: http://www.blog.pythonlibrary.org/2010/07/24/wxpython-creating-a-simple-media-player/ major problems mplayer doesn't like setting properties and so I can't ever pause because if I do it then won't let me set the state back to play (see code I use here http://paste.pocoo.org/show/574269/ ) 尝试使用mplayer,例如: http : //www.blog.pythonlibrary.org/2010/07/24/wxpython-creating-a-simple-media-player/主要问题mplayer不喜欢设置属性,因此我可以永远不要暂停,因为如果我这样做了,那么就不会让我重新设置播放状态(请参阅我在此处使用的代码http://paste.pocoo.org/show/574269/ )
On Linux I have used gstreamer, works after some headaches (though still has its problems also), MacOS X hasn't been tested yet but I am going to try quicktime and wx.media.MediaCtrl hoping that works) 在Linux上,我使用了gstreamer,虽然有些头痛(尽管仍然有一些问题),但仍可以工作,但尚未测试MacOS X,但我将尝试使用quicktime和wx.media.MediaCtrl,希望可以工作)
I've used PortAudio in a couple of projects, which is a free-cross-platform-open-source-audio library, but never with python. 我在几个项目中使用了PortAudio ,这是一个免费的跨平台,开放源音频库,但从来没有使用python。 Don't worry, there are bindings for it:
不用担心,这里有绑定:
PyAudio provides Python bindings for PortAudio. PyAudio为PortAudio提供Python绑定。
""" Play a WAVE file. """
import pyaudio
import wave
import sys
chunk = 1024
if len(sys.argv) < 2:
print "Plays a wave file.\n\n" +\
"Usage: %s filename.wav" % sys.argv[0]
sys.exit(-1)
wf = wave.open(sys.argv[1], 'rb')
p = pyaudio.PyAudio()
# open stream
stream = p.open(format =
p.get_format_from_width(wf.getsampwidth()),
channels = wf.getnchannels(),
rate = wf.getframerate(),
output = True)
# read data
data = wf.readframes(chunk)
# play stream
while data != '':
stream.write(data)
data = wf.readframes(chunk)
stream.close()
p.terminate()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.