banner



Raspberry Pi Aiy There Was a Glitch Try Again in a Few Seconds

Hither is a brusk demo in case you know nothing of Google AIY (Aritificial Intelligence Yourself).

If you lot adopt you tin watch the total instructional video on YouTube.

In mid-2017 Google released a kit for utilise with the Raspberry Pi under the AIY brand, it came with a Voice HAT, Phonation HAT microphone board, a 3″ speaker,  a paper-thin box,  some wires and some lovely arcade buttons. This kit was surpassed with the V2 release that used the Pi Nil WH.

Just yous don't demand the kit to accept advantage of the epitome that they accept provided. All we need to do is brand a few changes to some configuration files to become the Google AIY to piece of work without the Vocalization Chapeau stuff.

I will be using a USB sound carte (This is the one I bought from Amazon United kingdom of great britain and northern ireland – US) instead of the Vocalisation Hat forth with an external speaker and a three.5mm jack microphone. Wanna follow forth? Take a look beneath.

Contents

  1. What yous will need
  2. Where to begin
  3. Setting up the software
    1. General settings
    2. Edit sound settings and test
    3. Enable Google Cloud stuff
    4. Getting it to run on boot
  4. What to exercise adjacent?
  5. Problems?

What you volition demand

    • Raspberry Pi ii/3 (Amazon UK – US)
    • Micro-SD card (I would recommend a minimum of 8GB)
    • External powered speaker (Anker make a adequately practiced one – Amazon UK – US simply any will do)
    • USB soundcard (This is the one I bought from Amazon UK – US)
      • This choice gives you 3.5mm input for audio and three.5mm output
      • You lot will need a cheap three.5mm microphone for this approach (This is the one I bought from Amazon Great britain – US but whatever will exercise)
    • WiFi dongle or Ethernet connectedness if using the Pi 2
    • A breadboard
    • A momentary push button
    • A Google Account (This is and so you can make utilize of the Google Assistant API)

Where to begin

I will be using Windows for this process, steps are similar but Linux and Mac users will take to muddle through I am afraid.

Footstep one – Edifice Blocks
This is probably a little obvious to nigh of you, connect all your components together but hold off on power for now.

You will need to connect the push up to GPIO23, you lot can yet use this without the button if y'all don't have i. Using your breadboard, connect one side of your button to GPIO23 and the other side to GND, the pins are mark in pink and blue on the epitome.

Step 2 – Getting Software
Download and burn down the image to your SD carte du jour, it will be zipped upwards in a Tar format that you can extract with 7-Zip and burned with something like Win32DiskImager or you tin can burn information technology direct to you lot SD card using Etcher.

Pace 3 – Getting Continued

Easy
Hither is where things go a trivial messy, depending upon what y'all have available. If y'all have a monitor, keyboard and mouse available then you tin set up your WiFi in the GUI environs that this image volition kick direct into. This is likely the easiest method to go upward and running quickly. I won't get into the specifics here, setting up the WiFi should be like shooting fish in a barrel as Pi in the GUI these days. You can accomplish everything in this tutoral through the GUI interface but I am going to go the rest of the manner with a terminal window.

Medium
If you don't have desire to mess up your desktop setup or you are using an all-in-i, you should connect through Ethernet to your home network. This is my preferred method to fix up my Raspberry Pi'due south.

Hard
Grab yourself a USB to series converter, and hook information technology up to the Pi's RX and TX lines. Yous volition still demand an internet connectedness so this is not the best route to take but it can get y'all in to connect up your WiFi module.

We are going to connect to the Pi for the first time using SSH or through a serial interface. To do this I am going to use Putty but feel gratuitous to utilise your terminal/serial console of choice, at that place are even browser based ones these days.

When you open Putty you can choose betwixt SSH or Serial (choose Serial if you are using that interface and select the correct COM port) at this betoken you will need to know the IP address of your Pi if running the SSH road.

Raspberry Pi Google AIY Speak Button Pin

Setting up the software

