Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Audio setup & debugging
Clone this wiki locally
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
You may need to adjust the volume and/or input gain for the microphone, you can do this with
Once the adjustments have been made, you can save the settings using
Debugging your setup
If there is an error in your log file complaining about audio you may need to tinker your audio setup. These errors might be these:
If you use an incorrect / unlisted device name, AlexaPi will tell you and exit with the list of correct options.
Another application is using your device:
IOError: [Errno -9985] Device unavailable
If you are running a desktop OS, it might be PulseAudio in user-session mode. You have to run PA in system-wide mode in order to run AlexaPi. Scroll down for more info.
Checking if your system audio works
- To test playback, run
- To test recording, run
arecord -f S16_LE -r 16000 -D your_input_device test.wav- exit with CTRL+C and
aplay -f S16_LE -r 16000 test.wavto play
Audio playback issues
- First check that you are on the latest version of your OS, VLC and the
- Try SoX instead of VLC. Change
soxin your config. SoX doesn't handle some playlists correctly for now though. A lot of things might not work.
Checking AlexaPi's recordings
If you get null responses, you might wanna check the sound AlexaPi records. First, run in the Debug mode and then check the directory
/tmp/AlexaPi-runtime-xxx (where xxx is some random string) for the file
recording.wav. This has to be played with special
aplay -r 16000 -f S16_LE recording.wav
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
Raspbian defaults to the HDMI audio out. If you want to use the 3.5mm jack you can use
and choose "Advanced Options" to force 3.5mm audio output.
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.
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.
You have these options:
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):
mkdir -p /var/lib/AlexaPi/.config/pulse 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:
Install PulseAudio 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
Run these commands:
mkdir -p /var/lib/AlexaPi/.config/pulse sudo cp /etc/pulse/client.conf /var/lib/AlexaPi/.config/pulse/
Also if you see issues with permissions in the log file for /var/lib/AlexaPi (if you have an older install), you may need to run these commands:
# create and set a home directory for the user alexapi chown -R alexapi:alexapi /var/lib/AlexaPi/ usermod --home /var/lib/AlexaPi alexapi
Next, we add the pi (or your user) and alexapi users to the
pulse-accessgroup, and just for good measure add the pulse user to the
sudo adduser pulse audio sudo adduser <username or pi> pulse-access sudo adduser alexapi pulse-access
If you are running the root override (like on a CHIP or Orange Pi), you also need to add the user root into the pulse-access group:
sudo adduser root 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
Now we need to enable the systemd service so it starts automatically:
sudo systemctl enable pulseaudio.service
Last we need to configure
config.yamlfor AlexaPi to use PulseAudio: (If you didn't install AlexaPi in
/opt, the file
config.yamlis in your AlexaPi/src directory.)
sudo nano /etc/opt/AlexaPi/config.yaml
in this file, in the sound section, if you're using VLC handler set
input_device: "pulse" output: "pulse" output_device: ""
Or if you're using SoX set
input_device: "pulse" output: "pulseaudio" output_device: ""
and install the
sudo apt-get install libsox-fmt-pulse
Reboot your system and check to see that everything is working. If the audio playback is choppy, you can try installing VLC manually with
sudo apt-get install vlc.
User session mode (AlexaPi as the only audio app)
PulseAudio via dmix
Alternatively, you can force PA to use dmix, so other apps can use ALSA directly. See https://wiki.archlinux.org/index.php/PulseAudio#ALSA.2Fdmix_without_grabbing_hardware_device Warning: This has not been tested. Feedback is welcome.
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.