这里我们有一个普通的代码,用于使用PyAudio来传输来自wav文件的音频:
def play_sound(sound):
CHUNK = 1024
wf = wave.open(sound, 'rb')
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
data = wf.readframes(CHUNK)
while len(data) > 0:
stream.write(data)
data = wf.readframes(CHUNK)
stream.stop_stream()
stream.close()
p.terminate()
return True
如何在不使用PyDub的情况下将音频流传输到扬声器之前增加音频音量?
答案 0 :(得分:0)
使用Shah's answer和soundfile模块怎么样?
import soundfile as sf
import sounddevice as sd
weight = 1.7
data, fs = sf.read('myfile.wav')
sd.play(data * weight, fs, blocking=True)