我正在尝试使用 sounddevice 模块播放音频流,我尝试了很多方法,但它们都没有多大意义,似乎根本不适合我,数据 100% 是有效的,如果保存到它播放完美的文件,所以我知道数据没有以任何方式损坏。
import requests
import numpy as np
import sounddevice as sd
url = 'https://audio10.broadcastify.com/dbhq0jtm96yrs78.mp3?nocache=7847116&xan=xtf9912b'
#creates a varable for the url
chunk_size = 256 *4
#chunk size
r = requests.get(url, stream = True)
#uses requests.get to get data from link
for chunk in r.iter_content(chunk_size=chunk_size):
#grabs the audio content of the web page with the r varable and putting it into the chunk varable as byte data
chunk = np.frombuffer(chunk, dtype=np.int8)
#turns the chunk byte data into an array
print(chunk)
#prints the chunk data to show the result
#somehow use the soundevice module to play back the audio stream? but i dont know how?
#the only clue that i have is that i cant use sd.play(chunk) because the play function isnt
#able to play stream data like that