我有一个播放 wav 文件的非常基本的 pyaudio 代码。
open_wave = wave.open("tone_silence/l0r1d0_500.wavc",'rb')
pyAudio_session = pyaudio.PyAudio()
def callback(in_data, frame_count, time_info, status):
data = open_wave.readframes(frame_count)
return (data, pyaudio.paContinue)
pyAudio_stream = pyAudio_session.open(
format = pyAudio_session.get_format_from_width(open_wave.getsampwidth()),
channels = open_wave.getnchannels(),
rate = open_wave.getframerate(),
output = True,
stream_callback=callback)
while pyAudio_stream.is_active():
time.sleep(0.1)
pyAudio_stream.stop_stream()
pyAudio_stream.close()
print("Stopped")
pyAudio_session.terminate()
我已经搜索了互联网的每个角落,以找到一种方法,以便我可以根据需要更改流的分贝级别并将立体声输出平移到特定通道(仅限左扬声器/仅限右扬声器)。但我找不到任何方法。
我无法切换到 pydub(它实际上具有此功能),因为它不允许我随时关闭流;它播放完整的音频,不能突然关闭。