As of this writing (May 2023) CircuitPython has no way of boosting the volume of an audio file during playback. The 'level' parameter goes from 0 to 1, meaning you can turn stuff down, but not up.
In situations where audio is being downloaded from outside sources, as in The Positivity Pusher, it would be useful to have the ability to apply additional gain in software. We just don't have that ability.
A Bad but Functional Workaround
In CircuitPython, you can play single clips, and also 'mixer objects', which can simultaneously play multiple clips. My original idea was to make a mixer and play the clip twice at the same time.
For unknown reasons, this doesn't work. The clip(s) play but with missing chunks.
What does work is creating two identical clips and playing then both in the mixer. The execution looks something like:
from audiopwmio import PWMAudioOut import audiomixer from audiomp3 import MP3Decoder audio = PWMAudioOut(board.GP21) mixer = audiomixer.Mixer(buffer_size=1024, voice_count=2, sample_rate=10000, channel_count=1, bits_per_sample=16, samples_signed=True) theClip = MP3Decoder('clip.mp3') theClip2 = MP3Decoder('clip.mp3') audio.play(mixer) mixer.voice.level = 1 mixer.voice.level = 1 mixer.voice.play(theClip) mixer.voice.play(theClip2)
This method uses twice the memory because it loads the same MP3 into RAM two separate times. Additionally, the resulting volume boost is a modest but noticeable 6dB. Perceptively speaking, it does not "double" the volume in the sense of making the speaker twice as loud as it was before. In the case of the Positivity Pusher, this method raises the volume from a level that requires leaning in to hear, to a level that can be comfortably heard while the button is sitting on a desk and the user is sitting or standing nearby.
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.