-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch from ALSA to PulseAudio #153
Open
krisgesling
wants to merge
9
commits into
buster
Choose a base branch
from
feature/pulseaudio
base: buster
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
81733b9
Fix #132 - remove hardcoded play commands
krisgesling 231325c
Switch all ALSA commands to PulseAudio
krisgesling 7430af8
Add pactl source selection for microphones
krisgesling e13117b
Allow Mimic to output audio directly
krisgesling ce56e09
Write new pactl commands to run on boot
krisgesling 17deadd
update comments to reflect switch from ALSA to PA
krisgesling d9a5608
add alsa config to default to pulseaudio
krisgesling 45afc15
fix pulseaudio cardname audio_setup.sh generation; single ticks preve…
mcdonc ddf76da
Merge pull request #155 from mcdonc/fix/pulseaudio-cardname
krisgesling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Use PulseAudio by default | ||
pcm.!default { | ||
type pulse | ||
fallback "sysdefault" | ||
hint { | ||
show on | ||
description "Default ALSA Output (currently PulseAudio Sound Server)" | ||
} | ||
} | ||
|
||
ctl.!default { | ||
type pulse | ||
fallback "sysdefault" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,18 +74,15 @@ function save_choices() { | |
} | ||
|
||
function set_volume() { | ||
# Use amixer to set the volume level | ||
# This attempts to set both "Master" and "PCM" | ||
# Use PulseAudio to set the volume level | ||
|
||
amixer set PCM $@ > /dev/null 2>&1 | ||
amixer set Master $@ > /dev/null 2>&1 | ||
pactl set-sink-volume @DEFAULT_SINK@ $@ | ||
} | ||
|
||
function save_volume() { | ||
# Save command to amixer to set the volume level | ||
# Save PulseAudio volume command to set the default volume level | ||
|
||
echo "amixer set PCM $@ > /dev/null 2>&1" >> ~/audio_setup.sh | ||
echo "amixer set Master $@ > /dev/null 2>&1" >> ~/audio_setup.sh | ||
echo "pactl set-sink-volume @DEFAULT_SINK@ $@" >> ~/audio_setup.sh | ||
} | ||
|
||
function network_setup() { | ||
|
@@ -302,24 +299,29 @@ function setup_wizard() { | |
1) | ||
echo "$key - Analog audio" | ||
# audio out the analog speaker/headphone jack | ||
sudo amixer cset numid=3 "1" > /dev/null 2>&1 | ||
echo 'sudo amixer cset numid=3 "1" > /dev/null 2>&1' >> ~/audio_setup.sh | ||
pactl set-default-sink alsa_output.platform-bcm2835_audio.analog-stereo | ||
echo 'pactl set-default-sink alsa_output.platform-bcm2835_audio.analog-stereo' >> ~/audio_setup.sh | ||
audio="analog_audio" | ||
break | ||
;; | ||
2) | ||
echo "$key - HDMI audio" | ||
# audio out the HDMI port (e.g. TV speakers) | ||
sudo amixer cset numid=3 "2" > /dev/null 2>&1 | ||
echo 'sudo amixer cset numid=3 "2" > /dev/null 2>&1' >> ~/audio_setup.sh | ||
pactl set-default-sink alsa_output.platform-bcm2835_audio.digital-stereo | ||
echo 'pactl set-default-sink alsa_output.platform-bcm2835_audio.digital-stereo' >> ~/audio_setup.sh | ||
audio="hdmi_audio" | ||
break | ||
;; | ||
3) | ||
echo "$key - USB audio" | ||
# audio out to the USB soundcard | ||
sudo amixer cset numid=3 "0" > /dev/null 2>&1 | ||
echo 'sudo amixer cset numid=3 "0" > /dev/null 2>&1' >> ~/audio_setup.sh | ||
echo "Select your output device" | ||
pactl list sinks short | awk '{printf(" %d) %s\n", NR, $2)}' | ||
echo -n "${HIGHLIGHT}Choice:${RESET} " | ||
read -N1 -s card_num | ||
card_name=$(pactl list sinks short | awk '{print$2}' | sed -n ${card_num}p) | ||
pactl set-default-sink ${card_name} | ||
echo 'pactl set-default-sink ${card_name}' >> ~/audio_setup.sh | ||
audio="usb_audio" | ||
break | ||
;; | ||
|
@@ -355,12 +357,6 @@ function setup_wizard() { | |
# See: https://github.com/google/aiyprojects-raspbian/issues/297 | ||
sudo sed -i -e "s/^load-module module-suspend-on-idle/#load-module module-suspend-on-idle/" /etc/pulse/default.pa | ||
|
||
# Changes mycroft.conf to use the default output device | ||
sudo sed -i \ | ||
-e "s/aplay -Dhw:0,0 %1/aplay %1/" \ | ||
-e "s/mpg123 -a hw:0,0 %1/mpg123 %1/" \ | ||
/etc/mycroft/mycroft.conf | ||
|
||
# Install asound.conf | ||
sudo cp AIY-asound.conf /etc/asound.conf | ||
|
||
|
@@ -387,11 +383,11 @@ function setup_wizard() { | |
sudo /home/pi/mycroft-core/.venv/bin/python dfu.py --download 1_channel_firmware.bin | ||
cd .. | ||
|
||
# Configure Mycroft to use plughw:ArrayUAC10,0 (Seeed device) | ||
sudo sed -i \ | ||
-e "s/aplay -Dhw:0,0 %1/aplay -Dplughw:ArrayUAC10,0 %1/" \ | ||
-e "s/mpg123 -a hw:0,0 %1/mpg123 -a plughw:ArrayUAC10,0 %1/" \ | ||
/etc/mycroft/mycroft.conf | ||
# Configure PulseAudio to use Seeed device | ||
pactl set-default-source alsa_input.usb-SEEED_ReSpeaker_4_Mic_Array__UAC1.0_-00.analog-mono | ||
pactl set-default-sink alsa_output.usb-SEEED_ReSpeaker_4_Mic_Array__UAC1.0_-00.analog-stereo | ||
echo 'pactl set-default-source alsa_input.usb-SEEED_ReSpeaker_4_Mic_Array__UAC1.0_-00.analog-mono' >> ~/audio_setup.sh | ||
echo 'pactl set-default-sink alsa_output.usb-SEEED_ReSpeaker_4_Mic_Array__UAC1.0_-00.analog-stereo' >> ~/audio_setup.sh | ||
|
||
audio="seed_mic_array_20" | ||
break | ||
|
@@ -502,10 +498,18 @@ function setup_wizard() { | |
;; | ||
4) | ||
echo "$key - Other" | ||
echo "Other microphone _might_ work, but there are no guarantees." | ||
echo "Other microphones _might_ work, but there are no guarantees." | ||
echo "We'll run the tests, but you are on your own. If you have" | ||
echo "issues, the most likely cause is an incompatible microphone." | ||
echo "The PS Eye is cheap -- save yourself hassle and just buy one!" | ||
echo "" | ||
echo "Select your input device" | ||
pactl list sources short | awk '{printf(" %d) %s\n", NR, $2)}' | ||
echo -n "${HIGHLIGHT}Choice:${RESET} " | ||
read -N1 -s card_num | ||
card_name=$(pactl list sources short | awk '{print$2}' | sed -n ${card_num}p) | ||
pactl set-default-source ${card_name} | ||
echo 'pactl set-default-source ${card_name}' >> ~/audio_setup.sh | ||
mic="other" | ||
break | ||
;; | ||
|
@@ -693,12 +697,7 @@ function setup_wizard() { | |
|
||
function speak() { | ||
# Generate TTS audio using Mimic 1 | ||
~/mycroft-core/mimic/bin/mimic -t $@ -o /tmp/speak.wav | ||
|
||
# Play the audio using the configured WAV output mechanism | ||
wavcmd=$( jq -r ".play_wav_cmdline" /etc/mycroft/mycroft.conf ) | ||
wavcmd="${wavcmd/\%1/\/tmp\/speak.wav}" | ||
$( $wavcmd >/dev/null 2>&1 ) | ||
~/mycroft-core/mimic/bin/mimic -t $@ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good that the user may hear some output as a result of this being called, but using mimic esp when it is not compiled for pulseaudio doesn't tell us much about whether e.g. mycroft-speak or the codepath that mycroft actually uses to do TTS will work for them, will it? |
||
} | ||
|
||
###################### | ||
|
@@ -876,7 +875,7 @@ then | |
# the script will likely be overwritten during later updates. | ||
# | ||
# Default to analog audio jack at 75% volume | ||
amixer cset numid=3 "1" > /dev/null 2>&1 | ||
pactl set-default-sink alsa_output.platform-bcm2835_audio.analog-stereo | ||
set_volume 75% | ||
|
||
# Check for custom audio setup | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of wonder if it would behoove us here to emit
pactl unload-module module-suspend-on-idle
by default here, given that we know that suspension is a problem with many devices. If that doesn't sound reasonable, maybe we could add it as a comment to the sample audio_setup.sh above?