From d6bef63990613b34c0416321dafb8fdacee86a54 Mon Sep 17 00:00:00 2001 From: Armin Sander Date: Wed, 24 Jun 2026 14:28:02 +0200 Subject: [PATCH] Interface NoiseReductionType, so that everything is serialized in camelCase --- services/microsoft-voice-live/src/client.rs | 16 ++++++++++++-- .../microsoft-voice-live/src/transcribe.rs | 21 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/services/microsoft-voice-live/src/client.rs b/services/microsoft-voice-live/src/client.rs index d4809ee4..d5d5876d 100644 --- a/services/microsoft-voice-live/src/client.rs +++ b/services/microsoft-voice-live/src/client.rs @@ -20,7 +20,7 @@ use context_switch_core::{ Input, OutputPath, ThresholdLevel, audio, }; -use crate::transcribe::{Params, ServiceOutputEvent}; +use crate::transcribe::{NoiseReduction, NoiseReductionType, Params, ServiceOutputEvent}; use crate::transcription_state::TranscriptionState; pub struct Client { @@ -114,7 +114,7 @@ impl Client { async fn send_session_update(&mut self, params: &Params) -> Result<()> { let session = types::VoiceLiveSession { input_audio_sampling_rate: None, - input_audio_noise_reduction: params.noise_reduction.clone(), + input_audio_noise_reduction: params.noise_reduction.as_ref().map(noise_reduction), input_audio_echo_cancellation: None, input_audio_transcription: Some(types::TranscriptionConfig { language: params.language.clone(), @@ -321,6 +321,18 @@ fn eou_threshold_level(level: ThresholdLevel) -> EndOfUtteranceThresholdLevel { } } +fn noise_reduction(configured: &NoiseReduction) -> types::NoiseReduction { + let reduction_type = match configured.reduction_type { + NoiseReductionType::NearField => types::NoiseReductionType::NearField, + NoiseReductionType::FarField => types::NoiseReductionType::FarField, + NoiseReductionType::AzureDeepNoiseSuppression => { + types::NoiseReductionType::AzureDeepNoiseSuppression + } + }; + + types::NoiseReduction { reduction_type } +} + enum FlowControl { Continue, End, diff --git a/services/microsoft-voice-live/src/transcribe.rs b/services/microsoft-voice-live/src/transcribe.rs index 2598972c..41ee3260 100644 --- a/services/microsoft-voice-live/src/transcribe.rs +++ b/services/microsoft-voice-live/src/transcribe.rs @@ -1,6 +1,5 @@ use anyhow::Result; use async_trait::async_trait; -use openai_api_rs::realtime::types::NoiseReduction; use serde::{Deserialize, Serialize}; use context_switch_core::{Conversation, Service, TurnDetection}; @@ -36,6 +35,26 @@ pub struct Params { pub turn_detection: Option, } +/// Input-audio noise reduction. Mapped to the provider noise-reduction configuration before +/// being sent in the session update. +#[derive(Debug, Deserialize)] +pub struct NoiseReduction { + #[serde(rename = "type")] + pub reduction_type: NoiseReductionType, +} + +/// Noise-reduction profile. Mirrors the provider's variants with a camelCase wire form. +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum NoiseReductionType { + /// `nearField` is for close-talking microphones such as headphones. + NearField, + /// `farField` is for far-field microphones such as laptop or conference room microphones. + FarField, + /// Azure deep noise suppression, optimized for the speaker closest to the microphone. + AzureDeepNoiseSuppression, +} + #[derive(Debug)] pub struct MicrosoftVoiceLiveTranscribe;