Google Text-to-Speech not working in OH3

Hi all

I can’t get Google Text-to-Speech working in OH3. I followed the docs a few times.

Billing is enabled, Cloud Text-to-Speech API is activated. Created a OAuth 2.0 Client ID credential called openhab3. For type I selected “Desktop” instead of “TV and Limited Input” because I received the same error as described in this post.

Called the URL with my client-id, approve and get the authorization code. I enter the code in OH3 settings -> Google Cloud Text-to-Speech -> Authorization Code and save. In openhab.log I get two warnings:

[WARN ] [.googletts.internal.GoogleTTSService] - Audio format OGG_OPUS is not yet supported.

In the CLI, I try it with

openhab> openhab:voice say Hello World

I get an error in openhab.log:

2021-01-24 11:23:51.673 [WARN ] [core.voice.internal.VoiceManagerImpl] - Error saying 'Hello World ': Missing API key, configure it first before using
org.openhab.core.voice.TTSException: Missing API key, configure it first before using
at org.openhab.voice.voicerss.internal.VoiceRSSTTSService.synthesize(VoiceRSSTTSService.java:110) ~[?:?]
at org.openhab.core.voice.internal.VoiceManagerImpl.say(VoiceManagerImpl.java:221) [bundleFile:?]

Checking the setting in OH3, I see the Authorization Code is empty again. If I enter it manually again, I get the error:

2021-01-24 11:25:31.738 [ERROR] [oauth2client.internal.OAuthConnector] - grant type authorization_code to URL https://accounts.google.com/o/oauth2/token failed with error code invalid_grant, description Bad Request
2021-01-24 11:25:31.740 [WARN ] [ce.googletts.internal.GoogleCloudAPI] - Error initializing Google Cloud TTS service: Error fetching access token. Invalid authcode? Please generate a new one.

I assume the last part makes sense. It looks like the authorization code is working, so it is removed in the settings. If I try to use it again, it’s invalid because it has already been used successfully once.

What is going wrong here?

Thanks for any help

I seem to be running into a similar issue. I have regenerated a new authcode twice. It appears that the authcode has a limited lifetime before it becomes invalid and a new one needs to be generated?

Hi,
How u get an authorisation code and a client secret? I had a client id in an installation before. I saved the JSON created by google, where i see my clientID. But i dont see the Client secret and if i give the webpage in the browser with my client id, i get an error:

Hiba (400): redirect_uri_mismatch
The redirect URI in the request, urn:ietf:wg:oauth:2.0:oob, can only be used by a Client ID for native application. It is not allowed for the WEB client type. You can create a Client ID for native application at...

Pls help

Now i get this:

Authorization Error
Error 403: access_denied
The developer hasn’t given you access to this app. It’s currently being tested and it hasn’t been verified by Google. If you think you should have access, contact the developer (XXX@gmail.com).
Learn more
Request Details
response_type=code
redirect_uri=urn:ietf:wg:oauth:2.0:oob
client_id=713001946065-rokvqnbr09v026jspinn5t5uum8kopeu.apps.googleusercontent.com
access_type=offline
scope=https://www.googleapis.com/auth/cloud-platform

I recognized the same behavior. Once the Authorization Code is created properly it is working for some time and then I’m getting an error such as:

2021-02-02 10:35:41.737 [WARN ] [core.voice.internal.VoiceManagerImpl] - Error saying 'XXX': Missing service configuration.

org.openhab.core.voice.TTSException: Missing service configuration.

	at org.openhab.voice.googletts.internal.GoogleTTSService.synthesize(GoogleTTSService.java:308) ~[?:?]

	at org.openhab.core.voice.internal.VoiceManagerImpl.say(VoiceManagerImpl.java:221) [bundleFile:?]

	at org.openhab.core.voice.internal.VoiceManagerImpl.say(VoiceManagerImpl.java:176) [bundleFile:?]

