Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Audio setup & debugging

René Kliment edited this page Nov 27, 2016 · 42 revisions

Setting up your devices

If you want to change your playback / recording device (also because the default setting doesn't work for you), you can do that in the configuration file. If you installed into /opt as recommended, it is /etc/opt/AlexaPi/config.yaml. If you installed elsewhere, the file config.yaml is in your AlexaPi/src directory.

You may need to adjust the volume and/or input gain for the microphone, you can do this with alsamixer. Once the adjustments have been made, you can save the settings using alsactl store.

Debugging your setup

If there is an error in your log file complaining about alsaaudio you may need to check the name of your sound card input device.

These errors might look like this:

alsaaudio.ALSAAudioError: Device or resource busy [plughw:1]

alsaaudio.ALSAAudioError: No such file or directory [plughw:1]

However, make sure that no other application is using your sound card and that your playback / recording works with other applications.

  1. To test playback, run aplay /usr/share/sounds/alsa/Front_Center.wav
  2. To rest recording, run arecord -D yourdevice test.wav - exit with CTRL+C and aplay test.wav

Selecting the device default for input and / or output often works.

You can use these commands to figure out your device names (look for the "plughw:" line):

arecord -l
arecord -L
aplay -l
aplay -L

Audio debugging script

To help in debugging and tracking down audio issues, please use the following command as a standard form of data collection:

cd ~ && wget https://raw.githubusercontent.com/alexa-pi/AlexaPi-misc/master/alsa-info.sh && bash alsa-info.sh

This site has some good information regarding alsa: http://www.volkerschatz.com/noise/alsa.html

If you can't figure it out yourself, be sure to post the output of those commands when asking for help

Raspberry Pi-specific

HDMI Audio

If you are using HDMI out and are losing the first part of audio playback try running vcgencmd force_audio hdmi 1. See the Raspberry Pi section in Devices for details.

Arch Linux

The internal audio is not enabled by default in Arch Linux see the Raspberry Pi/Audio section in Arch wiki on how to do that manually.

External DAC Support

Some external DACs might have issues with the default Device Platform configuration. This may or may not include an unresponsive audio system with no sign of normal ALSA audio errors. The HiFiBerry DAC+ for example needs GPIO pins of its' own to receive audio from your pi. The default platform config uses PIN 18 as an optional button, which is one of the same pins used by the DAC to communicate.

Make these pin numbers don't overlap with your DAC's pinout:

  raspberrypi:
    button: 7
    plb_light: 24
    rec_light: 25

Alternatively, if you don't need a button, nor LEDs, you can just use the dummy device platform and it won't touch your GPIO at all.

PulseAudio

You might get errors regarding PulseAudio. This is very probably due to the fact that you're running a GUI installation of your OS with PA in session mode and you want to run AlexaPi as a daemon under another user. Unfortunately things don't work like this, because this way PA is there only for the user pi.

This is still experimental. We're discussing things in #38. Any help on this is appreciated.

You have these options:

Disabling PA

Note: You might not be able to run other apps that use audio output without some ALSA tweaking.

All under root (or sudo before every command):

  • If you have an older install, you have to create a home directory for the user alexapi to prevent permission errors:

mkdir -p /var/lib/AlexaPi/.config/pulse chown -R alexapi:alexapi /var/lib/AlexaPi/ usermod --home /var/lib/AlexaPi alexapi

- Then

    ```
cp /etc/pulse/client.conf /var/lib/AlexaPi/.config/pulse/
# edit /var/lib/AlexaPi/.config/pulse/client.conf and set "autospawn = no"

Running PA in system-wide mode (recommended)

This is the preferred (and possibly the only sensible) way to run PA with AlexaPi.

-- In addition i would call it experimental for now.

Note that there are some warnings about unexpected behavior and the like, but you can safely ignore it. Read more about system-wide PA on their wiki.

Setup and Configure Pulseaudio:

  • If you have an older install, you have to create a home directory for the user alexapi to prevent permission errors:

sudo mkdir -p /var/lib/AlexaPi/.config/pulse/ sudo chown -R alexapi:alexapi /var/lib/AlexaPi/ sudo usermod --home /var/lib/AlexaPi alexapi


- Then:
    ```
sudo cp /etc/pulse/client.conf /var/lib/AlexaPi/.config/pulse/

-- Note: I believe I left the client.conf unchanged from default and autospawn=no was already set - basically this is the same from disabling PA above.

  • Next install the required PulseAudio modules, and optionally uninstall the deprecated modules as recommended on freedesktop.org. Have a look at that page to understand how these things will work - there may also be things there to try if this setup doesn't work for you.

sudo apt install pulseaudio pavucontrol sudo apt remove pavumeter paman padevchooser


- Once that completes, we add the _pi_ (or your user) and _alexapi_ users to the `pulse-access` group, and just for good measure add the _pulse_ user to the `audio` group:

    ```
sudo adduser pulse audio
sudo adduser <username or pi> pulse-access
sudo adduser alexapi pulse-access
  • Next we need to create the systemd service so PulseAudio will start on boot in system wide mode: Create the file in you text editor, i used nano:

sudo nano /etc/systemd/system/pulseaudio.service


    in the new blank file that opens, place the following text: 

    ```
[Unit]
Description=PulseAudio Daemon

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
PrivateTmp=true
ExecStart=/usr/bin/pulseaudio --system --realtime --disallow-exit --no-cpu-limit
exit and save the file in the editor (for nano `[Ctrl] + x`, then `y`, then `[Enter]`)
  • Now we need to enable the systemd service so it starts automatically:

sudo systemctl enable pulseaudio.service


- Last we need to configure `config.yaml` for AlexaPi to use PulseAudio:
(If you didn't install AlexaPi in `/opt`, the file `config.yaml` is in your _AlexaPi/src_ directory.)
    ```
sudo nano /etc/opt/AlexaPi/config.yaml 
in this file, in the _sound_ section, set
```

input_device: "pulse" output: "pulse" output_device: ""


- Reboot your system and verify everything is working!  (hopefully it is)


### User session mode (AlexaPi as the only audio app)
TODO

### Using other user's (pi for example) PA instance

This is crazy and not supported (nor will ever be). You'd have to setup up some permissions, the actual socket (unix or TCP) to communicate and you'd have to make sure the user pi is always (and first) logged in before starting AlexaPi.