arduinoesp32google-home

Voice outout on a Google Nest mini using ESP32


I am trying to output as a voice message inputted text. I am using Google Nest Mini and ESP32.

The code displayed below works as intended. It uses ghn.notify() to pass a message to the voice assistant and it says it out loud.

#include <WiFi.h>
#include <esp8266-google-home-notifier.h>

const char* ssid     = "your_ssid";
const char* password = "your_password";

GoogleHomeNotifier ghn;

void setup() 
{
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  
  const char displayName[] = "Living Room speaker";
  
  if (ghn.device(displayName, "en") != true) 
  {
    Serial.println(ghn.getLastError());
    return;
  }
  
  ghn.notify("Hi, how are you");  
}

However, when I try to pass a String as an argument to ghn.notify() I have the following error:

no matching function for call to 'GoogleHomeNotifier::notify(String&)'

This is the added code:

void loop() {
  if (Serial.available()) { 
    String command = Serial.readStringUntil('\n'); 
     
    ghn.notify(command); 
    
  }
}

Is there a way to make the voice assistant say the text that was inputted in the serial monitor?


Solution

  • I found a solution to the problem. When using

    ghn.notify(command);

    a built-in function was used to fix the error. So in the end the code looks like this:

    void loop() {
      if (Serial.available()) { 
        String command = Serial.readStringUntil('\n'); 
         
        ghn.notify(command.c_str()); 
        
      }
    }