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

Audio setup & debugging

revere521 edited this page Nov 18, 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.

Pulseaudio

Right now it might not work. We're discussing this in #38. You can find some tips in there for the time being. Any help on that is also appreciated.

Disabling PA

All under root:

mkdir -p /var/lib/AlexaPi/.config/pulse
chown -R alexapi:alexapi /var/lib/AlexaPi/
usermod --home /var/lib/AlexaPi alexapi
cp /etc/pulse/client.conf /var/lib/AlexaPi/.config/pulse/
# edit /var/lib/AlexaPi/.config/pulse/client.conf and set "autospawn = no"

Running in System-Wide mode

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

This is setup and working on a Raspberry Pi 2 model B, running a relatively clean install of Raspbian Pixel. Its also notable that i am not running a headless system, and the user pi automatically logs in and loads to the desktop (and then MagicMirror2). We are also going to run pulseaudio in system-wide mode as a deamon, and there are some warnings about unexpected behavior and the like so YMMV; but this worked for me (read more about that here; https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SystemWide/). Depending on a variety of things you may need to use sudo to elevate permissions on commands listed below (i.e. just put sudo in front of any of the commands if you get permission denied - you know to be care with sudo though right).

Setup and Configure Pulseaudio: Create a home directory in /var/lib to prevent permission errors (as suggested by renekliment here: https://github.com/alexa-pi/AlexaPi/issues/38) under root or with sudo:

mkdir -p /var/lib/AlexaPi/ chown -R alexapi:alexapi /var/lib/AlexaPi/ usermod --home /var/lib/AlexaPi alexapi 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

Next install the required pulseaudio modules, and optionally uninstall the depreciated modules as recommended on freedesktop.org (https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/PerfectSetup/) 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:

apt install pulseaudio pavucontrol apt remove pavumeter paman padevchooser

once that completes, we add the pi (or yor user) and alexapi users to the pulse-access group, and just for good measure add the pulse user to the audio group:

adduser pulse audio adduser <username or pi> pulse-access 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 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 look for the line

input_device: "plughw:1"

and change it to

input_device: "pulse"

next find

output: "alsa"

and change it to

output: "pulse"

you can leave output_device: "default" as is.

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

User session mode (AlexaPi as the only audio app)