Close

Volume Control Driving Me Poetty

A project log for VoiceBox

Adding a Flask web interface (and other stuff) to the Google AIY Voice Kit.

tmTM 08/13/2018 at 20:230 Comments

I was having trouble changing the volume after turning music off (it seems that mpd stop drops the daemon's connection to PulseAudio). A search for the mpc error "problems setting volume" took me to an ancient archlinux.org thread which recommended adding  mixer_type "software" to /etc/mpd.conf. So I changed the pulse part of my mpd.conf to:

audio_output {
    type          "pulse"
    name          "My Pulse Output"
    mixer_type    "software"
}

With the "software" setting, mpd output volume is muted: I had to turn the volume up to 100 to match the previous volume at 50. (I suspect it's a dB vs percentage thing, or that the VoiceHat hardware amp is being bypassed.) So back to the drawing board.

After an hour ritually cursing Lennart Poettering, and five minutes reading the pacmd man page, I realized that perhaps failing to change volume when music isn't playing isn't entirely unreasonable behavior. Maybe, just maybe, I ought to change my code. So now setVolume() checks whether music is playing before attempting to change the volume.

# Set and display music volume
def setVolume(volume):
    if not connectMPD(): return
    try:
        if mpdState() == 'stop': music('on')
        mpc.setvol(volume)
        displaySplitText(1, 'Volume: '+str(mpc.status()['volume']))
    except Exception as e:
        print('Error setting music volume: '+str(e))
        aiy.audio.say('Error setting music volume')

 Sorry Lennart.

That feel when you dodge putting in the effort to understand the Linux sound system, again.

Discussions