Text To Speech on Android Auto

Step 1: Shell command to retrieve the path (there might be easier ways to achieve this, but the only way I found is through the API)

shell_command:
  tts_api: >
    curl -X POST -H "Authorization: Bearer <<your long lived access token>>" -H "Content-Type: application/json" -d '{"message": "{{mymessage}}", "engine_id": "google_cloud"}' http://localhost:8123/api/tts_get_url

Depending on your engine you might have to change the engine id (translate, polly, nabu casa,…).

Step 2 (optional): Make a script that parses the full 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':
        '<<your external https HA URL>>{{parsed_data.path}}' }
  - stop: Return answer
    response_variable: answer
mode: single
fields:
  message:
    selector:
      text: null
    name: message
    description: TTS Message
    required: true

Step 3: Use it in scripts and automations:

sequence:
  - service: script.tts_service_url
    data:
      message: >-
        The text that should be spoken
    response_variable: url
  - service: notify.mobile_app_florian #Change to your service
    data:
      message: command_activity
      data:
        intent_package_name: org.videolan.vlc
        intent_action: android.intent.action.VIEW
        intent_uri: "{{url.value}}"
1 Like