gnumpi / esphome_audio

Custom audio components for ESPHome
Other
62 stars 23 forks source link

dev-next branch Music Assistant group player issue #47

Open darki73 opened 4 months ago

darki73 commented 4 months ago

Hey, first of all, thank you for the great work you have done!

Issue

While using a single speaker to play anything from Music Assistant, stream goes file, everything works. The only missing piece to make formats other than mp3 to work was adding codec: auto to the media player configuration block.

However, upon the creating a group of speakers, any time i try to play the audio, it results in the following errors on the device (each of them)

Log output from the device ``` [20:59:29][W][esp-idf:000]: I (356675) tsens: Config temperature range [-10°C ~ 80°C], error < 1°C [20:59:51][W][esp-idf:000]: I (378667) ESP_DECODER: esp_decoder_init, stack size is 30720 [20:59:51][W][esp-idf:000]: I (378671) I2S: DMA Malloc info, datalen=blocksize=2048, dma_buf_count=4 [20:59:51][W][esp-idf:000]: I (378681) AUDIO_PIPELINE: link el->rb, el:0x3d8188d4, tag:http, rb:0x3d81909c [20:59:51][W][esp-idf:000]: I (378691) AUDIO_PIPELINE: link el->rb, el:0x3d818bcc, tag:decoder, rb:0x3d8590dc [20:59:51][W][esp-idf:000]: I (378693) AUDIO_PIPELINE: link el->rb, el:0x3d818d68, tag:resampler, rb:0x3d89911c [20:59:51][W][esp-idf:000]: I (378723) AUDIO_THREAD: The http task allocate stack on external memory [20:59:51][W][esp-idf:000]: I (378726) AUDIO_ELEMENT: [http-0x3d8188d4] Element task created [20:59:51][W][esp-idf:000]: I (378728) AUDIO_THREAD: The decoder task allocate stack on external memory [20:59:51][W][esp-idf:000]: I (378732) AUDIO_ELEMENT: [decoder-0x3d818bcc] Element task created [20:59:51][W][esp-idf:000]: I (378747) AUDIO_THREAD: The resampler task allocate stack on external memory [20:59:51][W][esp-idf:000]: I (378750) AUDIO_ELEMENT: [resampler-0x3d818d68] Element task created [20:59:51][W][esp-idf:000]: I (378764) AUDIO_ELEMENT: [i2s_out-0x3d818f24] Element task created [20:59:51][W][esp-idf:000][decoder]: I (378804) AUDIO_ELEMENT: [decoder] AEL_MSG_CMD_RESUME,state:1 [20:59:51][W][esp-idf:000][decoder]: I (378808) ESP_DECODER: Ready to do audio type check, pos:0, (line 104) [20:59:51][W][esp-idf:000][http]: I (378813) AUDIO_ELEMENT: [http] AEL_MSG_CMD_RESUME,state:1 [20:59:51][W][esp-idf:000][http]: I (378841) HTTP_CLIENT: Body received in fetch header state, 0x3fccf247, 47 [20:59:51][W][esp-idf:000][http]: I (378846) HTTP_STREAM: total_bytes=47 [20:59:51][W][esp-idf:000][http]: E (378849) HTTP_STREAM: Invalid HTTP stream, status code = 404 [20:59:51][W][esp-idf:000][http]: E (378854) AUDIO_ELEMENT: [http] AEL_STATUS_ERROR_OPEN,-1 [20:59:51][W][esp-idf:000][http]: W (378859) AUDIO_ELEMENT: [http] audio_element_on_cmd_error,7 [20:59:51][W][esp-idf:000][decoder]: W (378866) AUDIO_ELEMENT: IN-[decoder] AEL_IO_ABORT [20:59:51][W][esp-idf:000][decoder]: E (378871) AUDIO_FORMAT: failed to get head buf data(line 175) [20:59:51][W][esp-idf:000][decoder]: E (378878) ESP_DECODER: Audio type detect error (line 147) [20:59:51][W][esp-idf:000][decoder]: W (378883) AUDIO_ELEMENT: [decoder] AEL_IO_ABORT, -3 [20:59:51][E][esp_adf_pipeline:223]: HTTPStreamReader got in error state while PREPARING. Stopping pipeline! [20:59:51][E][esp_adf_pipeline:246]: Timeout while PREPARING. Stopping pipeline! [20:59:51][W][esp-idf:000]: E (378907) AUDIO_ELEMENT: [http] Element already stopped [20:59:51][E][esp_adf_pipeline:223]: HTTPStreamReader got in error state while STOPPING. Stopping pipeline! [20:59:51][E][esp_adf_pipeline:246]: Timeout while STOPPING. Stopping pipeline! [20:59:51][W][esp-idf:000]: I (378926) AUDIO_PIPELINE: audio_pipeline_unlinked [20:59:51][W][esp-idf:000]: W (378928) AUDIO_ELEMENT: [http] Element has not create when AUDIO_ELEMENT_TERMINATE [20:59:51][W][esp-idf:000]: W (378932) AUDIO_ELEMENT: [decoder] Element has not create when AUDIO_ELEMENT_TERMINATE [20:59:51][W][esp-idf:000]: I (378935) CODEC_ELEMENT_HELPER: The element is 0x3d818bcc. The reserve data 2 is 0x0. [20:59:51][W][esp-idf:000]: W (378939) AUDIO_ELEMENT: [resampler] Element has not create when AUDIO_ELEMENT_TERMINATE [20:59:51][W][esp-idf:000]: W (378942) AUDIO_ELEMENT: [i2s_out] Element has not create when AUDIO_ELEMENT_TERMINATE [20:59:51][W][esp-idf:000]: I (378946) I2S: DMA queue destroyed [21:00:26][W][esp-idf:000]: I (413298) ESP_DECODER: esp_decoder_init, stack size is 30720 [21:00:26][W][esp-idf:000]: I (413302) I2S: DMA Malloc info, datalen=blocksize=2048, dma_buf_count=4 [21:00:26][W][esp-idf:000]: I (413311) AUDIO_PIPELINE: link el->rb, el:0x3d8188d4, tag:http, rb:0x3d81909c [21:00:26][W][esp-idf:000]: I (413320) AUDIO_PIPELINE: link el->rb, el:0x3d818bcc, tag:decoder, rb:0x3d8590dc [21:00:26][W][esp-idf:000]: I (413323) AUDIO_PIPELINE: link el->rb, el:0x3d818d68, tag:resampler, rb:0x3d89911c [21:00:26][W][esp-idf:000]: I (413353) AUDIO_THREAD: The http task allocate stack on external memory [21:00:26][W][esp-idf:000]: I (413355) AUDIO_ELEMENT: [http-0x3d8188d4] Element task created [21:00:26][W][esp-idf:000]: I (413358) AUDIO_THREAD: The decoder task allocate stack on external memory [21:00:26][W][esp-idf:000]: I (413360) AUDIO_ELEMENT: [decoder-0x3d818bcc] Element task created [21:00:26][W][esp-idf:000]: I (413376) AUDIO_THREAD: The resampler task allocate stack on external memory [21:00:26][W][esp-idf:000]: I (413379) AUDIO_ELEMENT: [resampler-0x3d818d68] Element task created [21:00:26][W][esp-idf:000]: I (413394) AUDIO_ELEMENT: [i2s_out-0x3d818f24] Element task created [21:00:26][W][esp-idf:000][decoder]: I (413410) AUDIO_ELEMENT: [decoder] AEL_MSG_CMD_RESUME,state:1 [21:00:26][W][esp-idf:000][decoder]: I (413414) ESP_DECODER: Ready to do audio type check, pos:0, (line 104) [21:00:26][W][esp-idf:000][http]: I (413420) AUDIO_ELEMENT: [http] AEL_MSG_CMD_RESUME,state:1 [21:00:26][W][esp-idf:000][http]: I (413445) HTTP_CLIENT: Body received in fetch header state, 0x3fccfccf, 47 [21:00:26][W][esp-idf:000][http]: I (413451) HTTP_STREAM: total_bytes=47 [21:00:26][W][esp-idf:000][http]: E (413456) HTTP_STREAM: Invalid HTTP stream, status code = 404 [21:00:26][W][esp-idf:000][http]: E (413460) AUDIO_ELEMENT: [http] AEL_STATUS_ERROR_OPEN,-1 [21:00:26][W][esp-idf:000][http]: W (413464) AUDIO_ELEMENT: [http] audio_element_on_cmd_error,7 [21:00:26][W][esp-idf:000][decoder]: W (413473) AUDIO_ELEMENT: IN-[decoder] AEL_IO_ABORT [21:00:26][W][esp-idf:000][decoder]: E (413478) AUDIO_FORMAT: failed to get head buf data(line 175) [21:00:26][W][esp-idf:000][decoder]: E (413483) ESP_DECODER: Audio type detect error (line 147) [21:00:26][W][esp-idf:000][decoder]: W (413488) AUDIO_ELEMENT: [decoder] AEL_IO_ABORT, -3 [21:00:26][E][esp_adf_pipeline:223]: HTTPStreamReader got in error state while PREPARING. Stopping pipeline! [21:00:26][E][esp_adf_pipeline:246]: Timeout while PREPARING. Stopping pipeline! [21:00:26][W][esp-idf:000]: E (413535) AUDIO_ELEMENT: [http] Element already stopped [21:00:26][E][esp_adf_pipeline:223]: HTTPStreamReader got in error state while STOPPING. Stopping pipeline! [21:00:26][E][esp_adf_pipeline:246]: Timeout while STOPPING. Stopping pipeline! [21:00:26][W][esp-idf:000]: I (413555) AUDIO_PIPELINE: audio_pipeline_unlinked [21:00:26][W][esp-idf:000]: W (413557) AUDIO_ELEMENT: [http] Element has not create when AUDIO_ELEMENT_TERMINATE [21:00:26][W][esp-idf:000]: W (413559) AUDIO_ELEMENT: [decoder] Element has not create when AUDIO_ELEMENT_TERMINATE [21:00:26][W][esp-idf:000]: I (413562) CODEC_ELEMENT_HELPER: The element is 0x3d818bcc. The reserve data 2 is 0x0. [21:00:26][W][esp-idf:000]: W (413564) AUDIO_ELEMENT: [resampler] Element has not create when AUDIO_ELEMENT_TERMINATE [21:00:26][W][esp-idf:000]: W (413566) AUDIO_ELEMENT: [i2s_out] Element has not create when AUDIO_ELEMENT_TERMINATE [21:00:26][W][esp-idf:000]: I (413569) I2S: DMA queue destroyed [21:00:29][W][esp-idf:000]: I (416675) tsens: Config temperature range [-10°C ~ 80°C], error < 1°C ```

