在使用Python进行流式处理之前增

时间:2016-05-19 13:35:04

标签: python python-2.7 audio volume pyaudio

这里我们有一个普通的代码,用于使用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的情况下将音频流传输到扬声器之前增加音频音量?

1 个答案:

答案 0 :(得分:0)

使用Shah's answersoundfile模块怎么样?

import soundfile as sf
import sounddevice as sd

weight = 1.7

data, fs = sf.read('myfile.wav')
sd.play(data * weight, fs, blocking=True)