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

Commit

Permalink
Allow running check_audio.py without root
Browse files Browse the repository at this point in the history
Running as root means that ALSA ignores /home/pi/.asoundrc, so problems
with the demos can't (easily) be detected in check_audio.py. See:
#254

Since it now uses configure_driver.sh, we have to fix
#268
or the config will not survive a reboot.

Change-Id: Icb440243395d885f20cd345b57a83ed82edd6e71
  • Loading branch information
drigz committed Jan 29, 2018
1 parent 7b353e9 commit 629d747
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
14 changes: 5 additions & 9 deletions checkpoints/check_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import fileinput
import os
import re
import subprocess
import sys
import tempfile
import textwrap
Expand Down Expand Up @@ -137,15 +138,10 @@ def do_checks():


def enable_audio_driver():
print(textwrap.fill(
"""Enabling audio driver for VoiceKit."""))
for line in fileinput.input("/boot/config.txt",
inplace=True, backup=".bak"):
if re.match("^# dtoverlay=googlevoicehat-soundcard", line):
print("dtoverlay=googlevoicehat-soundcard")
else:
print(line, end='')
os.system("dtoverlay googlevoicehat-soundcard")
print("Enabling audio driver for VoiceKit.")
configure_driver = os.path.join(
os.path.dirname(__file__), '..', 'scripts', 'configure-driver.sh')
subprocess.check_call(['sudo', configure_driver])


def main():
Expand Down
5 changes: 4 additions & 1 deletion scripts/configure-driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ set -e

sed -i \
-e "s/^dtparam=audio=on/#\0/" \
-e "s/^#\(dtparam=i2s=on\)/\1/" \
-e "s/^#\s*\(dtparam=i2s=on\)/\1/" \
-e "s/^#\s*\(dtoverlay=i2s-mmap\)/\1/" \
-e "s/^#\s*\(dtoverlay=googlevoicehat-soundcard\)/\1/" \
/boot/config.txt
grep -q "dtoverlay=i2s-mmap" /boot/config.txt || \
echo "dtoverlay=i2s-mmap" >> /boot/config.txt
Expand All @@ -34,3 +36,4 @@ grep -q "dtoverlay=googlevoicehat-soundcard" /boot/config.txt || \
grep -q "dtparam=i2s=on" /boot/config.txt || \
echo "dtparam=i2s=on" >> /boot/config.txt

dtoverlay googlevoicehat-soundcard
2 changes: 1 addition & 1 deletion shortcuts/check_audio.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Encoding=UTF-8
Type=Application
Name=Check audio
Comment=Check that the voiceHAT audio input and output are both working.
Exec=sudo /home/pi/AIY-projects-python/env/bin/python /home/pi/AIY-projects-python/checkpoints/check_audio.py
Exec=/home/pi/AIY-projects-python/env/bin/python /home/pi/AIY-projects-python/checkpoints/check_audio.py
Terminal=true

0 comments on commit 629d747

Please sign in to comment.