Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Russell Grokett
Published © GPL3+

Google Voice Assistant Using Asterisk PBX on Raspberry Pi

Run Google Voice Assistant using Asterisk VOIP PBX running on a Raspberry Pi (even a Pi Zero).

IntermediateFull instructions provided2 hours12,204
Google Voice Assistant Using Asterisk PBX on Raspberry Pi

Things used in this project

Hardware components

Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
×1
VOIP (SIP) Phone such as Grandstream GXP1620
Alternately, use a VOIP Softphone for PC (see below)
×1

Software apps and online services

VOIP Softphone
Need either a VOIP physical phone or Softphone
Alternate VOIP Softphone
Only one VOIP hard or soft phone needed!
RaspiAsteriskGoogle
Software from Github

Story

Read more

Schematics

Call Flow Chart

Code

Code snippet #6

Plain text
Debugging: 
  If you don’t get dial tone, your SIP Phone isn’t registering to your Asterisk server.  Try the following:  a.       Reboot the Raspberry and then the SIP phone to see if they reconnect.  b.     Verify the files above are edited correctly.  c.      Access Asterisk from command line:  $ sudo asterisk -r  CLI>  sip show peers  This should show your sip phone’s IP and status. Watch out for firewalls, particularly if using a softphone!  d.      Verify IP addresses of the VOIP Phone and Raspi and be sure you can ping the phone's IP from the Pi.  e.      If still an issue, turn on SIP Debugging:    CLI> sip set debug on  This will display SIP connection attempt messages. If you see nothing after a few
  minutes, then your SIP Phone isn’t even trying to talk to Asterisk. You need
  to dig into the SIP Phone’s setup instructions.  f.       Asterisk log messages go to /var/log/asterisk/messages. But note there can be lots of
  nasty looking messages, most are for unused/unneeded features. So it can be difficult to decipher.  g.      Google is your friend. Cut/paste any error messages you see into it to learn more!

Code snippet #9

Plain text
sudo apt-get updatesudo apt-get install python-dev
sudo apt-get install portaudio19-dev libffi-dev libssl-dev
sudo apt-get install python-pip
sudo python -m pip install PySocks
sudo python -m pip install google-assistant-sdk[samples]

Code snippet #13

Plain text
Found client_secret.json  OK  Found OAUTH
  assistant_credentials.json OK  Sending sample to Google
  Assistant API...  DEBUG:google.auth.transport.requests:Making
  request: POST  https://accounts.google.com/o/oauth2/token  DEBUG:urllib3.connectionpool:Starting
  new HTTPS connection (1): accounts.google.com  DEBUG:urllib3.connectionpool:https://accounts.google.com:443
  "POST /o/oauth2/token HTTP/1.1" 200 None  INFO:root:Connecting to
  embeddedassistant.googleapis.com  INFO:root:Recording
  audio request.  DEBUG:root:ConverseRequest:
  config {    audio_in_config {      encoding: LINEAR16      sample_rate_hertz: 16000    }    audio_out_config {      encoding: LINEAR16      sample_rate_hertz: 16000      volume_percentage: 50    }  }  DEBUG:root:ConverseRequest:
  audio_in (6400 bytes)  DEBUG:root:ConverseRequest:
  audio_in (6400 bytes)  DEBUG:root:ConverseRequest:
  audio_in (6400 bytes)...  DEBUG:root:ConverseRequest:
  audio_in (6400 bytes)  DEBUG:root:ConverseRequest:
  audio_in (4096 bytes)  DEBUG:root:ConverseRequest:
  audio_in (3200 bytes)  …(more)  DEBUG:root:ConverseResponse: event_type: END_OF_UTTERANCE  INFO:root:End of audio
  request detected  DEBUG:root:ConverseResponse:
  result {    spoken_request_text:
  "what is the current weather"  }  DEBUG:root:ConverseRequest:
  audio_in (3200 bytes)  INFO:root:Transcript of user request: "what is
  the current weather".  INFO:root:Playing
  assistant response.  DEBUG:root:ConverseResponse:
  result {    conversation_state: "\n&C#590…6f7-0000-2231-932c-94e…3c9ba\022\270\001Kj93Nlg1eVpmWWMGlLSURpYUpWdkpXb2hRUW43YnNIcmdBQUFDQ1RjV0…
  "    microphone_mode: CLOSE_MICROPHONE  }  DEBUG:root:ConverseResponse:
  audio_data (1600 bytes)  DEBUG:root:ConverseResponse:
  audio_data (1600 bytes)  DEBUG:root:ConverseResponse:
  audio_data (1600 bytes)  …(more)  DEBUG:root:ConverseResponse: audio_data (1044 bytes)  INFO:root:Finished playing assistant response.  AUDIO FILES:  -rw-r--r-- 1 pi   pi   
  55340 Apr 30 17:02 in.wav  -rw-r--r-- 1 root root
  252288 May  1 14:51 out.wav   ...

Code snippet #15

Plain text
$ cd /home/pi/RaspiAsteriskGoogle$ nano google.agi
Change my $debug = 0;
To my $debug = 1;
Save
$ bash ./install.sh

Code snippet #21

Plain text
$ ls -l /tmp-rw-rw---- 1 asterisk asterisk 32266 May  3 02:01 google_audio3424_8k.sln
-rw-rw---- 1 asterisk asterisk 73004 May  3 02:01 google_audio3424_in.wav
-rw-rw---- 1 asterisk asterisk 64576 May  3 02:01 google_audio3424_out.wav
-rw-rw---- 1 asterisk asterisk  6124 May  3 02:01 google_audio3441.wav
google_audio3441.wav -- Audio of your question
google_audio3424_in.wav    -- Audio formatted for Google
google_audio3424_out.wav   -- Audio response from Google
google_audio3424_8k.sln    -- Audio formatted for Asterisk

Github

https://github.com/rgrokett/RaspiAsteriskGoogle

Github

https://github.com/rgrokett/RaspiAsteriskAlexa

Credits

Russell Grokett
10 projects • 17 followers
Interests: Astronomy, Scuba, Caving, Electronics, Web, Coding, Ham Radio, Sci Fi, IoT

Comments