Confuguration

I am using the following configuration:

---
external_components:
  - source:
      type: git
      url: https://github.com/gnumpi/esphome_audio
      ref: dev-next
    components:
      - adf_pipeline
      - i2s_audio
    # refresh: 0s

i2s_audio:
  - id: i2s_in
    i2s_lrclk_pin: GPIO7
    i2s_bclk_pin: GPIO16
  - id: i2s_out
    i2s_lrclk_pin: GPIO8
    i2s_bclk_pin: GPIO18

adf_pipeline:
  - platform: i2s_audio
    id: adf_i2s_in
    type: audio_in
    i2s_audio_id: i2s_in
    i2s_din_pin: GPIO15
    pdm: false
    channel: left
    sample_rate: 16000
    bits_per_sample: 32bit
  - platform: i2s_audio
    id: adf_i2s_out
    type: audio_out
    i2s_audio_id: i2s_out
    i2s_dout_pin: GPIO17
    adf_alc: true
    alc_max: .5

microphone:
  - platform: adf_pipeline
    id: i2s_mic
    gain_log2: 3
    keep_pipeline_alive: false
    pipeline:
      - adf_i2s_in
      - self

media_player:
  - platform: adf_pipeline
    id: i2s_player
    name: "${device_friendly_name} Media Player"
    keep_pipeline_alive: false
    codec: auto
    internal: false
    announcement_audio:
      sample_rate: 16000
      bits_per_sample: 16
      num_channels: 1
    pipeline:
      - self
      - resampler
      - adf_i2s_out

Additional Information

