Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions services/microsoft-voice-live/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 20 additions & 1 deletion services/microsoft-voice-live/src/transcribe.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -36,6 +35,26 @@ pub struct Params {
pub turn_detection: Option<TurnDetection>,
}

/// 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;

Expand Down
Loading