Skip to content
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

Adding Google AIY to DietPi #94

Closed
R1CH-T opened this issue Jul 10, 2017 · 10 comments
Closed

Adding Google AIY to DietPi #94

R1CH-T opened this issue Jul 10, 2017 · 10 comments

Comments

@R1CH-T
Copy link

R1CH-T commented Jul 10, 2017

I have spent most of the day trying to add the Google Assistant AIY code to DietPi and have had limited success. I have been able to write an installation entry for DietPi, which is working up until the point that the script and /or service are started. It gets all the way through the installation and OAUTH stuff, but then fails because of audio issues and also button failure.

The pre-configured .iso image works flawlessly on my MagPi AOI kit.

If I start it up with python3 src/main.py, I get the following errors:

(env) root@AIY:/mnt/dietpi_userdata/voice-recognizer-raspi# python3 src/main.py
[2017-07-10 00:45:43,780] WARNING:main:File /tmp/status-led specified for --led-fifo does not exist.
[2017-07-10 00:45:43,792] INFO:audio:started recording
[2017-07-10 00:45:43,798] INFO:main:ready...
Press the button on GPIO 23 then speak, or press Ctrl+C to quit...
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
arecord: main:722: audio open error: No such file or directory
[2017-07-10 00:45:43,804] ERROR:audio:Microphone recorder died unexpectedly, aborting...

root@AIY:/mnt/dietpi_userdata/voice-recognizer-raspi# python3 checkpoints/check_audio.py
Failed to find the voiceHAT soundcard. Refer to HACKING.md for how to
setup the voiceHAT driver: https://git.io/v99yK
Press Enter to close...

It seems that the drivers either did not install or configure properly, in order to get the Voice Hat working...

Am I missing something? Perhaps I am lacking some dependencies, or something.

Please look at this GitHub issue for further details.

@R1CH-T
Copy link
Author

R1CH-T commented Jul 10, 2017

Button light does not flash, button, speaker and mic do not work:

root@AIY:/mnt/dietpi_userdata/voice-recognizer-raspi# systemctl status voice-recognizer.service -l
● voice-recognizer.service - voice recognizer
   Loaded: loaded (/lib/systemd/system/voice-recognizer.service; enabled)
   Active: failed (Result: start-limit) since Mon 2017-07-10 01:24:53 UTC; 15min ago
  Process: 583 ExecStart=/mnt/dietpi_userdata/voice-recognizer-raspi/env/bin/python3 -u src/main.py (code=exited, status=217/USER)
 Main PID: 583 (code=exited, status=217/USER)
   CGroup: /system.slice/voice-recognizer.service

Jul 10 01:24:53 AIY systemd[1]: voice-recognizer.service: main process exited, code=exited, status=217/USER
Jul 10 01:24:53 AIY systemd[1]: Unit voice-recognizer.service entered failed state.
Jul 10 01:24:53 AIY systemd[1]: voice-recognizer.service holdoff time over, scheduling restart.
Jul 10 01:24:53 AIY systemd[1]: Stopping voice recognizer...
Jul 10 01:24:53 AIY systemd[1]: Starting voice recognizer...
Jul 10 01:24:53 AIY systemd[1]: voice-recognizer.service start request repeated too quickly, refusing to start.
Jul 10 01:24:53 AIY systemd[1]: Failed to start voice recognizer.
Jul 10 01:24:53 AIY systemd[1]: Unit voice-recognizer.service entered failed state.

-----------------------------------------------------------------------------------------------------------------------------------------------

root@AIY:/mnt/dietpi_userdata/voice-recognizer-raspi# systemctl status voice-recognizer.service
● voice-recognizer.service - voice recognizer
   Loaded: loaded (/lib/systemd/system/voice-recognizer.service; enabled)
   Active: failed (Result: start-limit) since Mon 2017-07-10 01:24:53 UTC; 15min ago
  Process: 583 ExecStart=/mnt/dietpi_userdata/voice-recognizer-raspi/env/bin/python3 -u src/main.py (code=exited, status=217/USER)
 Main PID: 583 (code=exited, status=217/USER)
   CGroup: /system.slice/voice-recognizer.service

root@AIY:/mnt/dietpi_userdata/voice-recognizer-raspi# cat /etc/asound.conf
options snd_rpi_googlemihat_soundcard index=0

