gnumpi / esphome_audio

Custom audio components for ESPHome
Other
20 stars 8 forks source link

Make configuration more intuitive #20

Open gnumpi opened 2 months ago

gnumpi commented 2 months ago

The current configuration schema for ADF pipeline components is not intuitive and primarily focuses on the developer's perspective rather than the user's perspective.

I am planing the following changes:

old config:

adf_pipeline:
  - platform: i2s_audio
    type: sink
    id: adf_i2s_out
    i2s_audio_id: i2s_out
    i2s_dout_pin: GPIO10

  - platform: i2s_audio
    type: source
    id: adf_i2s_in
    i2s_audio_id: i2s_in
    i2s_din_pin: GPIO4
    channel: left
    sample_rate: 16000
    bits_per_sample: 16bit

  - platform: audio_processing
    type: resample-filter
    id: downsample

microphone:
  - platform: adf_pipeline
    id: adf_microphone
    pipeline:
      - adf_i2s_in
      - self

speaker:
  - platform: adf_pipeline
    id: adf_speaker
    pipeline:
      - self
      - adf_i2s_out

media_player:
  - platform: adf_pipeline
    id: adf_media_player
    name: s3-dev_media_player
    internal: false
    pipeline:
      - self
      - downsample
      - adf_i2s_out

new config:

adf_pipeline_element:
  - platform: i2s_audio
    id: adf_i2s_out
    i2s_audio_id: i2s_out
    i2s_dout_pin: GPIO10

  - platform: i2s_audio
    id: adf_i2s_in
    i2s_audio_id: i2s_in
    i2s_din_pin: GPIO4
    channel: left
    sample_rate: 16000
    bits_per_sample: 16bit

  - platform: audio_processing
    type: resample-filter
    id: downsample

microphone:
  - platform: adf_pipeline_element
    id: adf_microphone
    source: adf_i2s_in

speaker:
  - platform: adf_pipeline_element
    id: adf_speaker
    sink: adf_i2s_out    

media_player:
  - platform: adf_pipeline_element
    id: adf_media_player
    name: s3-dev_media_player
    internal: false
    sink: adf_i2s_out
    processing_pipeline:
      - downsample

Any comments or suggestions on this?

nielsnl68 commented 2 months ago

From what i get from the above this is the route's

audio route

Why not show it in a chain structure like:


audio:
  - platform: i2s_audio
    id: adf_i2s_out
    i2s_audio_id: i2s_out
    i2s_dout_pin: GPIO10

  - platform: i2s_audio
    id: adf_i2s_in
    i2s_audio_id: i2s_in
    i2s_din_pin: GPIO4
    channel: left
    sample_rate: 16000
    bits_per_sample: 16bit

  - platform: audio_processing
    type: resample-filter
    id: downsample

microphone:
  - platform: adf_audio
    id: adf_microphone
    source:
        element: downsample
        source:
            element: adf_i2s_in

speaker:
  - platform: adf_audio
     id: adf_speaker
     destiny: 
         element: downsample
         destiny:  
             element: adf_i2s_out

media_player:
  - platform: adf_pipeline_element
    id: adf_media_player
    name: s3-dev_media_player
    internal: false
    speaker: adf_speaker

voice_assistant:
  id: va
  mic: adf_microphone
  speaker: adf_speaker
  ...

As you can see i changed sink in destiny, i think that fits more together with source. An other option is to change source into faucet but i do not thing de common person get what is mend with those.

nielsnl68 commented 2 months ago

Maybe it can simpler (basically what you already have. without the self):

microphone:
  - platform: adf_audio
    id: adf_microphone
    source:
        - downsample
        - adf_i2s_in

speaker:
  - platform: adf_audio
    id: adf_speaker
    destiny: 
        - downsample
        - adf_i2s_out
gnumpi commented 2 months ago

From what i get from the above this is the route's

audio route

That's not completely correct. The media player does not use the speaker component it outputs directly to the pipeline and the VA can be configured to use either, the MP or the speaker as an output.

gnumpi commented 2 months ago

Maybe it can simpler (basically what you already have. without the self):

microphone:
  - platform: adf_audio
    id: adf_microphone
    source:
        - downsample
        - adf_i2s_in

speaker:
  - platform: adf_audio
    id: adf_speaker
    destiny: 
        - downsample
        - adf_i2s_out

I like this suggestions!!!

nielsnl68 commented 2 months ago

I like this suggestions!!!

The only pro of the other solution would be that we could add extra component specific options as well

nielsnl68 commented 2 months ago

hat's not completely correct. The media player does not use the speaker component it outputs directly to the pipeline and the VA can be configured to use either, the MP or the speaker as an output.

It would be a better idea to remove the I2S stuff from the MP and use the Speaker component for the I2S

gnumpi commented 2 months ago

hat's not completely correct. The media player does not use the speaker component it outputs directly to the pipeline and the VA can be configured to use either, the MP or the speaker as an output.

It would be a better idea to remove the I2S stuff from the MP and use the Speaker component for the I2S

The I2S stuff is not part of the MP. The MP, Speaker and Microphone as well as I2SIn and I2SOut are all individual elements that can 'talk' to each other via the adf_pipeline. The speaker component can be used to provide a pipeline interface for esphome components which don't have an adf_pipeline implementation. It is more efficient to connect the MP directly to I2S or any other output like the pipeline implementation of matrixio voice.