Talk With Alexa and Google Assistant Together in a Raspberry Pi

Intro: Talk With Alexa and Google Assistant Together in a Raspberry Pi

Run Amazon Alexa and Google Assistant at the same time in a Raspberry Pi. Call either of their names, they turn on their own LEDs and ring sounds for response. Then you ask some request and they answer it to you respectively. You can know their characteristics well.

[Talking with 2 Voice Navigators Together (in Japanese)]

It is not difficult to install these two voice navigators in a Raspberry Pi. Very thorough Step by Step Guides are provided in web for both of them. You have only to install “PulseAudio” additionally to talk with them together. Enjoy!

(*1) The Pi with 2 Navigators enters Voice Activated Contest. If you like it, vote please. Thank you.

(*2) I appreciate Dimeiza for his earlier article described in Japanese.

Step 1: Stuff

Stuff List:

  • Raspberry Pi 3
  • Power Adaptor: DC 5V, 2.5A
  • Micro-SD Card: 16GB
  • USB Microphone: I use a microphone in a cheap USB camera (Logitech C270).
  • Some LEDs
  • Breadboard
  • Some Jumper wires
  • Speaker or Headphone: TV can be used also via HDMI port.

I have touched Raspberry Pi for the first time 4 months ago. Hence I don't know it well. The installed OS is Raspbian Stretch (NOOBS v.2.4.4). I will not be able to give you troubleshooting for other OS or versions.

Step 2: Install Amazon Alexa Voice Service

A very thorough "step-by-step instructions" is provided in web. Just following it, you can install Alexa Voice Service SDK in your Pi, and run a sample code in it. Call "Alexa!"

To know whether your call reaches your Pi, turning LEDs On and ringing short sounds are added in the sample code "/home/pi/sdk-folder/sdk-source/avs-device-sdk/SampleApp/src/UIManager.cpp".

1) Add 5 lines with "system(...);" in "void UIManager::printState() {" in the sample c++ code "UIManager.cpp", and save it.

*******

switch (m_dialogState) {

case DialogUXState::IDLE:

system("gpio -g mode 24 out");

system("gpio -g write 24 0");

ConsolePrinter::prettyPrint("Alexa is currently idle!");

return;

case DialogUXState::LISTENING:

system("gpio -g mode 24 out");

system("gpio -g write 24 1");

system("aplay /home/pi/sdk-folder/application-necessities/sound-files/re.wav 1>/dev/null 2>/dev/null");

ConsolePrinter::prettyPrint("Listening...");

return;

********

2) Return to "2. Build the SDK" in Step by Step Guide and execute again every step untill "4. Run the sample app" except for 3.1.

3) Copy a short sound file "re.wav" and paste it in "/home/pi/sdk-folder/application-necessities/sound-files".

Step 3: Install Google Assistant SDK

A very thorough Step by Step Guide is provided in web. Just following it, you can install Google Assistant Libraryin your Pi, and run a sample code in it. Call "OK Google!" or "Hey Google!"

To know whether your call reaches your Pi, turning LEDs On and ringing short sounds are added in the sample code "/home/pi/assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/library/hotword.py".

(*) The editor in Instructables cannot express indents. Adequate indents are needed in each lines below in python code.

1) Add 3 lines after "import json" in the sample code "hotword.py".

*******

import RPi.GPIO as GPIO

import time

import subprocess

********

2) Add 2 lines after "print()" in "def process_event(event, device_id):" in the sample code "hotword.py".

*******

if event.type == EventType.ON_CONVERSATION_TURN_STARTED:

print() # Add the following 2 lines:

GPIO.output(23, 1)

subprocess.call("aplay /home/pi/sdk-folder/application-necessities/sound-files/re2.wav", shell=True)

print(event)

*******

3) Add 2 lines after "'device_id:', assistant.device_id + '\n')" in "def main():" in the sample code "hotword.py", and save it.

*******

with Assistant(credentials, args.device_model_id) as assistant:

events = assistant.start()

print('device_model_id:', args.device_model_id + '\n' +

'device_id:', assistant.device_id + '\n') # Add the following 2 lines:

GPIO.setmode(GPIO.BCM)

GPIO.setup(23, GPIO.OUT, initial=GPIO.LOW)

*******

4) Copy a short sound file "re2.wav" and paste it in "/home/pi/sdk-folder/application-necessities/sound-files".

Step 4: Install PulseAudio and Run 2 Navigators Together

At the end of the former step, you can run each of voice navigators respectively; Alexa and Google Assistant. However you cannot run these two navigators at the same time. Hence install "PulseAudio". You can run these two navigators at the same time.

********

sudo apt-get install pulseaudio

********

[note]

You should run Alexa at first, and call Google Assistant later. If you want run only Google Assistant, stop PulseAudio before calling it.

********

pulseaudio -k

********

If you call a navigator when the other navigator is speaking, your Pi will get confused. Hence you should wait for or interrupt the latter to finish speaking. However, it is interesting to solve confused Pi. Enjoy!

Share

    Recommendations

    • Tiny Home Contest

      Tiny Home Contest
    • Audio Contest 2018

      Audio Contest 2018
    • Metalworking Contest

      Metalworking Contest

    Discussions