Easily configure audio for Raspberry Pi devices running OpenVoiceOS.
This repository provides scripts and systemd services to manage audio configurations, simplifying tasks like setting default soundcards, combining audio sinks, and managing USB soundcard volumes. It's designed for users looking to optimize their Raspberry Pi's audio capabilities without diving deep into manual setup.
- Auto-detect and configure default soundcards, prioritizing external Hats and USB devices.
- Combine multiple audio sinks for seamless playback across devices.
- Revert all audio-related configurations to the default state with a single command.
- Ensure compatibility by managing mutually exclusive services (
autoconfigure_soundcard.service
andcombine_sinks.service
).
💡 Tip: Want automatic hardware detection and driver setup? Check out ovos-i2csound, designed for Raspberry Pi-specific hardware like Mycroft Mark 1 and Respeaker.
-
autoconfigure_soundcard.service
Automatically configures the default soundcard based on the detected hardware on boot and when USB devices are plugged in. -
combine_sinks.service
Systemd service that combines multiple audio sinks into one, allowing seamless audio output across multiple devices. This service is mutually exclusive withautoconfigure_soundcard.service
. -
install.sh
Installation script that sets up all necessary files and configurations, including copying scripts to the appropriate directories and enabling systemd services. -
ovos-audio-setup
Main script that provides an interactive setup menu to configure the default soundcard, enable automatic soundcard configuration, enable combined audio sinks, or revert all changes. -
soundcard_autoconfigure
Automatically detects and configures the default soundcard, prioritizing USB soundcards. Falls back to onboard soundcards if no external soundcards are found. (Mark1 > USB > other > Headphones > HDMI
) -
update-audio-sinks
Manages PulseAudio/PipeWire sinks, specifically for combining audio sinks when multiple devices are detected. -
usb-autovolume
Adjusts the volume of USB soundcards and recreates the combined audio sink to include the new USB soundcard.
Run the following command to install all necessary scripts and enable the systemd services:
git clone https://github.com/your-repo/raspOVOS-audio-setup.git
cd raspOVOS-audio-setup
sudo bash install.sh
This will copy the scripts to the appropriate directories, set executable permissions, and enable the required systemd services.
To run the script, execute the following:
/usr/local/bin/ovos-audio-setup
Follow the prompts to choose an option based on your needs.
The script provides the following choices:
-
1) Set default soundcard
Manually set the default soundcard. It will list all available soundcards and prompt you to choose one. Selecting this option will disable any activecombine_sinks.service
orautoconfigure_soundcard.service
. -
2) Autoconfigure default soundcard
Automatically configures the default soundcard based on the detected hardware (USB or onboard soundcard). Theautoconfigure_soundcard.service
will be enabled, and any activecombine_sinks.service
will be disabled. -
3) Enable combined audio sinks
Enables the combination of multiple audio sinks into one unified audio output. Thecombine_sinks.service
will be enabled, and theautoconfigure_soundcard.service
will be disabled. -
4) Revert changes
Reverts all audio configurations to their default state. This disables any active services and restores original system settings. -
5) Exit
Exit the setup process without making changes.
- All scripts generate logs, which are saved to the
/tmp
directory:- /tmp/autosoundcard.log (for soundcard autoconfiguration)
- /tmp/autovolume-usb.log (for USB soundcard udev events)
- /tmp/autosink.log (for sink creation and merging events)
Check these logs for troubleshooting if you have no audio output.
Below is a sample log output for typical operations:
(ovos) ovos@raspOVOS:~ $ tail -f /tmp/*.log
==> /tmp/autosoundcard.log <==
Fri 17 Jan 11:42:46 WET 2025 - **** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 1: Device [USB Audio Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: vc4hdmi [vc4-hdmi], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 3: sndrpiproto [snd_rpi_proto], device 0: WM8731 HiFi wm8731-hifi-0 [WM8731 HiFi wm8731-hifi-0]
Subdevices: 0/1
Subdevice #0: subdevice #0
Fri 17 Jan 11:42:48 WET 2025 - Mark 1 soundcard detected by ovos-i2csound.
Fri 17 Jan 11:42:48 WET 2025 - Detected CARD_NUMBER for Mark 1 soundcard: 3
Fri 17 Jan 11:42:48 WET 2025 - Configuring ALSA default card
Fri 17 Jan 11:42:48 WET 2025 - Running as user, modifying ~/.asoundrc
Fri 17 Jan 11:42:48 WET 2025 - ALSA default card set to: 3
==> /tmp/autovolume-usb.log <==
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: vc4hdmi [vc4-hdmi], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 3: sndrpiproto [snd_rpi_proto], device 0: WM8731 HiFi wm8731-hifi-0 [WM8731 HiFi wm8731-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
Fri Jan 17 11:42:43 WET 2025 - USB audio device detected. Soundcard index: 1
Fri Jan 17 11:42:43 WET 2025 - Volume set to 85% on card 1, control 'Speaker'
==> /tmp/autosink.log <==
Setting up audio output as combined sinks
Running as user
Sinks before action: 52 alsa_output.platform-bcm2835_audio.stereo-fallback PipeWire s16le 2ch 48000Hz SUSPENDED
53 alsa_output.platform-3f902000.hdmi.hdmi-stereo PipeWire s32le 2ch 48000Hz SUSPENDED
54 alsa_output.platform-soc_sound.stereo-fallback PipeWire s32le 2ch 48000Hz RUNNING
56 alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo PipeWire s16le 2ch 48000Hz SUSPENDED
auto_combined sink missing
Total sinks: 4
Combined sink created with outputs: alsa_output.platform-bcm2835_audio.stereo-fallback,alsa_output.platform-3f902000.hdmi.hdmi-stereo,alsa_output.platform-soc_sound.stereo-fallback,alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo (module ID: 536870916)
Sinks after action: 52 alsa_output.platform-bcm2835_audio.stereo-fallback PipeWire s16le 2ch 48000Hz SUSPENDED
53 alsa_output.platform-3f902000.hdmi.hdmi-stereo PipeWire s32le 2ch 48000Hz SUSPENDED
54 alsa_output.platform-soc_sound.stereo-fallback PipeWire s32le 2ch 48000Hz RUNNING
56 alsa_output.usb-GeneralPlus_USB_Audio_Device-00.analog-stereo PipeWire s16le 2ch 48000Hz SUSPENDED
108 auto_combined PipeWire float32le 2ch 48000Hz SUSPENDED
Enjoy configuring your audio setup with ease! 🎉
This work was funded by the Ministerio para la Transformación Digital y de la Función Pública and Plan de Recuperación, Transformación y Resiliencia - Funded by EU – NextGenerationEU within the framework of the project ILENIA with reference 2022/TL22/00215337