esphome / home-assistant-voice-pe

Home Assistant Voice PE
Other
42 stars 7 forks source link

[voice_kit] Add VNR and pipeline stage I2C commands #120

Closed kahrendt closed 1 week ago

kahrendt commented 2 weeks ago

Requires https://github.com/esphome/voice-kit-xmos-firmware/pull/5 for the pipeline stage commands.

Adds functions to the voice_kit component for reading and writing certain settings on the XMOS. read_vnr() gets the XMOS's voice to noise ratio (basically a VAD). write_pipeline_stage allows you to configure the pipeline stage a microphone channel uses. read_pipeline_stage() is added just to confirm that the pipeline stages have been made on the XMOS.

There are 5 options for the stages: PIPELINE_STAGE_NONE - no processing applied, raw microphone data PIPELINE_STAGE_AEC - Acoustic Echo Cancellation PIPELINE_STAGE_IC - AEC + Interference Cancellation PIPELINE_STAGE_NS - AEC + IC + Noise Suppression PIPELINE_STAGE_AGC - AEC +IC + NS + Automatic Gain Control

Here is some useful yaml for testing these out after adding id: voice_kit_component under the voice_kit component:

sensor:
  - platform: template
    name: "Voice to noise ratio"
    lambda: return id(voice_kit_component).read_vnr();
    update_interval: 0.25s
    state_class: "measurement"
    accuracy_decimals: 3

select:
  - platform: template
    name: "Channel 0 stage"
    options:
      - "None"
      - "AEC"
      - "IC"
      - "NS"
      - "AGC"
    optimistic: true
    on_value:
      then:
        - lambda: |-
            if (x == "None") {
              id(voice_kit_component).write_pipeline_stage(voice_kit::MICROPHONE_CHANNEL_0, voice_kit::PIPELINE_STAGE_NONE);
            } else if (x == "AEC") {
              id(voice_kit_component).write_pipeline_stage(voice_kit::MICROPHONE_CHANNEL_0, voice_kit::PIPELINE_STAGE_AEC);
            } else if (x == "IC") {
              id(voice_kit_component).write_pipeline_stage(voice_kit::MICROPHONE_CHANNEL_0, voice_kit::PIPELINE_STAGE_IC);
            } else if (x == "NS") {
              id(voice_kit_component).write_pipeline_stage(voice_kit::MICROPHONE_CHANNEL_0, voice_kit::PIPELINE_STAGE_NS);
            } else if (x == "AGC") {
              id(voice_kit_component).write_pipeline_stage(voice_kit::MICROPHONE_CHANNEL_0, voice_kit::PIPELINE_STAGE_AGC);
            }
  - platform: template
    name: "Channel 1 stage"
    options:
      - "None"
      - "AEC"
      - "IC"
      - "NS"
      - "AGC"
    optimistic: true
    on_value:
      then:
        - lambda: |-
            if (x == "None") {
              id(voice_kit_component).write_pipeline_stage(voice_kit::MICROPHONE_CHANNEL_1, voice_kit::PIPELINE_STAGE_NONE);
            } else if (x == "AEC") {
              id(voice_kit_component).write_pipeline_stage(voice_kit::MICROPHONE_CHANNEL_1, voice_kit::PIPELINE_STAGE_AEC);
            } else if (x == "IC") {
              id(voice_kit_component).write_pipeline_stage(voice_kit::MICROPHONE_CHANNEL_1, voice_kit::PIPELINE_STAGE_IC);
            } else if (x == "NS") {
              id(voice_kit_component).write_pipeline_stage(voice_kit::MICROPHONE_CHANNEL_1, voice_kit::PIPELINE_STAGE_NS);
            } else if (x == "AGC") {
              id(voice_kit_component).write_pipeline_stage(voice_kit::MICROPHONE_CHANNEL_1, voice_kit::PIPELINE_STAGE_AGC);
            }
github-actions[bot] commented 2 weeks ago

Firmware built successfully! :tada:

Download and extract the firmware to install with https://web.esphome.io

Make sure to choose home-assistant-voice-esp32s3.factory.bin.

github-actions[bot] commented 1 week ago

Firmware built successfully! :tada:

Download and extract the firmware to install with https://web.esphome.io

Make sure to choose home-assistant-voice-esp32s3.factory.bin.

github-actions[bot] commented 1 week ago

Firmware built successfully! :tada:

Download and extract the firmware to install with https://web.esphome.io

Make sure to choose home-assistant-voice-esp32s3.factory.bin.