TTS with MQTT and ESP8266

Hello~
I’ve got myself an ESP8266 with DAC and ESP8266Audio that can play MP3 from URL and here is the problem. Does anyone know how to make google TTS service to output the URL of the local file to MQTT payload? I’m kinda new and I’m still trying to learn the syntax.

So far I’ve tried to make media_player like this in configuration.yaml

media_player:
  - platform: universal
name: ESP
commands:
  select_source:
    service: mqtt.publish
    data_template:
      topic: "esp/test"
      payload: '{{ source }}'

tts:
  - platform: google
    language: 'cs'

and then in scripts.yaml

TestEsp:
  alias: "testing ESP"
  sequence:
    - service: tts.google_say
      data:
        message: 'Test Test Test.'

but this script is somehow wrong

Invalid config for [script]: [TestEsp] is an invalid option for [script]

any ideas ?

make sure your indentation is correct. It doesn’t look like it is for the media player.

And change the capital letters in “TestEsp” to all lower case. You can use a _ between to help readability (test_esp)

that fixed the Invalid config but there is still silence on the MQTT and i have no idea how to pass the URL link to the MQTT

try:

http://HA_IP_address:HA_Port/local/mp3_file_name.mp3

I’ve tried to access the generated files by tts via http but it’s 404 no mater what. I’ve tried ip:8123/local/file.mp3 ip:8123/local/tts/file.mp3 and ip:8123/file.mp3
I’ve only managed to get the file when I set the catch_dir: www then I can access the file with ip:8123/local/file.mp3

anyway, I need to pass that url adress (ip:8123/local/file.mp3) via mqtt payload. I don’t mind if I’ll use the www directory.

Update:
i’ve found that the file is on url: ip/api/tts_proxy/file.mp3
Still dont know how to pass this into mqtt

did you find a solution to this, how is the esp8266 producing the sound when received ?

I’m really close to an implementation of this. My code is really sloppy because I suck. I need some alpha testers to help me.

I have the ESP able to receive soma.fm streams via MQTT and today got it working with MQTT TTS served from the home assistant API folder. This effectively creates an ESP8266 Audio Node that gets served from HA. I need to figure out how to access the TTS filename from HA through a template.

I used https://github.com/earlephilhower/ESP8266Audio

It kinda works. If anyone is interested, I’d be happy to share the code.

I posted on reddit and there was interest so here is the repo. Making this public is a first for me so let me know what I forgot.

3 Likes

@jumblies do you have any plans to do a nice youtube walk through of this, seems to be a great idea for door bells, washer/dryer notifications etc without having to go looking for the phone to see a notification on there. let me know if you do a youtube video, id love to see it.

I haven’t seen much interest but I’d be happy to try my hand.

I could use some guidance. Have you tried it yet and failed? If so, how far did you get?

I’ve got it playing HA TTS messages with some distortion which I think is due to the amp and might be bitrate dependent (Google TTS) is low and webradio plays just fine.

I havent tried it yet, i was waiting to see if there was a tutorial video, if i get some time over the next couple of weeks i will, if i succeed, ill do a video

Great! Give it a whirl. I’m using the mono amp with a 4W speaker. Using the other DAC I don’t think I got distortion. If you have all the parts it should be almost turn key. Needs MQTT broker and WiFi creds and then can be uploaded to a D1 mini.

What was the part number for the amp that you used, i want to order all the parts needed, could you list what you used

Max98357 I2S 3W Class D Amplifier
PLUS
Speaker
OR
DAC Module CJMCU-1334 UDA1334A I2S DAC Audio Stereo Decoder Module
PLUS your own powered speakers

With the mono amp, I have distortion of TTS files but I don’t think I have it with the stereo module. I believe it is due to clipping present in the MP3 files generated by google TTS but I don’t have a ton of solid evidence to back that up. Web radio plays fine through the mono amp with speaker without distortion and that is built into the code uploaded to github

1 Like

so is it work ? about sending TTS from home assistant to esp32 with speaker ?