Volume Skill not working on Picroft Stretch


I have installed fresh the image Picroft Stretch on a Raspberry Pi 3B+ with usb mic and speakers through the jack.
All sound is working great except that it gives error to control the Volume via speaking by using Volume skill.

Picroft - stretch 2018-09-13
Mycroft - 18.8.1
Mic - usb mic
Speakers via jack 3.5mm

Content of audio_setup.sh works fine and possible to set different volume levels by :
sudo amixer cset numid=3 “1” > /dev/null
amixer set PCM 99%

It is also possible to set different output sound level via the command line with ‘amixer set PCM xx%’ command.

However, by speaking to Mycroft and requesting to set a volume level, there is a crash/error in the Volume Skill. Log Output of mycroft-cli:

22:34:00.615 - main:handle_record_begin:35 - INFO - Begin Recording…
Playing WAVE ‘/home/pi/mycroft-core/mycroft/res/snd/start_listening.wav’ : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
22:34:03.423 - main:handle_record_end:40 - INFO - End Recording…
22:34:03.432 - main:handle_wakeword:56 - INFO - Wakeword Detected: hey mycroft
22:34:05.373 - main:handle_utterance:61 - INFO - Utterance: [‘set the volume to 5’]
22:34:05.581 - mycroft.skills.core:wrapper:716 - ERROR - An error occurred while processing a request in Volume Skill
Traceback (most recent call last):
File “/home/pi/mycroft-core/mycroft/skills/core.py”, line 707, in wrapper
File “/opt/mycroft/skills/mycroft-volume.mycroftai/init.py”, line 95, in handle_set_volume
level = self.__get_volume_level(message, self.mixer.getvolume()[0])
AttributeError: ‘VolumeSkill’ object has no attribute ‘mixer’
^— NEWEST —^

Thanks for the support.

Excellent job for the project.

I had a issue with the Volume Skill after I configured “Pycroft 2018-09-12 Stretch Lightning” to use a USB based speaker. While the error message you have provided is not the same, it may have the same root cause for you to pursue.

What I found when I used a USB based speaker was the mixer control name used for the USB speaker did not match the default mixer control name used by the initialisation of the alsasound.Mixer() object in the Volume Skill code.

On the Pycroft, the Volume Skill initialisation is to be found at: /opt/mycroft/skills/mycroft-volume.mycroftai/__init__.py

If you can read python, you will see that it uses the Mixer class from the alsaaudio module. The documentation describes this class.

class alsaaudio.Mixer(control='Master', id=0, cardindex=-1, device='default')

Arguments are:
    control - specifies which control to manipulate using this mixer object. 
    The list of available controls can be found with the alsaaudio.mixers() function. 
    The default value is 'Master' - other common controls may be 'Master Mono', 'PCM', 'Line', etc.

You can check your mixer control name with the command.

more /etc/asound.conf

As an example this file is here. You can see this USB harware mixer control name is ‘pcm’.

pcm.!default {
  type plug
  slave {
    pcm "hw:0,0"

ctl.!default {
    type hw           
    card 0

In the file /opt/mycroft/skills/mycroft-volume.mycroftai/__init__.py, here is the responsible code. In lines 44 to 57:-

def __init__(self):
    super(VolumeSkill, self).__init__("VolumeSkill")
    self.default_level = self.config.get('default_level')
    self.min_volume = self.config.get('min_volume')
    self.max_volume = self.config.get('max_volume')
    self.volume_sound = join(dirname(__file__), "blop-mark-diangelo.wav")
        self.mixer = Mixer()
    except Exception:
        # Retry instanciating the mixer
            self.mixer = Mixer()
        except Exception as e:
            self.log.error('Couldn\'t allocate mixer, {}'.format(repr(e)))

I put a work around by over riding the control=Master default and specifying the mixer control name to be PCM. This can be done by changing line 51:

self.mixer = Mixer()


self.mixer = Mixer('PCM')

A proper fix may be to the rename the USB based hardware Mixer name to ‘Master’.

I did notice two side effects:
1. Some error messages about various speaker configuration were presented when the Skill Volume was started. So far it appears I was able to safely ignore these.
2. Pycroft was aware of the change and would no longer automatically use GIT for upgrades to this Skill.

Overall, I plan to purse this (when time is available) to see if I can set the mixer control name for USB based hardware to Master correctly and will post an answer if I can sort it out.

Give it a go and see if it helps
Good Luck.

Thanks, that seems to be shedding some light into this problem. I’ll try it later with changing the alsa to Master, I don’t think we should be changing this within the Skill if that is the problem.

Also, in addition I found that the Picroft code is also not consistent:
In auto_run.sh, the way to set volume uses PCM: amixer set PCM “${lvl}9%”
In audio_setup.sh (which is called from auto_run and is recommended to get things at startup the way you prefer), the way to set volume gives example using Master: amixer set Master 75%

Clearly, in my setup PCM is working to control volume and Master is not.

I’ll update if I’m successful on setting alsa to Master but then the auto_run.sh script in the Picroft image needs also to be changed accordingly.

Hi again @djl
I have attempted to re-name the playback control name from PCM to Master to fit the Volume skill python code but I was not successful.

You have pointed to the correct issue, the call in Volume skills calls simply self.mixer = Mixer() leaving the default value of control to Master. However, the configuration of ALSA in Picroft sets the name of the ALSA controller as PCM.
Not sure how others using the Picroft image have the Volume skill working or probably no-one had tested yet.

I’ll need to wait for someone with more Alsa experience to take a look. I’m out of depth to fix.

1 Like

I noticed the issue with the same symptoms with the guided setup for Stretch Lightning release.
amixer: Cannot find the given element from control default.
amixer: Mixer default load error: Invalid argument.

Running on RPi 3B+ with PS Eye and USB speakers.

This topic was vaguely similar, so that’s how I landed here.
Tell me if this is not related.

Is there a tracking bug for this? The volume service is currently not working on picroft.

Check github, and if not, file one?

Must not have had any effect. I just installed and fully updated the latest of everything on a RPi 4 and requests to adjust the volume STILL don’t work on Picroft. SO sad that we have to go to the command line to fix even simple things like this.