At present you lot will need to create a project on the Google Cloud Platform the instructions on AIY are great for this.

          Time-saving tip          You lot can re-create these commands by selecting them and copying with ctrl-c and then paste into Putty with a mouse right-click.        

General settings

Login to your Pi, the username is pi and the countersign will be raspberry

First we'll update. This can accept ages (30 minutes) but it is important to brand sure your Pi can talk to your hardware, information technology may need newer drivers. Runs these commands separately:

          
sudo apt-get update

sudo apt-get upgrade

sudo reboot

Second, permit'due south modify some settings in the Raspberry Pi Software Configuration Tool:

sudo raspi-config        

(Optional)3 Boot Options –> B1 Desktop / CLI

Select Console Autologin

Now bound dorsum and select Wait for Network at Kicking

Now under two. Network Option we will need to connect to WiFi if you are using it. Yous will need to know your home network SSID (The proper name that pops upwardly when searching for WiFi) and the countersign.

Edit audio settings and test

Now nosotros need to delve into some of the audio configuration files, these are used past the Pi (Specifically ALSA) to determine what device to use as the default for audio input and output.

You will demand to run 2 commands which will open files in the terminal, delete the contents of that file and paste in the Audio Configuration code listed below.

Command i

sudo raspi-config sudo nano /etc/asound.conf        

Command 2

sudo nano ~/.asoundrc        

Audio Configuration lawmaking
This code tells the OS which bill of fare yous desire to use, here it is specified equally a USB PnP Audio Device. If your USB sound carte du jour reports to the Os differently you can alter the title, use the command true cat /proc/asound/cards to see how your appears.

options snd-usb-audio alphabetize=1 pcm.!default { type hw menu i } ctl.!default { type hw card one }        

Side by side let's change some of the ALSA configuration files and then it e'er uses our default device (nosotros specified that information technology would exist device one)

sudo nano /usr/share/alsa/alsa.conf        

Now detect the section that contains the post-obit, it is on folio 2:

#defaults.ctl.card 0 #defaults.pcm.menu 0        

Replace those sections with:

defaults.ctl.card 1 defaults.pcm.card one        

Now lets go in an change our volume settings. Type alsamixer to bring upwardly this window.

I inverse mine so that they were at 50% for both speaker and Mic, you can navigate to your devive with F6. Once you exit yous can shop those settings with the following control:

sudo alsactl store        

Now allow'southward reboot and encounter it our changes accept have effect:

sudo reboot        

Let'southward test our audio now, to do that we are going to record from the microphone and play it back through the speakers.

This command will record audio through your microphone for five seconds:

arecord -d v -f S16_LE -r 44100 -t wav they_hear_me_recording_they_hating.wav        

This command will play back what you take recorded, hopefully y'all will hear whatever you recorded through your external speaker:

aplay they_hear_me_recording_they_hating.wav        

Enable Google Cloud stuff

You will demand to grab some credentials in gild to work with the Google Assiatant. Brand sure you have a Google Account and y'all are logged in on your PC.

Go to the the Google Cloud platform website and create a project, make sure you select/actuate Google Assistant

Next you need to grab some credentials for an OAuth 2.0 client once you have configured your 'app' you can download them from the credentials list. This volition be a JSON file.

Now we demand to get that onto the Pi, the easiest fashion is just to create a file in the terminal, open the downloaded file on your PC and re-create and paste the contents to the terminal window inside the JSON file we volition create:

sudo nano /home/pi/assistant.json        

Now to activate!

cd AIY-voice-kit-python        

The run this:

src/examples/vox/assistant_grpc_demo.py        

It is going to ask you to visit a website, bit of a pain because copying the URL from the terminal will close the Python script. Re-create the long URL and paste information technology into your desktop browser and follow the authorisation steps to go your primal. Copy the response key from your browser and and then run that command once more in the final, this time you tin paste the response in and it volition activate your device.

Getting it to run on boot

Copy this case src/examples/voice/assistant_library_with_button_demo.py using this command:

cp src/examples/vocalism/assistant_library_with_button_demo.py src/master.py        