pcm.softvol {
    type softvol
    slave.pcm dmix
    control {
        name Master
        card 0
    }
}

pcm.micboost {
    type route
    slave.pcm dsnoop
    ttable {
        0.0 30.0
        1.1 30.0
    }
}

pcm.!default {
    type asym
    playback.pcm "plug:softvol"
    capture.pcm "plug:micboost"
}

ctl.!default {
    type hw
    card 0
}

-----------------------------------------------------------------------------------------------------------------------------------------------

root@AIY:/mnt/dietpi_userdata/voice-recognizer-raspi# aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
softvol
micboost
default
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
dmix:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample mixing device
dmix:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample mixing device
dsnoop:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample snooping device
dsnoop:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample snooping device
hw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct hardware device without any conversions
hw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct hardware device without any conversions
plughw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Hardware device with all software conversions
plughw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Hardware device with all software conversions

-----------------------------------------------------------------------------------------------------------------------------------------------

root@AIY:/mnt/dietpi_userdata/voice-recognizer-raspi# arecord -l
**** List of CAPTURE Hardware Devices ****
root@AIY:/mnt/dietpi_userdata/voice-recognizer-raspi# arecord -L
null
    Discard all samples (playback) or generate zero samples (capture)
softvol
micboost
default
root@AIY:/mnt/dietpi_userdata/voice-recognizer-raspi# aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
softvol
micboost
default
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
dmix:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample mixing device
dmix:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample mixing device
dsnoop:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct sample snooping device
dsnoop:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct sample snooping device
hw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Direct hardware device without any conversions
hw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Direct hardware device without any conversions
plughw:CARD=ALSA,DEV=0
    bcm2835 ALSA, bcm2835 ALSA
    Hardware device with all software conversions
plughw:CARD=ALSA,DEV=1
    bcm2835 ALSA, bcm2835 IEC958/HDMI
    Hardware device with all software conversions

@ensonic
Copy link
Contributor

ensonic commented Jul 10, 2017

Could you run the checkpoint scripts:
https://github.com/google/aiyprojects-raspbian/tree/master/checkpoints
Also did use disable the HDMI audio? You should get this device listing:

$ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
softvol
micboost
default
sysdefault:CARD=sndrpigooglevoi
    snd_rpi_googlevoicehat_soundcar, 
    Default Audio Device
dmix:CARD=sndrpigooglevoi,DEV=0
    snd_rpi_googlevoicehat_soundcar, 
    Direct sample mixing device
dsnoop:CARD=sndrpigooglevoi,DEV=0
    snd_rpi_googlevoicehat_soundcar, 
    Direct sample snooping device
hw:CARD=sndrpigooglevoi,DEV=0
    snd_rpi_googlevoicehat_soundcar, 
    Direct hardware device without any conversions
plughw:CARD=sndrpigooglevoi,DEV=0
    snd_rpi_googlevoicehat_soundcar, 
    Hardware device with all software conversions

Another thing to check is whether the driver got loaded:

$ lsmod | grep snd
snd_soc_bcm2835_i2s     6546  2 
snd_soc_googlevoicehat_soundcard     3351  3 
snd_soc_googlevoicehat_codec     3936  1 
snd_soc_core          179915  3 snd_soc_googlevoicehat_codec,snd_soc_googlevoicehat_soundcard,snd_soc_bcm2835_i2s
snd_compress           10384  1 snd_soc_core
snd_pcm_dmaengine       5894  1 snd_soc_core
snd_pcm                98501  4 snd_pcm_dmaengine,snd_soc_googlevoicehat_soundcard,snd_soc_core
snd_timer              23904  2 snd_pcm
snd                    70032  8 snd_compress,snd_timer,snd_soc_core,snd_pcm

@R1CH-T
Copy link
Author

R1CH-T commented Jul 10, 2017

Thank you for the reply, ensonic.

I can't look at it again, right now, but i actually did manually run all the checkpoint scripts and if I recall correctly, they all failed. (I was up very late last night fiddling around with this thing.)

Also did use disable the HDMI audio?

It could be something to do with HDMI: I set it up headless with /boot/dietpi.txt, but didn't completely disable it. It also does look like it's a problem with drivers not loading. I'll try the lsmod ASAP.

I've been given a couple of pointers over at my other issue page, so I'll try those suggestions, too.