I am fully aware that code from the dev-next is not intended to be used on a "daily basis", so i can't really say that there is an issue with the project itself.

Just want to throw out there the issue i had, better to say it early than to refactor a lot of code later.

gnumpi commented 4 months ago

I haven't looked into the speaker groups capability of MA yet, it seems MA creates a url in that case that is not recognisable by the http client. Can you copy paste the stream URL from the log and try playing it in your browser?

darki73 commented 4 months ago

@gnumpi Hey, thanks for the reply. Just give me a couple of minutes to recompile the firmware with logging enabled and i will update this message once i will have results.

[15:47:13][D][media_player:061]: 'HA Satellite Ivan (605) Media Player' - Setting
[15:47:13][D][media_player:068]:   Media URL: http://10.11.0.20:8097/ugp/ugp_hfv6ni9w.flac?player_id=media_player.ha_bedroom_satellite_ivan_ha_satellite_ivan_605_media_player
[15:47:13][D][esp_audio_sources:098]: Set new uri: http://10.11.0.20:8097/ugp/ugp_hfv6ni9w.flac?player_id=media_player.ha_bedroom_satellite_ivan_ha_satellite_ivan_605_media_player
[15:47:13][D][adf_media_player:057]: Got control call in state IDLE
[15:47:13][D][adf_media_player:058]: req_track stream uri: http://10.11.0.20:8097/ugp/ugp_hfv6ni9w.flac?player_id=media_player.ha_bedroom_satellite_ivan_ha_satellite_ivan_605_media_player
[15:47:13][D][esp_adf_pipeline:060]: Starting request, current state UNINITIALIZED
[15:47:13][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from UNINITIALIZED to INITIALIZING. (REQ: 0)
[15:47:13][I][adf_media_player:192]: got new pipeline state: 1, while in MP state IDLE
[15:47:13][I][adf_media_player:255]: current mp state: IDLE
[15:47:13][I][adf_media_player:256]: anouncement: false
[15:47:13][I][adf_media_player:257]: play_intent: false
[15:47:13][I][adf_media_player:258]: current_uri_: yes
[15:47:14][D][esp-idf:000]: I (51763) ESP_DECODER: esp_decoder_init, stack size is 30720

[15:47:14][D][i2s_audio:067]: Install driver requested by Writer
[15:47:14][D][esp-idf:000]: I (51769) I2S: DMA Malloc info, datalen=blocksize=1024, dma_buf_count=4

[15:47:14][D][i2s_audio:073]: Installing driver : yes
[15:47:14][D][esp_adf_pipeline:497]: pipeline tag 0, http
[15:47:14][D][esp_adf_pipeline:497]: pipeline tag 1, decoder
[15:47:14][D][esp_adf_pipeline:497]: pipeline tag 2, i2s_out
[15:47:14][D][esp-idf:000]: I (51789) AUDIO_PIPELINE: link el->rb, el:0x3d8188d4, tag:http, rb:0x3d818f14

[15:47:14][D][esp-idf:000]: I (51797) AUDIO_PIPELINE: link el->rb, el:0x3d818bcc, tag:decoder, rb:0x3d858f54

[15:47:14][D][esp_adf_pipeline:507]: Setting up event listener.
[15:47:14][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from INITIALIZING to CREATED. (REQ: 0)
[15:47:14][I][adf_media_player:192]: got new pipeline state: 2, while in MP state IDLE
[15:47:14][I][adf_media_player:255]: current mp state: IDLE
[15:47:14][I][adf_media_player:256]: anouncement: false
[15:47:14][I][adf_media_player:257]: play_intent: false
[15:47:14][I][adf_media_player:258]: current_uri_: yes
[15:47:14][W][component:237]: Component adf_pipeline.media_player took a long time for an operation (55 ms).
[15:47:14][W][component:238]: Components should block for at most 30 ms.
[15:47:14][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from CREATED to PREPARING. (REQ: 0)
[15:47:14][I][adf_media_player:192]: got new pipeline state: 3, while in MP state IDLE
[15:47:14][D][adf_i2s_out:141]: Set final i2s settings: 44100
[15:47:14][I][adf_media_player:255]: current mp state: PLAYING
[15:47:14][I][adf_media_player:256]: anouncement: false
[15:47:14][I][adf_media_player:257]: play_intent: false
[15:47:14][I][adf_media_player:258]: current_uri_: yes
[15:47:14][D][esp_audio_sources:103]: Prepare elements called (initial_call)!
[15:47:14][D][esp_audio_sources:137]: Use fixed settings: no
[15:47:14][D][esp_audio_sources:138]: Streamer status: 1
[15:47:14][D][esp_audio_sources:139]: decoder status: 1
[15:47:14][D][esp_audio_sources:140]: stream uri: http://10.11.0.20:8097/ugp/ugp_hfv6ni9w.flac?player_id=media_player.ha_bedroom_satellite_ivan_ha_satellite_ivan_605_media_player
[15:47:14][D][adf_audio_element:108]: Preparing [http]...
[15:47:14][D][esp-idf:000]: I (51881) AUDIO_THREAD: The http task allocate stack on external memory

[15:47:14][D][esp-idf:000]: I (51883) AUDIO_ELEMENT: [http-0x3d8188d4] Element task created

[15:47:14][D][adf_audio_element:108]: Preparing [decoder]...
[15:47:14][D][esp-idf:000]: I (51888) AUDIO_THREAD: The decoder task allocate stack on external memory

[15:47:14][D][esp-idf:000]: I (51892) AUDIO_ELEMENT: [decoder-0x3d818bcc] Element task created

[15:47:14][D][adf_audio_element:108]: Preparing [i2s_out]...
[15:47:14][D][esp-idf:000]: I (51909) AUDIO_ELEMENT: [i2s_out-0x3d818d9c] Element task created

[15:47:14][D][adf_audio_element:165]: Resuming [http]...
[15:47:14][D][adf_audio_element:172]: [http] Sending resume command.
[15:47:14][D][adf_audio_element:165]: Resuming [decoder]...
[15:47:14][D][adf_audio_element:172]: [decoder] Sending resume command.
[15:47:14][D][esp-idf:000][decoder]: I (51956) AUDIO_ELEMENT: [decoder] AEL_MSG_CMD_RESUME,state:1

[15:47:14][D][esp-idf:000][decoder]: I (51962) ESP_DECODER: Ready to do audio type check, pos:0, (line 104)

[15:47:14][I][esp_audio_sources:033][http]: Receive http event: 2
[15:47:14][I][esp_audio_sources:033][http]: Receive http event: 4
[15:47:14][D][esp-idf:000][http]: I (51988) HTTP_STREAM: total_bytes=0

[15:47:14][D][adf_audio_element:191]: [http] Checking State, got 74
[15:47:14][D][adf_audio_element:191]: [decoder] Checking State, got 72
[15:47:14][I][HTTPStreamReader:230]: Codec Format reported: 0.
[15:47:14][D][esp-idf:000][decoder]: I (52535) ESP_DECODER: Detect audio type is FLAC

[15:47:14][D][esp-idf:000][decoder]: I (52540) CODEC_ELEMENT_HELPER: The element is 0x3d818bcc. The reserve data 2 is 0x0.

[15:47:14][D][esp-idf:000][decoder]: I (52545) FLAC_DECODER: a new song playing

[15:47:14][I][HTTPStreamReader:240]: [ * ] Receive music info from decoder, sample_rates=44100, bits=16, ch=2
[15:47:14][I][HTTPStreamReader:243]: [ * ] Receive music info from decoder, codec_fmt=8, bps=0, duration=0, bytes=0
[15:47:14][D][adf_i2s_out:141]: Set final i2s settings: 44100
[15:47:14][D][adf_audio_element:108]: Preparing [http]...
[15:47:14][D][adf_audio_element:108]: Preparing [decoder]...
[15:47:14][D][esp-idf:000][decoder]: I (52613) FLAC_DECODER: Closed

[15:47:14][D][esp_audio_sources:193]: Preparation done!
[15:47:14][D][esp_adf_pipeline:342]: wait for preparation, done
[15:47:14][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from PREPARING to STARTING. (REQ: 0)
[15:47:14][I][adf_media_player:192]: got new pipeline state: 5, while in MP state PLAYING
[15:47:14][I][adf_media_player:255]: current mp state: PLAYING
[15:47:14][I][adf_media_player:256]: anouncement: false
[15:47:14][I][adf_media_player:257]: play_intent: false
[15:47:14][I][adf_media_player:258]: current_uri_: yes
[15:47:14][E][esp_adf_pipeline:246]: Timeout while RESUMING. Stopping pipeline!
[15:47:14][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from STARTING to ABORTING. (REQ: 1)
[15:47:14][I][adf_media_player:192]: got new pipeline state: 10, while in MP state PLAYING
[15:47:14][I][adf_media_player:255]: current mp state: PLAYING
[15:47:14][I][adf_media_player:256]: anouncement: false
[15:47:14][I][adf_media_player:257]: play_intent: false
[15:47:14][I][adf_media_player:258]: current_uri_: yes
[15:47:14][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from ABORTING to STOPPED. (REQ: 1)
[15:47:14][I][adf_media_player:192]: got new pipeline state: 4, while in MP state PLAYING
[15:47:14][I][adf_media_player:255]: current mp state: IDLE
[15:47:14][I][adf_media_player:256]: anouncement: false
[15:47:14][I][adf_media_player:257]: play_intent: false
[15:47:14][I][adf_media_player:258]: current_uri_: yes
[15:47:15][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from STOPPED to DESTROYING. (REQ: 1)
[15:47:15][I][adf_media_player:192]: got new pipeline state: 11, while in MP state IDLE
[15:47:15][I][adf_media_player:255]: current mp state: IDLE
[15:47:15][I][adf_media_player:256]: anouncement: false
[15:47:15][I][adf_media_player:257]: play_intent: false
[15:47:15][I][adf_media_player:258]: current_uri_: yes
[15:47:15][D][esp_adf_pipeline:518]: Called deinit_all
[15:47:15][D][esp-idf:000]: I (52789) AUDIO_PIPELINE: audio_pipeline_unlinked

[15:47:15][D][esp-idf:000]: W (52792) AUDIO_ELEMENT: [http] Element has not create when AUDIO_ELEMENT_TERMINATE

[15:47:15][D][esp-idf:000]: W (52794) AUDIO_ELEMENT: [decoder] Element has not create when AUDIO_ELEMENT_TERMINATE

[15:47:15][D][esp-idf:000]: I (52797) CODEC_ELEMENT_HELPER: The element is 0x3d818bcc. The reserve data 2 is 0x0.

[15:47:15][D][esp-idf:000]: W (52800) AUDIO_ELEMENT: [i2s_out] Element has not create when AUDIO_ELEMENT_TERMINATE

[15:47:15][D][esp-idf:000]: I (52803) I2S: DMA queue destroyed

[15:47:15][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from DESTROYING to UNINITIALIZED. (REQ: 1)

And here is when i try to play another track:

[15:49:42][D][media_player:061]: 'HA Satellite Ivan (605) Media Player' - Setting
[15:49:42][D][media_player:068]:   Media URL: http://10.11.0.20:8097/ugp/ugp_hfv6ni9w.flac?player_id=media_player.ha_bedroom_satellite_ivan_ha_satellite_ivan_605_media_player
[15:49:42][D][esp_audio_sources:098]: Set new uri: http://10.11.0.20:8097/ugp/ugp_hfv6ni9w.flac?player_id=media_player.ha_bedroom_satellite_ivan_ha_satellite_ivan_605_media_player
[15:49:42][D][adf_media_player:057]: Got control call in state IDLE
[15:49:42][D][adf_media_player:058]: req_track stream uri: http://10.11.0.20:8097/ugp/ugp_hfv6ni9w.flac?player_id=media_player.ha_bedroom_satellite_ivan_ha_satellite_ivan_605_media_player
[15:49:42][D][esp_adf_pipeline:060]: Starting request, current state UNINITIALIZED
[15:49:42][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from UNINITIALIZED to INITIALIZING. (REQ: 0)
[15:49:42][I][adf_media_player:192]: got new pipeline state: 1, while in MP state IDLE
[15:49:42][I][adf_media_player:255]: current mp state: IDLE
[15:49:42][I][adf_media_player:256]: anouncement: false
[15:49:42][I][adf_media_player:257]: play_intent: false
[15:49:42][I][adf_media_player:258]: current_uri_: yes
[15:49:42][D][esp-idf:000]: I (200449) ESP_DECODER: esp_decoder_init, stack size is 30720

[15:49:42][D][i2s_audio:067]: Install driver requested by Writer
[15:49:42][D][esp-idf:000]: I (200456) I2S: DMA Malloc info, datalen=blocksize=1024, dma_buf_count=4

[15:49:42][D][i2s_audio:073]: Installing driver : yes
[15:49:42][D][esp_adf_pipeline:497]: pipeline tag 0, http
[15:49:42][D][esp_adf_pipeline:497]: pipeline tag 1, decoder
[15:49:42][D][esp_adf_pipeline:497]: pipeline tag 2, i2s_out
[15:49:42][D][esp-idf:000]: I (200475) AUDIO_PIPELINE: link el->rb, el:0x3d8188d4, tag:http, rb:0x3d818f14

[15:49:42][D][esp-idf:000]: I (200483) AUDIO_PIPELINE: link el->rb, el:0x3d818bcc, tag:decoder, rb:0x3d858f54

[15:49:42][D][esp_adf_pipeline:507]: Setting up event listener.
[15:49:42][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from INITIALIZING to CREATED. (REQ: 0)
[15:49:42][I][adf_media_player:192]: got new pipeline state: 2, while in MP state IDLE
[15:49:42][I][adf_media_player:255]: current mp state: IDLE
[15:49:42][I][adf_media_player:256]: anouncement: false
[15:49:42][I][adf_media_player:257]: play_intent: false
[15:49:42][I][adf_media_player:258]: current_uri_: yes
[15:49:42][W][component:237]: Component adf_pipeline.media_player took a long time for an operation (53 ms).
[15:49:42][W][component:238]: Components should block for at most 30 ms.
[15:49:42][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from CREATED to PREPARING. (REQ: 0)
[15:49:42][I][adf_media_player:192]: got new pipeline state: 3, while in MP state IDLE
[15:49:42][D][adf_i2s_out:141]: Set final i2s settings: 44100
[15:49:42][I][adf_media_player:255]: current mp state: PLAYING
[15:49:42][I][adf_media_player:256]: anouncement: false
[15:49:42][I][adf_media_player:257]: play_intent: false
[15:49:42][I][adf_media_player:258]: current_uri_: yes
[15:49:42][D][esp_audio_sources:103]: Prepare elements called (initial_call)!
[15:49:42][D][esp_audio_sources:137]: Use fixed settings: no
[15:49:42][D][esp_audio_sources:138]: Streamer status: 1
[15:49:42][D][esp_audio_sources:139]: decoder status: 1
[15:49:42][D][esp_audio_sources:140]: stream uri: http://10.11.0.20:8097/ugp/ugp_hfv6ni9w.flac?player_id=media_player.ha_bedroom_satellite_ivan_ha_satellite_ivan_605_media_player
[15:49:42][D][adf_audio_element:108]: Preparing [http]...
[15:49:42][D][esp-idf:000]: I (200564) AUDIO_THREAD: The http task allocate stack on external memory

[15:49:42][D][esp-idf:000]: I (200568) AUDIO_ELEMENT: [http-0x3d8188d4] Element task created

[15:49:42][D][adf_audio_element:108]: Preparing [decoder]...
[15:49:42][D][esp-idf:000]: I (200573) AUDIO_THREAD: The decoder task allocate stack on external memory

[15:49:42][D][esp-idf:000]: I (200576) AUDIO_ELEMENT: [decoder-0x3d818bcc] Element task created

[15:49:42][D][adf_audio_element:108]: Preparing [i2s_out]...
[15:49:42][D][esp-idf:000]: I (200593) AUDIO_ELEMENT: [i2s_out-0x3d818d9c] Element task created

[15:49:42][D][adf_audio_element:165]: Resuming [http]...
[15:49:42][D][adf_audio_element:172]: [http] Sending resume command.
[15:49:42][D][adf_audio_element:165]: Resuming [decoder]...
[15:49:42][D][adf_audio_element:172]: [decoder] Sending resume command.
[15:49:42][D][esp-idf:000][decoder]: I (200642) AUDIO_ELEMENT: [decoder] AEL_MSG_CMD_RESUME,state:1

[15:49:42][D][esp-idf:000][decoder]: I (200648) ESP_DECODER: Ready to do audio type check, pos:0, (line 104)

[15:49:42][I][esp_audio_sources:033][http]: Receive http event: 2
[15:49:42][I][esp_audio_sources:033][http]: Receive http event: 4
[15:49:42][D][esp-idf:000][http]: I (200670) HTTP_STREAM: total_bytes=0

[15:49:42][D][adf_audio_element:191]: [http] Checking State, got 74
[15:49:42][D][adf_audio_element:191]: [decoder] Checking State, got 72
[15:49:42][I][HTTPStreamReader:230]: Codec Format reported: 0.
[15:49:43][D][esp-idf:000][decoder]: I (201264) ESP_DECODER: Detect audio type is FLAC

[15:49:43][D][esp-idf:000][decoder]: I (201269) CODEC_ELEMENT_HELPER: The element is 0x3d818bcc. The reserve data 2 is 0x0.

[15:49:43][D][esp-idf:000][decoder]: I (201272) FLAC_DECODER: a new song playing

[15:49:43][I][HTTPStreamReader:240]: [ * ] Receive music info from decoder, sample_rates=44100, bits=16, ch=2
[15:49:43][I][HTTPStreamReader:243]: [ * ] Receive music info from decoder, codec_fmt=8, bps=0, duration=0, bytes=0
[15:49:43][D][adf_i2s_out:141]: Set final i2s settings: 44100
[15:49:43][D][adf_audio_element:108]: Preparing [http]...
[15:49:43][D][adf_audio_element:108]: Preparing [decoder]...
[15:49:43][D][esp-idf:000][decoder]: W (201334) AUDIO_ELEMENT: IN-[decoder] AEL_IO_ABORT

[15:49:43][D][esp-idf:000][decoder]: I (201339) FLAC_DECODER: Closed

[15:49:43][D][esp_audio_sources:193]: Preparation done!
[15:49:43][D][esp_adf_pipeline:342]: wait for preparation, done
[15:49:43][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from PREPARING to STARTING. (REQ: 0)
[15:49:43][I][adf_media_player:192]: got new pipeline state: 5, while in MP state PLAYING
[15:49:43][I][adf_media_player:255]: current mp state: PLAYING
[15:49:43][I][adf_media_player:256]: anouncement: false
[15:49:43][I][adf_media_player:257]: play_intent: false
[15:49:43][I][adf_media_player:258]: current_uri_: yes
[15:49:43][D][adf_audio_element:165]: Resuming [http]...
[15:49:43][D][adf_audio_element:172]: [http] Sending resume command.
[15:49:43][D][adf_audio_element:165]: Resuming [decoder]...
[15:49:43][D][adf_audio_element:172]: [decoder] Sending resume command.
[15:49:43][D][esp-idf:000][decoder]: I (201452) AUDIO_ELEMENT: [decoder] AEL_MSG_CMD_RESUME,state:1

[15:49:43][D][esp-idf:000][decoder]: I (201457) ESP_DECODER: Ready to do audio type check, pos:0, (line 104)

[15:49:43][D][adf_audio_element:165]: Resuming [i2s_out]...
[15:49:43][D][adf_audio_element:172]: [i2s_out] Sending resume command.
[15:49:43][D][esp-idf:000][i2s_out]: I (201477) AUDIO_ELEMENT: [i2s_out] AEL_MSG_CMD_RESUME,state:1

[15:49:43][D][adf_audio_element:191]: [http] Checking State, got 79
[15:49:43][D][adf_audio_element:191]: [decoder] Checking State, got 75
[15:49:43][D][esp-idf:000][http]: I (201509) HTTP_CLIENT: Body received in fetch header state, 0x3fccd9db, 47

[15:49:43][D][esp-idf:000][http]: I (201515) HTTP_STREAM: total_bytes=47

[15:49:43][D][esp-idf:000][http]: E (201519) HTTP_STREAM: Invalid HTTP stream, status code = 404

[15:49:43][D][esp-idf:000][http]: E (201524) AUDIO_ELEMENT: [http] AEL_STATUS_ERROR_OPEN,-1

[15:49:43][D][esp-idf:000][http]: W (201529) AUDIO_ELEMENT: [http] audio_element_on_cmd_error,7

[15:49:43][D][esp-idf:000][decoder]: W (201536) AUDIO_ELEMENT: IN-[decoder] AEL_IO_ABORT

[15:49:43][D][esp-idf:000][decoder]: E (201541) AUDIO_FORMAT: failed to get head buf data(line 175)

[15:49:43][D][esp-idf:000][decoder]: E (201545) ESP_DECODER: Audio type detect error (line 147)

[15:49:43][D][esp-idf:000][decoder]: W (201551) AUDIO_ELEMENT: [decoder] AEL_IO_ABORT, -3

[15:49:43][D][esp-idf:000][i2s_out]: W (201557) AUDIO_ELEMENT: IN-[i2s_out] AEL_IO_ABORT

[15:49:43][D][adf_audio_element:324]: [http] Checking State for stopping, got 7
[15:49:43][D][esp-idf:000]: E (201569) AUDIO_ELEMENT: [http] Element already stopped

[15:49:43][E][esp_adf_pipeline:223]: HTTPStreamReader got in error state while STOPPING. Stopping pipeline!
[15:49:43][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from ABORTING to DESTROYING. (REQ: 4)
[15:49:43][I][adf_media_player:192]: got new pipeline state: 11, while in MP state PLAYING
[15:49:43][I][adf_media_player:255]: current mp state: PLAYING
[15:49:43][I][adf_media_player:256]: anouncement: false
[15:49:43][I][adf_media_player:257]: play_intent: false
[15:49:43][I][adf_media_player:258]: current_uri_: yes
[15:49:43][E][esp_adf_pipeline:246]: Timeout while STOPPING. Stopping pipeline!
[15:49:43][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from DESTROYING to DESTROYING. (REQ: 4)
[15:49:43][I][adf_media_player:192]: got new pipeline state: 11, while in MP state PLAYING
[15:49:43][I][adf_media_player:255]: current mp state: PLAYING
[15:49:43][I][adf_media_player:256]: anouncement: false
[15:49:43][I][adf_media_player:257]: play_intent: false
[15:49:43][I][adf_media_player:258]: current_uri_: yes
[15:49:43][D][esp_adf_pipeline:518]: Called deinit_all
[15:49:43][D][esp-idf:000]: I (201623) AUDIO_PIPELINE: audio_pipeline_unlinked

[15:49:43][D][esp-idf:000]: W (201626) AUDIO_ELEMENT: [http] Element has not create when AUDIO_ELEMENT_TERMINATE

[15:49:43][D][esp-idf:000]: W (201628) AUDIO_ELEMENT: [decoder] Element has not create when AUDIO_ELEMENT_TERMINATE

[15:49:43][D][esp-idf:000]: I (201631) CODEC_ELEMENT_HELPER: The element is 0x3d818bcc. The reserve data 2 is 0x0.

[15:49:43][D][esp-idf:000]: W (201633) AUDIO_ELEMENT: [i2s_out] Element has not create when AUDIO_ELEMENT_TERMINATE

[15:49:43][D][esp-idf:000]: I (201636) I2S: DMA queue destroyed

[15:49:43][D][esp_adf_pipeline:448]: [MediaPlayer] Pipeline changed from DESTROYING to UNINITIALIZED. (REQ: 4)
[15:49:43][I][adf_media_player:192]: got new pipeline state: 0, while in MP state PLAYING
[15:49:43][I][adf_media_player:255]: current mp state: IDLE
[15:49:43][I][adf_media_player:256]: anouncement: false
[15:49:43][I][adf_media_player:257]: play_intent: false
[15:49:43][I][adf_media_player:258]: current_uri_: yes

Basically, the URL for the playback always starts with - http://10.11.0.20:8097/ugp/ugp_hfv6ni9w.flac

Where ugp_hfv6ni9w is the internal Universal Group Player ID used by the MA. Upon clicking play in the MA, it seems to tell the ESP32 the URL to get the data from, and it tries to play the data, but for some reason fails to do so.

This URL is the same for both speakers (i have two devices in one group), just the player_id is different on each device.

And no, i am unable to play the audio in the browser as it seems to expect something else rather than just URL from me. With the arduino and with no esphome_audio it works just fine with the same URL on the device, but yet again, from the browser i am not able to play the stream.

gnumpi commented 4 months ago

And no, i am unable to play the audio in the browser as it seems to expect something else rather than just URL from me. With the arduino and with no esphome_audio it works just fine with the same URL on the device, but yet again, from the browser i am not able to play the stream.

I was not aware that the arduino media player does play flac streams.

Is it possible that the url is only valid for playing once? Because the esphome_audio media player streams the url silently for a bit to detect the necessary audio settings and then finally plays the url again in a second step after all settings are made.

darki73 commented 4 months ago

I seriously doubt that the stream is in flac, the original file is an m4a (youtube music as a source) or ogg (spotify), my guess the headers which device receives during the connection phase actually specify which format it is supposed to use.

Reasons why i don't actually believe that stream is in flac:

  1. There is no ffmpeg installed on my system
  2. The CPU usage during the playback is not rising (it is a 6800H system which runs Proxmox and Home Assistant as a VM).

On another note, when trying to play the audio to a group which is using esp-idf, logs of the MA show the following (i know that this might be not related, and an error from the completely different project, but still):

2024-07-03 16:24:43.006 INFO (MainThread) [music_assistant.streams] Start Queue Flow stream for Queue Bedroom - crossfade: False
2024-07-03 16:24:43.536 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1013, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ConnectionResetError: [Errno 104] Connection reset by peer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/helpers/webserver.py", line 136, in _handle_catch_all
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/providers/ugp/__init__.py", line 392, in _serve_ugp_stream
    await resp.write(chunk)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_response.py", line 517, in write
    await self._payload_writer.write(data)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/http_writer.py", line 119, in write
    await self.drain()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/http_writer.py", line 171, in drain
    await self._protocol._drain_helper()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/base_protocol.py", line 95, in _drain_helper
    await asyncio.shield(waiter)
ConnectionError: Connection lost
2024-07-03 16:24:43.540 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1013, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ConnectionResetError: [Errno 104] Connection reset by peer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/helpers/webserver.py", line 136, in _handle_catch_all
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/music_assistant/server/providers/ugp/__init__.py", line 392, in _serve_ugp_stream
    await resp.write(chunk)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_response.py", line 517, in write
    await self._payload_writer.write(data)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/http_writer.py", line 119, in write
    await self.drain()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/http_writer.py", line 171, in drain
    await self._protocol._drain_helper()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/base_protocol.py", line 95, in _drain_helper
    await asyncio.shield(waiter)
ConnectionError: Connection lost

As for the

Is it possible that the url is only valid for playing once?

It is not, MA creates a static group id upon the creation of the group, so it is always the same, from my observations, it just starts to stream audio on this URL whenever the play button is clicked, and also notifies the end devices to connect to URL to start playback.

gnumpi commented 4 months ago

Ok, thanks for all the useful information. I will need to try to reproduce the error on my setup. It will probably take a few days though.

darki73 commented 4 months ago

Sure, no problem, as i said, i am aware that this is a dev-next branch which should not be used without expecting some issues )

formatBCE commented 4 months ago

@darki73 side question: do you connect the player to MA over HA?

P.S. I'm asking because for me these media players never worked in Music Assistant. Probably, there's direct way to add them, instead of connecting from Home Assistant?

darki73 commented 4 months ago

@formatBCE hey, yes, players flashed from esphome ui in homeassistant, then added to homeassistant under esphome integration, then enabled in the Home Asisstant players in MA.

Standalone players work just fine with esp-idf firmware, but not when grouped, with arduino I am able to play same media on all 4 (still assembling rest) speakers with no issue while all of them in a group.

formatBCE commented 4 months ago

@darki73 that's interesting. I tried it once more, same result - doesn't play.. I tried with YouTube, Spotify and Jellyfin music providers - everything gets translated into MA flac HTTP url, and then I see 0 bytes stream in esp logs..

formatBCE commented 4 months ago

@gnumpi it's even more interesting, that i actually can play music directly from Home Assistant (one by one, apparently, but it shouldn't matter), but not from Music Assistant... The URL from HA is mp3, while from MA it's always flac, regardless of the source library. Could this be the issue? Should i create the ticket?

darki73 commented 4 months ago

Here are some more findings:

  1. https://github.com/music-assistant/server/blob/main/music_assistant/server/providers/ugp/__init__.py#L215
  2. https://github.com/music-assistant/server/blob/main/music_assistant/server/providers/ugp/__init__.py#L337
  3. https://github.com/music-assistant/server/blob/main/music_assistant/server/providers/ugp/__init__.py#L298

They do indeed just straight up slap the .flac to the URL, which, by my guess, might not be handled properly in esp-adf, and by proper i mean framework sees the extension, and just goes with it.

Thing is, i have tried the YouTube streams with m4a and Spotify streams with ogg when playing solo, and MA is indeed passes the extension of the stream to ESP32, however, when using a group player (UGP -> Universal Group Player), according to the 3 links i provided earlier, it just adds .flac and goes with it.

P.S. After actually paying attention to what is written on the line 298:

# register dynamic routes for the ugp stream (both flac and mp3)
        for fmt in ("mp3", "flac"):
            route_path = f"/ugp/{group_player_id}.{fmt}"
            self.mass.streams.register_dynamic_route(route_path, self._serve_ugp_stream)
            self._registered_routes.add(route_path)

        return player

It registers URLs for both mp3 and flac, but if i did not missed anything else, it will always send flac to the client, even though there is an option for mp3 stream to be sent.

P.P.S. The official MA integration also has the following issue https://github.com/music-assistant/hass-music-assistant/issues/2508.

The issue that person describes happened to me as well, the fix was the codec: auto in the firmware (as without the dev branch and codec option esphome_audio seems to default to an mp3 stream). Thing is, i still seriously doubt that it actually sends flac to the client device as i have already said i dont have ffmpeg installed, so there is no way to convert the stream from m4a/ogg to flac. And even if it is bundled with the container, i notice no CPU usage increase while playing media (4 core VM with 8 gigs of RAM).

gnumpi commented 4 months ago

In my understanding there are two different issues here, the first one is that MA ignores the enforce mp3 setting since its last update, as it was already reported here: https://github.com/music-assistant/hass-music-assistant/issues/2508. Because of this, the audio is always send as flac and the 'codec: auto' is needed to be able to play flac with the adf_mediaplayer. The second issue is probably, that the audio stream can't be set up correctly on MA side after it got aborted by the client. In order to test if this is the case, I could add a music_assistant_audio settings (like the announcement_audio) to the media player which defines in which format audio is send from MA and when the MP detects a stream coming from MA it uses this settings instead of auto detecting the format. This would prevent the need of aborting the stream and restarting it after the audio settings got detected. This is actually already on my todo list, but didn't get to it yet...

@darki73 how do you run MA? Is it possible that MA has installed its own ffmpeg? Because I assume that MA depends on ffmepg and it always recodes the stream into either flac or mp3.

darki73 commented 4 months ago

@gnumpi MA is installed as an addon from the Home Assistant (i run Home Assistant OS).

The reason i doubt that it makes the UGP decode FLAC as i am not noticing any CPU usage increase during the playback (assuming it resamples the m4a/ogg to flac), and the machine is using mobile Ryzen 6800H CPU, while only 4 cores dedicated to a VM, so there should be at least a small spike during the playback initialization, but there is none. Also, they are making 2 URLs for the UGP stream, one mp3 and one flac, but that means that they have to do double the amount of work to actually provide two different streams with two different formats.

Funny thing is, if you click "enough" on the play/pause button, the sound will actually come live and i can either hear it from first / seconds / both of the speakers, BUT, from the logs, it is still the flac URL.

One more thing:

  1. Downloaded the 14, Hot.flac from - https://archive.org/details/legendaddy
  2. Uploaded through SMB share to the HA media folder
  3. Tried to play it via the HA "local media" on the selected device
  4. Sound is really choppy - device is unable to handle decoding (ESP32-S3-WROOM-1-N16R8)

So, from this observation, there is no way MA is doing the FLAC stream.

P.S. firmware is compiled with the following settings:

esphome:
  name: ${device_name}
  friendly_name: ${device_friendly_name}
  comment: ${device_comment}
  area: ${device_area}
  name_add_mac_suffix: false
  includes:
    - /config/smart_speaker/scripts/light_diymall_7x_ws2812.h
  platformio_options:
    board_build.arduino.memory_type: qio_opi
    board_build.flash_mode: dio
    board_upload.maximum_ram_size: 524288

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  flash_size: 16MB
  partitions: /config/smart_speaker/boards/N16R8.csv
  framework:
    type: esp-idf
    version: recommended
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
      CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
      CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
      CONFIG_ESP32_S3_BOX_BOARD: "y"
      COMPILER_OPTIMIZATION_SIZE: "y"

      CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM: "16"
      CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM: "512"
      CONFIG_TCPIP_RECVMBOX_SIZE: "512"
      CONFIG_TCP_SND_BUF_DEFAULT: "65535"
      CONFIG_TCP_WND_DEFAULT: "512000"
      CONFIG_TCP_RECVMBOX_SIZE: "512"

psram:
  mode: octal
  speed: 80MHz
formatBCE commented 4 months ago

@darki73 lossless FLAC is a bit different from MP3/AAC/OGG, converted to FLAC, where all lossy bytes will be replaced with 0. Also it might be that MA is "presenting" FLAC stream, and actually is showing MP3 data inside - but headers to stream are FLAC, so MP3 codec can't read the stream. This might be a stretch, but it aligns with what we see on practice.

P.S. Which ESP32-S3-WROOM-1-N16R8 board did you use? I got 2 different N16R8 boards from different manufacturers, and they both give strange noise on right channel with different external DACs... Also tried to adopt SEEED XIAO S3, but it fails to boot with seemingly good firmware...

darki73 commented 4 months ago

@formatBCE I have a board of my custom design with all the necessary components for playback and voltage management being placed as close to the ESP as possible. With the off the shelf boards I had many issues with sound quality both in recording and outputting.

gnumpi commented 4 months ago

@darki73 just for clarification, the HA addon is based on the MA server docker image, hence ffmpeg is installed and runs inside the MA docker container on your system:

https://github.com/music-assistant/server/blob/496b99d0b3681f3b65744b0f9ca7ba718015efa4/Dockerfile#L64

formatBCE commented 4 months ago

BTW, i also found that with codec: auto, while actually playing the song, media player somehow reports back that it skipped the song to MA, and in MA interface it starts showing next song in queue, although player actually is playing the same first song. If i pause/unpause or seek with seek bar from MA, it shows old song for couple seconds, then behaviour repeats. But If i give announcement during this, then after announcement player starts playing NEW song, not the song it stopped on. @gnumpi i guess it might be cache issue? Anyways, thank you for your work, it's the best implementation to the MP on ESPHome i've seen so far. If you need my help in testing, i'm happy to help. I wish i could dig into this deeper, but it's above my C++ skills. :)

gnumpi commented 4 months ago

Yeah unfortunately the MA support for native HA media players is not very good in the moment. They prefer providers that speak directly from MA to the devices instead of taking the route through HA. Unfortunately I don't have the time at the moment to also implement a direct route to MA.

formatBCE commented 4 months ago

Yeah unfortunately the MA support for native HA media players is not very good in the moment. They prefer providers that speak directly from MA to the devices instead of taking the route through HA. Unfortunately I don't have the time at the moment to also implement a direct route to MA.

You mean the provider for ESPHome? That would be a longshot! :)

darki73 commented 4 months ago

Small update, with https://github.com/gnumpi/esphome_audio/commit/d628b9734b54794e57739b53ec18117f772ee79e even the real FLAC can be played with no issues. ESP32-S3 is such a powerhouse!

P.S. Forgot to mention, for some reason, with Spotify (ogg files) provider there is no issue with playing on group of players, but with YouTube Music (m4a files) experience is hit or miss.