音乐播放器核心python模块
musicplayer的Python项目详细描述
这个python模块提供了一个高级的核心音乐播放器接口,您可以在其中提供所有剩余的高级逻辑,比如用户接口、播放列表逻辑和音频数据。
示例
一个非常简单的无间隙播放播放器:
importmusicplayer,sys,os,fnmatch,random,pprint,TkinterclassSong:def__init__(self,fn):self.url=fnself.f=open(fn)# `__eq__` is used for the peek stream managementdef__eq__(self,other):returnself.url==other.url# this is used by the player as the data interfacedefreadPacket(self,bufSize):returnself.f.read(bufSize)defseekRaw(self,offset,whence):r=self.f.seek(offset,whence)returnself.f.tell()files=[]defgetFiles(path):forfinsorted(os.listdir(path),key=lambdak:random.random()):f=os.path.join(path,f)ifos.path.isdir(f):getFiles(f)# recurseiflen(files)>1000:break# break if we have enoughiffnmatch.fnmatch(f,'*.mp3'):files.append(f)getFiles(os.path.expanduser("~/Music"))random.shuffle(files)# shuffle some morei=0defsongs():globali,fileswhileTrue:yieldSong(files[i])i+=1ifi>=len(files):i=0defpeekSongs(n):nexti=i+1ifnexti>=len(files):nexti=0returnmap(Song,(files[nexti:]+files[:nexti])[:n])# Create our Music Player.player=musicplayer.createPlayer()player.outSamplerate=96000# support high quality :)player.queue=songs()player.peekQueue=peekSongs# Setup a simple GUI.window=Tkinter.Tk()window.title("Music Player")songLabel=Tkinter.StringVar()defonSongChange(**kwargs):songLabel.set(pprint.pformat(player.curSongMetadata))defcmdPlayPause(*args):player.playing=notplayer.playingdefcmdNext(*args):player.nextSong()Tkinter.Label(window,textvariable=songLabel).pack()Tkinter.Button(window,text="Play/Pause",command=cmdPlayPause).pack()Tkinter.Button(window,text="Next",command=cmdNext).pack()player.onSongChange=onSongChangeplayer.playing=True# start playingwindow.mainloop()
说明
它提供了一个表示播放器的播放器对象。它需要一个生成器player.queue生成song对象,这些对象提供读取文件数据和在文件中查找的方法。请参阅源代码以获取进一步的详细参考。
它具有以下功能:
- 开源(简化的bsd许可证,请参见License.txt)
- 非常简单的界面
- 支持最重要的声音格式(MP3、FLAC、Ogg Vorbis、WMA、AAC/ALAC M4A,…)
- 通过播放器对象播放音频数据。使用FFmpeg进行解码,使用PortAudio进行播放。
- 当然,解码和回放是在单独的线程中完成的。你可以读到这些here。
- 通过player.outSamplerate支持任何采样率。首选的声音设备是通过player.preferredSoundDevice设置的。通过getSoundDevices()获取所有声音设备的列表。
- 可以通过player.volume和song.gain修改卷(有关详细信息,请参阅源代码)。
- 通过平滑限制函数防止剪辑,该函数仍保留大多数声音不受影响并保持动态范围(请参见smoothClip)。
- ReplayGain(音频音量标准化)(请参见pyCalcReplayGain)。据我所知,这是replaygain唯一的另一个实现,尽管它来自mp3gain(gain_analysis.c)。
- AcoustId音频指纹(请参见pyCalcAcoustIdFingerprint)。这个也被MusicBrainz使用。它使用Chromaprint库来实现。
- 提供访问歌曲元数据的简单方法。
- 提供了一种计算歌曲可视缩略图的方法,该缩略图显示每次频率的振幅和光谱质心(请参见pyCalcBitmapThumbnail)。灵感来自this project。
- Gapless playback
用法
主要用途可能是MusicPlayer project-一个功能齐全的高质量音乐播放器。
安装
要使源工作,您需要以下要求:
- 增压>;=1.55.0
- ffmpeg>;=2.0(包括libswresample)
- Portaudio=v19
- 色度
debian/ubuntu
apt-get install python-dev libsnappy-dev libtool yasm libchromaprint-dev portaudio19-dev libboost-dev
debian/ubuntu中的ffmpeg太旧(缺少libswresample),所以也要这样做:
add-apt-repository ppa:jon-severinsson/ffmpeg apt-get update apt-get install libavformat-dev libswresample-dev
或者从源安装。
macosx
brew install boost brew install portaudio brew install ffmpeg brew install chromaprint
其他注释
Chromaprint依赖于ffmpeg,因此如果您有一个自定义的ffmpeg安装,您可能还希望手动安装。./configure && make && sudo make install应该适用于ffmpeg和portaudio。您可能还想对ffmpeg使用--enable-shared。cmake . && sudo make install用于chromaprint。)
建筑
然后调用python setup.py build或./compile.py来构建python模块(它将构建python模块musicplayer.so)。
该模块也已注册on PyPI,因此您也可以通过:
easy_install musicplayer
类似项目
- overview在python wiki中:Audio modules和Music software。
- PyAudio。麻省理工学院执照。Portaudio包装。因此,相当低的水平和没有解码功能。2012年最后一次更新。
- PyFFmpeg。LGPL公司。ffmpeg包装。因此,音量很低,没有声音输出。你也许可以把pyffmpeg和pyaudio粘在一起,以获得一些有用的东西,但我希望它非常不稳定,而且太慢。基本上,TIS胶是用C++在这个模块中完成的。
- GStreamer Python Bindings。gstreamer功能强大,但作为一个跨平台的音乐播放器后端解决方案仍然太有限。相当重。那是我的直觉。也许这是错误的,这是一个完美的解决方案。但我认为,与此相反,这个模块以更紧凑、自动/更简单的方式做了很多事情,同时提供了更多以音乐播放器为中心的功能s.
- Beets。它的核心是音乐库管理器,对元数据进行管理。它可以计算出重放呼吸和声纹。通过bpd插件,它成为一个基于gstreamer的mpd兼容的守护进程播放器。
可能是死项目: