OH3 Google TTS: Error - grant type authorization_code

Dear Openhabians,

after my upgrade to OH3 I struggle to get Google Cloud TTS running again.
I have managed to go through the following process:

  1. I added a client ID in the google API console (TV and limited input device)
  2. Requested the token using:
https://accounts.google.com/o/oauth2/auth?client_id=MYCLIENTID&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/cloud-platform&response_type=code
  1. I input the client ID, the client secret and the code that I got from the request above in the google tts settings in OH3.

Now this is where I’m stuck - OH is telling me:

Error initializing Google Cloud TTS service: Exception in oauth communication, grant type authorization_code

Does anybode have a hint on what it want’s from me? Do I need to request a different kind of code?

Thank you so much for your help!

Bob

Hi Bob,

IIRC I sometimes ran into a similar issue during implementation of the OAuth2 authorization for Google TTS service. The reason for this was that the “copy to clipboard” method of GCP added a whitespace in front of (or behind, did not remember in detail) the secret. Can you check your copied values by pasting them.into a plain text editor in advance?

Hi and thank you for the quick reply!

I have checked it and it doesn’t have any whitespaces or the like.
My token starts with 4/1AY0e-g7…
Is it normal to have special characters like / and - in there?

Yes, that is looks valid.

If that did not help you might want to enable TRACE log for org.openhab.voice.googletts and org.openhab.core.auth.oauth2client te get more information and see some details if the communication. If you need help to analyze it you can share the log with me. But it might be better to do that via PM because of sensitive data.

1 Like

Thanks to @cweitkamp I want to share the solution:

The important step is to select “Desktop application” when creating an ClientID on the google platform. TV and limited input device will not work.

Then it works as expected!

1 Like

