hassio-addons icon indicating copy to clipboard operation
hassio-addons copied to clipboard

get key failed from Google

Open jzee opened this issue 3 years ago • 17 comments

Just installed the add-on from scratch, succeeded authenticating and creating an API key, configuring the plug-in with the client keys and secret

I'm running on hass.io 0.118.5

As an initial test, I tried to call http://hassio.local:8349/api/speakText?playerId=RINCON_XXXXXXXXXXXXXXXXX&text=hello&volume=20

There was nothing audible on my system, instead I received the following error {"success":false,"error":"Error: get key failed from google\n at /app/node_modules/google-tts-api/lib/key.js:30:32\n at processTicksAndRejections (internal/process/task_queues.js:97:5)\n at async /app/server/index.js:319:17"}

What am I doing wrong?

EDIT: api/playClip works fine and the audio plays alright!

The plug-in log shows

s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
> [email protected] server /app
> node server | pino-colada
Starting with configuration: {
  SONOS_CLIENT_ID: '<hidden>',
  SONOS_CLIENT_SECRET: '<hidden>,
  GOOGLE_TTS_LANGUAGE: 'en-US'
}
Express server is running on localhost:8349
(node:206) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
16:58:27 ✨ request completed GET 304 /api/speakText?playerId=RINCON_XXXXXXXXXXXXXXXXX&text=hello&volume=20 344ms

My system configuration is as follows:

System Health

Home Assistant Core Integration

version: 0.118.5
installation_type: Home Assistant OS
dev: false
hassio: true
docker: true
virtualenv: false
python_version: 3.8.6
os_name: Linux
os_version: 4.19.127-v7l
arch: armv7l
timezone: <hidden>

Home Assistant Cloud

logged_in: false
can_reach_cert_server: ok
can_reach_cloud_auth: ok
can_reach_cloud: ok

Hass.io

host_os: HassOS 4.17
update_channel: stable
supervisor_version: 2020.12.2
docker_version: 19.03.12
disk_total: 28.0 GB
disk_used: 6.9 GB
healthy: true
supported: true
board: rpi4
supervisor_api: ok
version_api: ok
installed_addons: TellStick (2.0), File editor (5.2.0), Node-RED (7.2.11), Terminal & SSH (8.10.0), deCONZ (6.5.0), Plejd (0.4.8), Mosquitto broker (5.1)

Lovelace

dashboards: 2
mode: storage
views: 7
resources: 0

jzee avatar Dec 05 '20 16:12 jzee

I have the same issue with the Google key failure. I'm not able to get the playClip to work either, but I have a feeling that I'm just not doing that part right.

patchrick84 avatar Dec 10 '20 20:12 patchrick84

Same here as well, just installed from scratch and am getting the same message. /api/playClip doesn't work either, but this time I get success false and missing parameters. Edit: Hey @patchrick84 and @jzee after a bit of looking around, I've found that some of the forks have been updated. If you want just a doorbell sound, and no speech, you want this one as I get the same error if I try to send text to it from @Letrab. https://github.com/Letrab/hassio-addons This one seems to work with text, but no doorbell chime from @jeffothy. https://github.com/jeffothy/hassio-addons Hopefully @kevinvincent will be able to see what's changed from here and update the main addon.

blindndangerous avatar Dec 11 '20 09:12 blindndangerous

I am willing to merge the changes from @jeffothy to my fork if that helps?

The better option would be to replace the Google tts altogether in the end: https://github.com/kevinvincent/hassio-addons/issues/6

Letrab avatar Dec 14 '20 10:12 Letrab

@Letrab That'd work I think. Definitely switching over to google cloud would be great as well.

blindndangerous avatar Dec 14 '20 11:12 blindndangerous

I appreciate the work you guys are putting into this. As a non-developer I'd be stranded in the water without your help. Looking forward to your merges and changes!

patchrick84 avatar Dec 14 '20 11:12 patchrick84

Updated my fork just now. Untested though atm...

Upgraded all packages to be future-proof. So as well the oauth module for example, so could be that authentication is broken. If so, let me know!

Letrab avatar Dec 14 '20 12:12 Letrab

I hope this isn't too noob of me, but bear with me. How do I add Letrab's fork to Home Assistant? If I go to your page and copy your link to add to the repositories in HA, it still links here to Kevin's.

patchrick84 avatar Dec 15 '20 13:12 patchrick84

@patchrick84 : Try again now, changed all URL to reference to my fork, which is needed apparently. Let me know if it works (as I don't use hassio myself, I use this module standalone).

Letrab avatar Dec 15 '20 14:12 Letrab

Alright, now I'm getting "success: false" when I do the "allclipcapabledevices" step. I redid the entire thing from scratch, even regenerated my API key on the Sonos site, but still no go.

Edit: After restarting the add-on it produced more info. Here's the log:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0. [s6-init] ensuring user provided files have correct perms...exited 0. [fix-attrs.d] applying ownership & permissions fixes... [fix-attrs.d] done. [cont-init.d] executing container initialization scripts... [cont-init.d] done. [services.d] starting services [services.d] done.

[email protected] server /app node server | pino-colada Starting with configuration: { SONOS_CLIENT_ID: '(deleted)', SONOS_CLIENT_SECRET: '(deleted)', GOOGLE_TTS_LANGUAGE: 'en-US', LOCAL_URL: 'hassio.local', PORT: 8349 } Express server is running on http://hassio.local:8349 Access Token Error Response Error: 400 Bad Request Access Token Error Response Error: 400 Bad Request TypeError: Cannot read property 'households' of undefined at /app/server/index.js:220:14 at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:207) UnhandledPromiseRejectionWarning: ReferenceError: hhResultText is not defined at /app/server/index.js:230:58 at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:207) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:207) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 16:11:28 ✨ request completed GET 200 /api/allClipCapableDevices 159ms

patchrick84 avatar Dec 15 '20 20:12 patchrick84

Should have tested it first. Made an error porting to the new oAuth library... Fixed now! Sorry for the inconvenience @patchrick84 !

Letrab avatar Dec 16 '20 08:12 Letrab

@Letrab - it's working now! At least, through the URL bar in my browser. Now I just have to teach myself how to integrate it into Home Assistant. I'm still a noob on that front!

Thanks!

patchrick84 avatar Dec 17 '20 19:12 patchrick84

@Letrab - it's working now! At least, through the URL bar in my browser. Now I just have to teach myself how to integrate it into Home Assistant. I'm still a noob on that front!

Thanks!

As said, I am not an hassio user myself. But as @kevinvincent stated in his documentation, you can use a rest command from hassio: https://www.home-assistant.io/integrations/rest_command/ . Just paste your wanted URL there ;-).

If you need parameters in the URL, you can follow this guide: https://community.home-assistant.io/t/execute-rest-command-with-variable-url-etc/53913/3

eg:

rest_command:
  speak_text:
    url: "https://hassio.local/api/speakText?text={{ text }}&playerId={{ playerId }}"

script:
  test_speakText_cmd:
    sequence:
      service: rest_command.speak_text
      data:
        text: "Good morning Vietnam!"
        playerId: "RINCON_01234567890123456"

(again, untested, but should be quite it :-)) Could be that you have to change http to https or add verify_ssl: false to get it working properly.

Letrab avatar Dec 18 '20 09:12 Letrab

Yup! Through several Google searches and other reading, that's almost exactly what I came up with as well and actually got a test set up working yesterday afternoon. Thanks again for your help and work on this! Hopefully it stays working for a long time.

patchrick84 avatar Dec 18 '20 11:12 patchrick84

Hi @Letrab ,

I tried using your fork to fix the key issue, but it seems that the new API change has caused the language param to not work. The old API was const url = await googleTTS('Hello World', 'en', 1); and the new one expects the second param to be a config object instead of the language. Your fork still uses the old params on line 255 (https://github.com/Letrab/hassio-addons/blob/f482c000eb450e6b79c98f0073be94691f8126d8/sonos-audioclip-tts/server/index.js#L255)

Shouldn't this be changed to the following?

speechUrl = googleTTS.getAudioUrl(
  text,
  {
    lang: config.GOOGLE_TTS_LANGUAGE,
    slow: false
  }
);

kallioaleksi avatar Dec 30 '20 11:12 kallioaleksi

Hey everyone, I've merged in @jeffothy pull request which I believe should fix this based on a quick read of the comments. If not, please let me know and I'll make any further fixes! Sorry for not responding to this as I've been fairly busy with other projects.

kevinvincent avatar Dec 31 '20 00:12 kevinvincent

Also ideally you can move to calling HASS's TTS to get a media file URL and then send that to playClip. This can be accomplished using this method: https://www.home-assistant.io/integrations/tts/#post-apitts_get_url and then calling playClip with the returned URL. The benefit of this method is that you can use any TTS service that integrates with HASS already.

kevinvincent avatar Dec 31 '20 00:12 kevinvincent

Hi @Letrab ,

I tried using your fork to fix the key issue, but it seems that the new API change has caused the language param to not work. The old API was const url = await googleTTS('Hello World', 'en', 1); and the new one expects the second param to be a config object instead of the language. Your fork still uses the old params on line 255 (https://github.com/Letrab/hassio-addons/blob/f482c000eb450e6b79c98f0073be94691f8126d8/sonos-audioclip-tts/server/index.js#L255)

Shouldn't this be changed to the following?

speechUrl = googleTTS.getAudioUrl(
  text,
  {
    lang: config.GOOGLE_TTS_LANGUAGE,
    slow: false
  }
);

Correct! Fixed

https://github.com/Letrab/hassio-addons

Letrab avatar Jan 02 '21 21:01 Letrab