@R1CH-T
Copy link
Author

R1CH-T commented Jul 10, 2017

I think we've identified the problem: It's to do with file paths, mainly.

Dietpi uses the directory /DietPi to hold a ramdisk with a copy of config.txt. The changes need to be applied there.

Also, there are a few hard-coded paths in the code, which will need rectifying at this end, I think.

Examples:
MichaIng/DietPi#1065 (comment)

Thanks,
Rich.

@R1CH-T
Copy link
Author

R1CH-T commented Jul 10, 2017

Just to let you know; I've got it working, with the exception of the system services, because they all contain hard-coded links to /home/pi. This will need sorting out to ensure better compatibility with other distros, but, yeah; works like a charm!

Thanks for your input.

@drigz
Copy link
Member

drigz commented Jul 11, 2017

install-services.sh uses sed to change the path in the service files to the correct value, so it should be portable. How did it fail in your case?

install-alsa-config.sh could be generic - I've filed #95 to track this, thanks for finding it!

@R1CH-T, let us know if you found any other places that could be made more generic.

@R1CH-T
Copy link
Author

R1CH-T commented Jul 11, 2017

Thanks so much for replying. 👍

install-services.sh uses sed to change the path in the service files to the correct value, so it should be portable. How did it fail in your case?

I'm not a coder at all and even my rudimentary script-kiddie skills are not up to the task of keeping up with you guys, but I think that the fact that the sed command in question starts sed "s:/home/pi/voice-recognizer-raspi... might be a problem:
...
for service in systemd/*.service; do
sed "s:/home/pi/voice-recognizer-raspi:${repo_path}:g" "$service"
> "/lib/systemd/system/$(basename "$service")"
done
...
Should it use $HOME? Or maybe some variation of the line from the same script, which sets the base directory:

cd "$(dirname "${BASH_SOURCE[0]}")/.."

...and go up one level from that; but apply for all of the system services.

I'm not sure if this is viable and I'm not sure that I even know what I'm saying, myself; but rectifying this could potentially prevent (some) future issues of this kind.

In the case of DietPi, everything is run under Root, so all stuff directed to /home/user/ ends up in /root/ and all stuff directed to /home/pi/ fails. Hence the problem. This was the author's decision and I'm pretty sure that this has been debated, but I'm not qualified to weigh in. The point is that if anything is hard-coded to point to, or to look in /home/pi/ (or any other arbitrary directory); chaos ensues. If /voice-recognizer-raspi/ was dropped into /home/richard/, we would be dealing with the same sort of problem.

Please forgive me if I am rattling on, but I need to educate myself and I hope that I can, in some small way, help both of the projects that I dragged into this issue. It's just that it's so easy and so much of a time-saver, to use Dietpi to set up and connect applications and services, that I find it hard to beat. Also, I have had so much more fun playing around with the AIO kit than I ever did with using the Google Assistant on a phone.

@drigz
Copy link
Member

drigz commented Jul 11, 2017

I think that the fact that the sed command in question starts sed "s:/home/pi/voice-recognizer-raspi... might be a problem:

The reason for this is that the files themselves contain "/home/pi/..." in their current state. This command should replace "/home/pi/..." with the correct path "${repo_path}" as it installs the scripts. You can try running the script and looking at /lib/systemd/system/voice-recognizer.service to see if it has the right paths.

However, you will need to manually edit the files voice-recognizer.service, status-led.service and status-monitor.service in /lib/systemd/system/ to remove the line User=pi. (if this works for you, that could be made automatic in install-services.sh)

You may also have other issues running as root - I seem to remember someone trying this before and having some problems before getting it working, but can't find the thread. Let us know how it goes!

Please forgive me if I am rattling on

Not at all - we're happy to have the feedback!

@R1CH-T
Copy link
Author

R1CH-T commented Jul 12, 2017

Well, I got it all working now. I just had to add a few sed commands to the installer code to change the file paths and remove user=pi from the relevant services. If you are interested, look here:

MichaIng/DietPi#1065 (comment)

The only issues I have now are a lack of Power Off and Reboot commands and the silent alarm, mentioned in another issue, here.

Thanks,
Rich.

@drigz
Copy link
Member

drigz commented Oct 18, 2017

I think #156 resolved the issue with the new voicekit branch, so hopefully everything's working now.

@drigz drigz closed this as completed Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants