I’ve set up an ESP32 D1 min as a media player. I’m trying to use TTS specifically, but I would like to play media for some things in the future. The esphome config I’m using is:
I have confirmed the i2s pins and wiring by installing a non-esphome Bluetooth speaker code on the d1 mini, and it works. I am using the current version of esphome, but I have also tried a dev branch because of this thread: Automatically convert TTS audio to MP3 on demand #102814
I’ve tried the TTS from google, Cloud, and Pipper. All 3 TTS service and the MP3 and Wav play through HA via the browser.
This is what is displayed in the ESPHome logs:
[00:29:31][D][media_player:059]: 'Media Player' - Setting
[00:29:31][D][media_player:066]: Media URL: http://homeassistant:8123/api/tts_proxy/b11aa06073e16ce48220ac67df4e47eacad46636_en-us_-_google_translate.mp3
[00:29:32][W][component:214]: Component i2s_audio.media_player took a long time for an operation (0.60 s).
[00:29:32][W][component:215]: Components should block for at most 20-30ms.
[00:29:32][W][component:214]: Component i2s_audio.media_player took a long time for an operation (0.42 s).
[00:29:32][W][component:215]: Components should block for at most 20-30ms.
If i copy the link to the mp3 file, it does play in the chrome.
I’ve searched this thread and google for answers but have not found anything that works. With so many people getting this to work, I hope I haven’t missed something simple.
Long shot, but try forcing none for the WiFi power_save_mode, see if that makes any difference. I’ve seen it mentioned here and there as causing issues.
From your logs, it appears you are using esp-wrover-kitlink for the board config, but you mentioned a D1 Mini, any reason you are not using wemos_d1_mini32link?
The other thing I can see is timing, barely a second between start and end of play… but you said that same mp3 played in the browser, right? Did you try uploading a plain mp3 file to HA (Media > My Media > MANAGE) and playing that?
I have tried to play both a Wav and an MP3 file from the media folder from HA… they both play when the target device is Chrome, but not the device.
One more piece of information… is I can’t get this to work on an M5Stack Atom Echo… if I set the Echo up as a Voice Assistance… it semi works. (semi… it’s not dependable). But TTS or playing media files don’t work.
Did you check the time between MEDIA_PLAYER_STATE_PLAYING and MEDIA_PLAYER_STATE_IDLE in the verbose logs when playing an mp3/wav file? Is it “as expected”?
If you can’t get it to work with either board, but you confirm it works with same wiring/accessories/board with a non-esphome firmware, then I’m at a loss I’m afraid.
Maybe one of the ESPHome wizards can help better than me.
I did check. I’ve used the projects | Media Player from the ESPhome.
I changed the log level to Very_Verbos. Here is the output when trying to play a wav file.
[18:44:32][C][audio:225]: External DAC channels: 1
[18:44:32][C][audio:226]: I2S DOUT Pin: 25
[18:44:35][VV][scheduler:226]: Running interval '' with interval=5000 last_execution=29603 (now=34603)
[18:44:35][VV][light.addressable:015]: Addressable Light 'M5Stack Atom Speaker Kit 8a2098' (effect_active=NO)
[18:44:35][VV][light.addressable:019]: [ 0] Color: R= 0 G= 0 B= 0 W= 0
[18:44:35][VV][light.addressable:021]:
[18:44:35][VV][api.service:777]: on_media_player_command_request: MediaPlayerCommandRequest {
key: 4249557831
has_command: NO
command: MEDIA_PLAYER_COMMAND_PLAY
has_volume: NO
volume: 0
has_media_url: YES
media_url: 'http://homeassistant:8123/media/local/piano-f-a1.wav?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlYTE4NmUxMDYwZDc0NDM1OWUyY2E3ZDBiMzFiODg0OCIsInBhdGgiOiIvbWVkaWEvbG9jYWwvcGlhbm8tZi1hMS53YXYiLCJwYXJhbXMiOltdLCJpYXQiOjE3MDM5Nzk4NzUsImV4cCI6MTcwNDA2NjI3NX0.l10kWQJ-vxsQe0ArA
[18:44:35][D][media_player:059]: 'M5Stack Atom Speaker Kit 8a2098' - Setting
[18:44:35][D][media_player:066]: Media URL: http://homeassistant:8123/media/local/piano-f-a1.wav?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlYTE4NmUxMDYwZDc0NDM1OWUyY2E3ZDBiMzFiODg0OCIsInBhdGgiOiIvbWVkaWEvbG9jYWwvcGlhbm8tZi1hMS53YXYiLCJwYXJhbXMiOltdLCJpYXQiOjE3MDM5Nzk4NzUsImV4cCI6MTcwNDA2NjI3NX0.l10kWQJ-vxsQe0ArAIrgzFuOFNWasJxa0G_GuB5YU_E
[18:44:35][W][component:214]: Component api took a long time for an operation (0.09 s).
[18:44:35][W][component:215]: Components should block for at most 20-30ms.
[18:44:36][VV][api.service:324]: send_media_player_state_response: MediaPlayerStateResponse {
key: 4249557831
state: MEDIA_PLAYER_STATE_PLAYING
volume: 1
muted: NO
}
[18:44:36][W][component:214]: Component i2s_audio.media_player took a long time for an operation (0.61 s).
[18:44:36][W][component:215]: Components should block for at most 20-30ms.
[18:44:36][VV][api.service:324]: send_media_player_state_response: MediaPlayerStateResponse {
key: 4249557831
state: MEDIA_PLAYER_STATE_IDLE
volume: 1
muted: NO
I didn’t get anywhere trying to trace your logs in the codebase, too many places where it could be failing, not enough info; the i2s_audio stuff seems to be severely lacking debug logging. But I have little doubts it is cancelling play for some reason, according to your logs.
A few suggestions:
Keep your tests to one device, now that you know neither work. The M5 should be easier to debug, since the project builder code is made for that device, compared to the raspi code used on a different model board (just trying to remove potential “unrelated” interference).
Have you tried replacing the media_player component with the speaker component to see if you can get it to play something with voice_assistant TTS (or raw data…)?
Have you tried a file on a different URL than that of HA? Change the below URL to something else if you prefer (this is a 16sec rain sound), just not something hosted on the HA machine.
It was a DNS look-up issue… my router uses 8.8.8.8 (google) DNS servers… and it doesn’t know about http://homeassistant:8123… and therefore the ESPHome couldn’t download the media file.
Two different fixes fixes here: 1st: Implement a local DNS, and assign a static address with my local DNS. (not ideal in my environment) 2nd:which I’m going to implement: under Setting | System | Network | Home Assistant URL — I changed the Local network from HTTP://homeassistant:8123 to Automatic