At present we need to create a service, this is something that runs at boot and remains running. To do this we need to create a 'service' file that describes our service, the environs it will run in and the location of the Python file. We take called out file main.py but you tin can call information technology what every you like, just be sure to modify it in the service too.

Lets begin by creating the file, nosotros will motion it later.

sudo nano pi-assistant.service        

Now copy the lawmaking below and paste it into your terminal.

Description=Pi Google Banana [Service] Surroundings=XDG_RUNTIME_DIR=/run/user/chiliad
ExecStart=/bin/bash -c 'python3 -u src/main.py'
WorkingDirectory=/habitation/pi/AIY-projects-python Restart=always User=pi [Install] WantedBy=multi-user.target

Now that nosotros have created our service file we will need to move it to the right folder with this command:

sudo mv pi-banana.service /lib/systemd/arrangement/        

Next we will need to enable the service so that it will work on boot with this command:

sudo systemctl enable pi-assistant.service        

At this indicate I had a few problems with the user (Pi) being able to run the script,  now the side by side set of commands are not entirely necessary but if you get permission errors with your service this should solve them:

Run them i at a fourth dimension.

sudo chown -R pi /dwelling/pi/.config/pulse chmod 755 /home/pi/.config/pulse        

Now let's first the service:

sudo service pi-assistant start        

If all has gone well and once your Pi has fully booted, you should just be able to printing the push button or call out 'Hey Google' to speak to the assistant.

If it hasn't and your service doesn't start, run these commands separately and and so reboot.

chown -R pi /run/user/g chmod 755 /run/user/g        

What to practise side by side?

Adding a power button for a headless setup is actually useful to safely shutdown the pi and to reboot it.

I have implemented rpi-shutdown from Halofx on GitHub and information technology is working not bad. 1 press of the button will shutdown the Pi and one time shutdown a second press will reboot it. To get this prepare up we'll need a push on GPIO 3, I have marker the pins for you:

Raspberry Pi Shutdown Button Pin

Download the code from GitHub and SFTP it over to your Pi or just create a new file with sudo nano /home/pi/shutdown_pi.py and paste the code in.

Now lets edit a file which will run our script at kicking, type – sudo nano /etc/rc.local

Y'all will see a file that looks like this:

#!/bin/sh -eastward # # rc.local # # This script is executed at the stop of each multiuser runlevel. # Make certain that the script will "leave 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does aught.  # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %southward\north" "$_IP" fi  exit 0        


No you will need to add together our Python file to rc.local file like this:

#!/bin/sh -e # # rc.local # # This script is executed at the finish of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on mistake. # # In order to enable or disable this script only modify the execution # bits. # # Past default this script does zero.  # Impress the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; so printf "My IP address is %s\n" "$_IP" fi sudo python /home/pi/shutdown_pi.py & exit 0        

Hopefully and in that location are no guarantees, you lot should be up and running. Sound configurations tin can exist fiddly, Python and Linux are quite sensitive to syntax and spacing for commands, you may have a very unlike USB audio bill of fare to me, there are lots of things that can make y'all efforts fail. I am happy to assistance in the comments or on YouTube but I am by no means a Linux proficient.

Bug?

Yes, unfortuately that is pretty likely, things can get wrong. Often times it is a case of going back and repeating some of the steps which change settings, permissions or just plain starting again.

  • Run the command speaker-test to see if you get output on your speakers
  • You service isn't running! Run the command sudo service pi-assistant status to encounter what error message information technology is flagging up. If it is to practise with failing to create a directory repeat the chmod and chown steps
  • Python is sensitive to spacing and specifically tabs, brand certain your code looks like it does above
  • My sound output is really low! Try 'Hey Google, what'sthe volume?' then fix is college with – 'Hey Google, set volume to *1-ten or 0-100%*'

saltingmonal1994.blogspot.com

Source: https://davidjwatts.com/google-aiy-without-the-kit-on-the-raspberry-pi-2-and-3/

0 Response to "Raspberry Pi Aiy There Was a Glitch Try Again in a Few Seconds"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel