Hey,
(sorry if this goes in the wrong category)
My daughters are big fans of the Google Assistant feature “what sound makes {{ prompt }}”. We use it quite often on our google mini. But… Google is evil, so I wanted to use the same feature on an m5stack atom.
Integrating into home assistant was actually quite easy, all I had to do was a REST sensor as follows:
rest:
- resource_template: "https://freesound.org/apiv2/search/text/?query={{ states.input_text.prompt.state }}&fields=previews&token=itsmytokendontstealityouthieves"
sensor:
- name: "freesounds"
json_attributes_path: '$.results[0].previews'
json_attributes:
- preview-hq-mp3
value_template: "{{ states.input_text.prompt.state }}"
method: GET
And then an automation when this sensor changes, play the mp3 directly on media_player
- id: '1692645805655'
alias: stream sound when prompt changes
description: ''
trigger:
- platform: state
entity_id:
- input_text.prompt
enabled: false
- platform: conversation
command:
- what sound makes {prompt}
condition: []
action:
- service: input_text.set_value
data:
value: '{{trigger.slots.prompt}}'
target:
entity_id: input_text.prompt
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.freesounds
- service: media_player.play_media
data:
media_content_type: music
media_content_id: '{{state_attr(''sensor.freesounds'', ''preview-hq-mp3'')}}'
target:
entity_id: media_player.my_media_player_dont_copy_this_make_your_own
And all of that is great and it even works almost flawlessly. But my daughters don’t speak English.
So I was looking at options to translate one or a few words from French and from Norwegian to English, so that I can then search for the sound on the freesound.org database. I have tried to install https://libretranslate.com/ on a pi I had lying around but that didn’t go well. So I figured I could use Google Translate (because google isn’t that evil?) and it worked, but only for a short time.
rest:
- resource: "https://translation.googleapis.com/language/translate/v2"
headers:
Content-Type: "application/json"
Authorization: Bearer "mytoken!"
sensor:
- name: "translated_from_fr"
json_attributes_path: '$.data.translations[0]'
json_attributes:
- translatedText
method: POST
scan_interval: 60000
payload: '{
"q": "{{states.input_text.prompt.state}}",
"source": "fr",
"target": "en",
"format": "text"
}'
I’m guessing that the Bearer token that I found using this expired.
Then I remembered that I’m already using some google services in Home Assistant like google calendar . So I thought I could use this authentication because clearly someone figured it out already in the Application Credentials top right corner of “devices and services”
Unfortunately, the existing integration “Google Translate” does not translate words, only uses TTS.
So here is my feature request: can someone smart make a “google translate” integration that actually translates? It’s really just one post request with the correct authentication.
Alternatively, could someone help me make this auth work on a REST sensor?