I basically ran into the same situation like Bob but then finally was able to get the authorization code (you also have make sure that in the google api “consent screen” you put your API to “production”.

However, I now get the error

No TTS service can be found for voice googletts:deDEStandardA

What am I missing?

TIA
Stefan

Hi Stefan,

it looks like your authentication didn’t go through. Or - and that’s a problem I’m having - it went missing again.
For me, after a week or so, suddenly my Google voice will become silent and I need to authenticate again. :frowning:

Do you know how I can check if the authentication went through? I guess like so

log:set TRACE org.openhab.voice.googletts
log:set TRACE org.openhab.core.auth.oauth2client

I retrieved the auth code, edited the OH page and saved it again:

2021-03-01 10:18:25.555 [DEBUG] [.googletts.internal.GoogleTTSService] - Updating configuration
2021-03-01 10:18:25.560 [TRACE] [.googletts.internal.GoogleTTSService] - New configuration: GoogleTTSConfig{pitch=0.1, speakingRate=1.0, volumeGainDb=0.0, purgeCache=false}
2021-03-01 10:18:25.561 [DEBUG] [ce.googletts.internal.GoogleCloudAPI] - Trying to get access and refresh tokens.
2021-03-01 10:18:25.570 [DEBUG] [oauth2client.internal.OAuthConnector] - Oauth request parameter grant_type, value authorization_code
2021-03-01 10:18:25.571 [DEBUG] [oauth2client.internal.OAuthConnector] - Oauth request parameter code, value 4/1AY0e-g5XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXzbsT1JNbAp_8
2021-03-01 10:18:25.572 [DEBUG] [oauth2client.internal.OAuthConnector] - Oauth request parameter redirect_uri, value urn:ietf:wg:oauth:2.0:oob
2021-03-01 10:18:25.572 [DEBUG] [oauth2client.internal.OAuthConnector] - Setting authentication for clientId 812xxxx4617XXXXXXXX5trg0vm1m01omo.apps.googleusercontent.com. Using basic auth false
2021-03-01 10:18:25.932 [DEBUG] [oauth2client.internal.OAuthConnector] - grant type authorization_code to URL https://accounts.google.com/o/oauth2/token success
2021-03-01 10:18:25.939 [DEBUG] [lient.internal.OAuthStoreHandlerImpl] - Decrypting token: AccessTokenResponse [accessToken=2coIXXXXXXXXAoCe+EuN08QaEZpmKWnJt1HG/TtHZhXXJ8Wvc/Ws5Xx0zCRaTyPXTMQXXXXXXXXXXXX, tokenType=Bearer, expiresIn=3599, refreshToken=qMSIzXXXXX8twY=, scope=https://www.googleapis.com/auth/cloud-platform, state=null, createdOn=2021-03-01T10:18:25.931931]
2021-03-01 10:18:26.210 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: undefined
2021-03-01 10:18:26.235 [TRACE] [.googletts.internal.GoogleTTSService] - Initializing voices
2021-03-01 10:18:26.236 [TRACE] [.googletts.internal.GoogleTTSService] - Initializing audio formats
2021-03-01 10:18:26.237 [WARN ] [.googletts.internal.GoogleTTSService] - Audio format OGG_OPUS is not yet supported.
2021-03-01 10:18:26.237 [TRACE] [.googletts.internal.GoogleTTSService] - Audio format not supported: OGG_OPUS
2021-03-01 10:18:26.238 [TRACE] [.googletts.internal.GoogleTTSService] - Audio format supported: MP3
2021-03-01 10:18:26.239 [TRACE] [.googletts.internal.GoogleTTSService] - Audio format supported: LINEAR16
2021-03-01 10:18:26.243 [DEBUG] [.googletts.internal.GoogleTTSService] - Updating configuration
2021-03-01 10:18:26.244 [TRACE] [.googletts.internal.GoogleTTSService] - New configuration: GoogleTTSConfig{pitch=0.1, speakingRate=1.0, volumeGainDb=0.0, purgeCache=false}
2021-03-01 10:18:26.245 [DEBUG] [lient.internal.OAuthStoreHandlerImpl] - Decrypting token: AccessTokenResponse [accessToken=2coI0AFwRAzTMQ09b9muWW13W08hjjtihoqOdq18bhgC3tfH, tokenType=Bearer, expiresIn=3599, refreshToken=qMSIza061SpDrt1HaY2z9Gio+Y1jCccWuR/4lSxytLVsqqgmWK2HbXOf7548twY=, scope=https://www.googleapis.com/auth/cloud-platform, state=null, createdOn=2021-03-01T10:18:25.931931]
2021-03-01 10:18:26.289 [TRACE] [.googletts.internal.GoogleTTSService] - Initializing voices
2021-03-01 10:18:26.291 [TRACE] [.googletts.internal.GoogleTTSService] - Initializing audio formats
2021-03-01 10:18:26.292 [WARN ] [.googletts.internal.GoogleTTSService] - Audio format OGG_OPUS is not yet supported.
2021-03-01 10:18:26.293 [TRACE] [.googletts.internal.GoogleTTSService] - Audio format not supported: OGG_OPUS
2021-03-01 10:18:26.293 [TRACE] [.googletts.internal.GoogleTTSService] - Audio format supported: MP3
2021-03-01 10:18:26.294 [TRACE] [.googletts.internal.GoogleTTSService] - Audio format supported: LINEAR16

which to me looks good.

then I am issueing a say-command like so

say(“Hi”,“googletts:deDEStandardA”,“chromecast:chromecast:686668768768767ed035d702f3fd4a6”, new PercentType(50))
and I get

2021-03-01 10:34:09.767 [WARN ] [core.voice.internal.VoiceManagerImpl] - Error saying 'Hi': No TTS service can be found for voice googletts:deDEStandardA

org.openhab.core.voice.TTSException: No TTS service can be found for voice googletts:deDEStandardA

Hi, your auth looks good!
Can you select a standard voice in the UI and try to issue a say command without specifying a voice?

There is no way to select a “standard” voice in the UI or do you refer to a different setting?


I removed the setting and issued the command in the console

openhab:voice say Hello world!

and when I re-add the voice to it


and

openhab:voice say Hello world!

I get

The “Default Voice” field should be a selection list of all voices that can be selected for your tts service (Google). Can you confirm you get a list of voices when you click on it?
Did you use “Desktop” as application as described earlier in this thread?
It looks like your authentication goes through, but it is not able to connect to the Google tts service…

No, none of these are dropdowns (like it was the case in OH2 - note that I am already on 3.1). Both are text boxes.

And yes, my client is Desktop (and I also tried “TV” like explained in the actual documentation).

Hi Stefan,

I ran into the same issue yesterday:

After some digging and following the different links in the binding documentation, I have noticed a message on the top of one of the pages saying that my trial or demo period was over (I don’t remember the exact wording). After I confirmed that I want to proceed with a “full account” it started to work again after I had created a new Authorization Code for the binding.

Hope this helps.
Matt

2 Likes

OMG, it was always there at the very top and I happily ignored all the time :man_facepalming:

Matt, you saved my day! :man_superhero:

  • Press “Sign up now” and click through two pretty unimpressive dialogs and you are set!
  • As stated above I authenticated again and the major difference is what appears afterwards in the logs:
2021-03-01 18:42:42.383 [TRACE] [.googletts.internal.GoogleTTSService] - Initializing voices
2021-03-01 18:42:42.385 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: en-AU-Wavenet-B
2021-03-01 18:42:42.386 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: en-GB-Wavenet-D
2021-03-01 18:42:42.386 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: fr-FR-Standard-D
2021-03-01 18:42:42.387 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: fr-FR-Standard-B
2021-03-01 18:42:42.388 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: fr-CA-Standard-A
2021-03-01 18:42:42.389 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: ru-RU-Standard-D
2021-03-01 18:42:42.390 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: ml-IN-Standard-A
2021-03-01 18:42:42.391 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: ru-RU-Standard-B
2021-03-01 18:42:42.392 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: en-US-Wavenet-E
2021-03-01 18:42:42.393 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: pt-PT-Wavenet-B
2021-03-01 18:42:42.394 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: fr-CA-Wavenet-D
2021-03-01 18:42:42.395 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: en-AU-Wavenet-D
2021-03-01 18:42:42.396 [TRACE] [.googletts.internal.GoogleTTSService] - Google Cloud TTS voice: en-IN-Standard-A
....

And guess what, surprise, I can select the Language in der Voice Field mentioned above which is filled with what was retrieved from Google and shown in the logs!

It also shows in the logs that it creates the sound

2021-03-01 18:49:38.465 [DEBUG] [.googletts.internal.GoogleTTSService] - Synthesize ‘Hallo Welt’ for voice ‘googletts:deDEStandardA’ in format AudioFormat [codec=MP3, container=NONE, bitDepth=16, bitRate=64000, frequency=44100]

and I can find the mp3 in the cache folder.

So the text-to-speech problem is solved. However, sigh, it is not played back.

So, I went further and for those who do have the same problem: the chromecast binding contains a callback URL which MUST point back to the openhab-URL (in my case because I have migrated from OH2 to OH3 the ip address had changed, so the URL became wrong!). So I changed it now everything is working.

…all’s well that ends well :slight_smile:

Thanks to you, Matt and Bob for the support!
Stefan

2 Likes

Good find! I wonder if you experience the same as me - having to re-authenticate every few weeks. Please let me know if that’s the case, right now I haven’t looked into it too much…

Yep, I will definitely tell you if that’s the case.

1 Like

I just had to reauthenticate again yesterday, I think 2 weeks after my initial authentication. Previously my application was Tv and limited input, now i tried desktop app.

Interesting! Thanks for the feedback - so it seems I’m not the only one! Two weeks also match what I’m experiencing!
Maybe there’s a setting in the google dev console that could prevent this?

Maybe this has to do with the lifetime of the access or refresh token? Do you see an error in the trace when it starts not responding anymore?

Yes, I could see exception