From 629d747a6bab32aeb86fdae7e325c64ac454c423 Mon Sep 17 00:00:00 2001 From: Rodrigo Queiro Date: Fri, 26 Jan 2018 16:56:59 +0100 Subject: [PATCH] Allow running check_audio.py without root 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: https://github.com/google/aiyprojects-raspbian/issues/254 Since it now uses configure_driver.sh, we have to fix https://github.com/google/aiyprojects-raspbian/issues/268 or the config will not survive a reboot. Change-Id: Icb440243395d885f20cd345b57a83ed82edd6e71 --- checkpoints/check_audio.py | 14 +++++--------- scripts/configure-driver.sh | 5 ++++- shortcuts/check_audio.desktop | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/checkpoints/check_audio.py b/checkpoints/check_audio.py index 08081310..a0be0b74 100755 --- a/checkpoints/check_audio.py +++ b/checkpoints/check_audio.py @@ -19,6 +19,7 @@ import fileinput import os import re +import subprocess import sys import tempfile import textwrap @@ -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(): diff --git a/scripts/configure-driver.sh b/scripts/configure-driver.sh index 370c0c4f..ee3a0710 100755 --- a/scripts/configure-driver.sh +++ b/scripts/configure-driver.sh @@ -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 @@ -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 diff --git a/shortcuts/check_audio.desktop b/shortcuts/check_audio.desktop index 142ac870..0ae29807 100644 --- a/shortcuts/check_audio.desktop +++ b/shortcuts/check_audio.desktop @@ -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