Currently using Raspberry Pi 3, pyaudio , ReSpeaker 2-Mics Pi HAT
How do I adjust the volume of the .wav file playing using python in RPI? ( the output is through respeaker 3.5mm audio jack connected by an earpiece)
I need the RPI to play and adjust the volume dynamically without needing me to change it manually
Not accessing the alsamixer using the command in command prompt. Need some advice on how to proceed.
Below is the current progress of my code ( this code will be in a while loop playing ) :
filename ="output.wav"
RESPEAKER_RATE = 16000
RESPEAKER_CHANNELS = 2
RESPEAKER_WIDTH = 2
RESPEAKER_INDEX = 0
chunk = 1024
wf = wave.open(filename, 'rb')
p = pyaudio.PyAudio()
stream = p.open(
format = p.get_format_from_width(RESPEAKER_WIDTH),
channels = RESPEAKER_CHANNELS,
rate = RESPEAKER_RATE,
output = True
)
data = wf.readframes(chunk)
while data != '':
stream.write(data)
data = wf.readframes(chunk)
stream.stop_stream()
stream.close()
p.terminate()
Tried this code but not really what I am trying to achieve
Trying to change it whilst it is playing rather than changing it before
from pydub import AudioSegment
song = AudioSegment.from_wav("output.wav")
song = song - 60
quieter_song_data = song.get_array_of_samples()
quieter_song_fs = song.frame_rate4
from Python RPI : How do i dynamically adjust the volume of my wav file currently playing
No comments:
Post a Comment