I have a pretty basic pyaudio code that plays a wav file.
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()
I have searched every corner of the internet to find a way such that I can change the Decibel level of the stream and pan the stereo output to a specific channel (left speaker only/right speaker only) as per need. But I could not find any method.
I cannot shift to pydub (which actually has this features) because it does not let me close the stream at any time; it plays the full audio and cannot be closed abruptly.