无需写入文件即可播放mp3原始音频数据

时间:2017-01-25 13:29:48

标签: python python-3.x audio mp3 raw-data

我想知道如何播放mp3原始音频数据(从Ivona文本到语音API检索),而无需将其写入文件。

我是否必须将其转换为wav并使用pyaudio

1 个答案:

答案 0 :(得分:0)

这是一种方法:

from urllib.request import urlopen
import pyaudio

pyaud = pyaudio.PyAudio()
srate=44100
stream = pyaud.open(format = pyaud.get_format_from_width(1),
                channels = 1,
                rate = srate,
                output = True)


url = ... # Assuming you retrive audio data from an URL
u = urlopen(url)
data = u.read(8192)

while data:
    stream.write(data)
    data = u.read(8192)

供参考,请参阅How to play mp3 from URL

希望这有帮助!