When I’m then generating a new Code using this URL: https://accounts.google.com/o/oauth2/auth?client_id=&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/cloud-platform&response_type=code, it is working again for some time.

I guess this issue and the issue from the initial post, is related to the setup of the Consent Screen. In my case I’ve created an application called “Openhab” and have added myself (my google account) as test-user.

Maybe someone can describe how to setup this Consent Screen properly.

I got the exact same error.

Until now, my oauth consent screen was in “Testing” mode. I have just set this to Production, in case that would make a difference. At this point I don’t know if it would, but we’ll see!

I have the same issue. When I enter the code the first time I pass the authentication and get the following message:

2021-02-15 01:34:31.633 [WARN ] [.googletts.internal.GoogleTTSService] - Audio format OGG_OPUS is not yet supported.

2021-02-15 01:34:31.725 [WARN ] [.googletts.internal.GoogleTTSService] - Audio format OGG_OPUS is not yet supported.

But when I look in the Google Cloud Text-to-Speech settings the authorization code is empty. When I paste the same code again, it has already expired with the following log entry:

2021-02-15 01:34:50.249 [ERROR] [oauth2client.internal.OAuthConnector] - grant type authorization_code to URL https://accounts.google.com/o/oauth2/token failed with error code invalid_grant, description Bad Request

2021-02-15 01:34:50.257 [WARN ] [ce.googletts.internal.GoogleCloudAPI] - Error initializing Google Cloud TTS service: Error fetching access token. Invalid authcode? Please generate a new one.

I got it working, apparently I had to set default audio source (called Default Sink) in the settings

Same problem after some successfuly use.

2021-02-17 06:30:04.206 [ERROR] [oauth2client.internal.OAuthConnector] - grant type refresh_token to URL https://accounts.google.com/o/oauth2/token failed with error code invalid_grant, description Token has been expired or revoked.

2021-02-17 06:30:04.215 [WARN ] [ce.googletts.internal.GoogleCloudAPI] - Error initializing Google Cloud TTS service: Error fetching access token. Invalid authcode? Please generate a new one.


I too have been having this issue.

I’ve re-generated my token every week or two, and that keeps it working for another week or so, but eventually one day it stops working again and this issue comes up again. I’ve just given up at this point until a new permanent fix is found. It would be nice if it just worked like it did back in OH2 days. :slight_smile:

I did notice due to the differences, back in OH2, I previously had GoogleTTS set up using the googletts.cfg file using a private_key_id and private_key, which was reliable, and never failed on me. Using a token instead has been what’s been troublesome.

@JimT Did changing the oauth consent screen to Production make a difference with your token expiry? I don’t want to be guessing and testing multiple different things at once, and would just like to know what’s ended up working for others to get this to stop expiring/nullifying the token.

Yes, it appears that ever since I did that, my googletts has been working without needing to regenerate the key. The last time I had to generate must’ve been 4th of Feb i.e. my last post. I have even updated openhab (snapshot version) several times since.

Thanks for the confirmation! I’ve just changed it to Production, and re-did the Authorization Code, will see if it sticks for me now too. :slight_smile:

I hope someone can help me out. I try to move from VoiceRSS that is working to the Google TTS. But without any luck. The Oauth is successful but I keep getting the message:

2021-03-22 15:05:35.437 [WARN ] [core.voice.internal.VoiceManagerImpl] - Error saying 'Hoi ik ben Google': Unable to find a voice for language nl

org.openhab.core.voice.TTSException: Unable to find a voice for language nl

I just cant get it operational.In the Karaf i dont see any voices available for Google TTS, only the ones for VoiceRSS.

Any suggestions?

Resolved it. I did not found or maybe overlooked it in all the manuals and topics. But apparently it is required to enable the google TTS API in their cloud after you created your project and did all the authentication steps.

So for the ones facing the same issue as i had:

Google - Cloud to Speech

You can enable the API there.