Hello,
Based on this example Text To Speech on Android Auto - Mobile Apps / Home Assistant Companion for Android - Home Assistant Community I’m trying to get message played on Android auto using car speakers.
I’m using picotts service and using curl I get the mp3 file generated.
curl -X POST -H "Authorization: Bearer long live token" -H "Content-Type: application/json" -d '{"message": "mymessage", "engine_id": "picotts"}' http://ha_local_ip_address:8123/api/tts_get_url
Answer is:
{"url":"http://local_ip_address:8123/api/tts_proxy/V2-xoCXQA76JuAE7swuY2A.mp3","path":"/api/tts_proxy/V2-xoCXQA76JuAE7swuY2A.mp3"}
A shell command is set-up as such:
tts_api: >
curl -X POST -H "Authorization: Bearer long live token" -H "Content-Type: application/json" -d '{"message": "{{mymessage}}", "engine_id": "picotts"}' http://ha_local_ip_address:8123/api/tts_get_url
And the script that uses it:
tts_script_service_url:
alias: TTS Service URL
variables:
answer: InitialValue
sequence:
- service: shell_command.tts_api
data:
mymessage: >
{{message}}
response_variable: json_data
- variables:
answer: >
{% set parsed_data = json_data['stdout'] | from_json %} {'value':
'http://ha_local_ip_address:8123{{parsed_data.path}}' }
- stop: Return answer
response_variable: answer
mode: single
fields:
message:
selector:
text: null
name: message
description: TTS Message
required: true
Now when the script is called with automation:
alias: Message parlé avec VLC
description: ""
triggers:
- trigger: state
entity_id:
- input_button.message_parle
conditions: []
actions:
- sequence:
- data:
message: Mon message parlé
response_variable: url
action: script.tts_script_service_url
- data:
message: command_activity
data:
intent_package_name: org.videolan.vlc
intent_action: android.intent.action.VIEW
intent_uri: "{{url.value}}"
action: notify.mobile_app_nokia_xr20
mode: single
An 401 error is triggered:
Error: ValueError: Template error: from_json got invalid input '401: Unauthorized' when rendering template '{% set parsed_data = json_data['stdout'] | from_json %} {'value': 'http://ha_local_ip_adress:8123{{parsed_data.path}}' }' but no default was specified
After a long search I’m out on idea to get this error resolved. I understand that this is a matter of authorisation but which one?
Thank you in advance for any hint that will steer me to the right direction