使用 Python 进行流式传输之前提高音量
Increase volume before streaming with Python
这里我们有一个使用 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 的情况下将音频流式传输到扬声器之前提高音量?
使用 soundfile and sounddevice 模块怎么样?
import soundfile as sf
import sounddevice as sd
weight = 1.7
data, fs = sf.read('myfile.wav')
sd.play(data * weight, fs, blocking=True)
这里我们有一个使用 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 的情况下将音频流式传输到扬声器之前提高音量?
使用 soundfile and sounddevice 模块怎么样?
import soundfile as sf
import sounddevice as sd
weight = 1.7
data, fs = sf.read('myfile.wav')
sd.play(data * weight, fs, blocking=True)