1.播放器playsound
https://pypi.org/project/playsound/
1 2 3 |
pip3 install playsound from playsound import playsound playsound("m.mp3") |
2.播放simpleaudio
https://pypi.org/project/simpleaudio/
1 2 3 4 5 |
pip3 install simpleaudio import simpleaudio wave = simpleaudio.WaveObject.from_wave_file("w.wav") player = wave.play() player.wait_done() |
3.播录机pyaudio
https://pypi.org/project/PyAudio/
https://pypi.org/project/PyWave/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
brew install portaudio # MacOS须先安装这个 pip3 install PyAudio pip3 install PyWave import pyaudio import PyWave wave = PyWave.open("w.wav") player=PyAudio() stream=player.open( format=wave.format, channels=wave.channels, rate=wave.frequency, output=True) while True: data=wave.read_samples(1024) if data=="": wave.close() break stream.write(data) stream.stop_stream() # 停止数据流 stream.close() player.terminate() # 关闭 PyAudio |
4.文字转音频gtts
https://pypi.org/project/gTTS/
1 2 3 4 |
pip3 install gTTS from gtts import gTTS tts = gTTS('hello', slow=False) tts.save('hello.mp3') |
5.文字转音频pyttsx3
https://pypi.org/project/pyttsx3/
1 2 3 4 5 |
pip3 install pyttsx3 import pyttsx3 engine = pyttsx3.init() engine.say("I will speak this text") engine.runAndWait() |
6.音频分析库librosa结合ipython音频播放
https://pypi.org/project/librosa/
1 2 3 4 5 6 |
pip3 install librosa import IPython.display as ipd import librosa x , sr = librosa.load("w.wav", sr=44100) # ipd.Audio(audio_path) ipd.Audio(x, rate=sr) |
7.游戏库pygame中的音频播放器mixer
https://pypi.org/project/pygame/
1 2 3 4 5 |
pip install pygame from pygame import mixer mixer.init() mixer.music.load("m.mp3") mixer.music.play() |
8.文件属性操作
https://eyed3.readthedocs.io/en/latest/
eyeD3 是一个 Python 程序和模块,提供了读写 ID3 标签 (v1.x 和 v2.3/v2.4) 的功能。同时可检测 MP3 文件的头信息,包括比特率、采样频率和播放时间等。
-end
声明
本文由崔维友 威格灵 cuiweiyou vigiles cuiweiyou 原创,转载请注明出处:http://www.gaohaiyan.com/2796.html
承接App定制、企业web站点、办公系统软件 设计开发,外包项目,毕设