From f30d9bb244566a85895e95f0c224000abe058f04 Mon Sep 17 00:00:00 2001 From: Armin Sander Date: Wed, 22 Jul 2026 10:55:35 +0200 Subject: [PATCH 1/2] Update tokio-websockets in the azure-speech-sdk-rs beause of a potential websocket upgrade problem and add a timeout of 5 seconds to all Azure connects --- external/azure-speech-sdk-rs | 2 +- services/azure/src/lib.rs | 15 +++++++++++++++ services/azure/src/synthesize.rs | 5 +++-- services/azure/src/transcribe.rs | 5 +++-- services/azure/src/translate.rs | 5 +++-- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/external/azure-speech-sdk-rs b/external/azure-speech-sdk-rs index ef3fcd24..9c5b66ac 160000 --- a/external/azure-speech-sdk-rs +++ b/external/azure-speech-sdk-rs @@ -1 +1 @@ -Subproject commit ef3fcd24c73eda43140b670614cd9b97060275fc +Subproject commit 9c5b66acf71be6352d731396fe42705963c982fe diff --git a/services/azure/src/lib.rs b/services/azure/src/lib.rs index 914eed7d..c7f924e3 100644 --- a/services/azure/src/lib.rs +++ b/services/azure/src/lib.rs @@ -1,3 +1,8 @@ +use std::{future::Future, time::Duration}; + +use anyhow::{Context, Result}; +use tokio::time::timeout; + mod host; // TODO: Attempt to make the modules non-pub pub mod synthesize; @@ -9,3 +14,13 @@ pub use host::*; pub use synthesize::AzureSynthesize; pub use transcribe::AzureTranscribe; pub use translate::AzureTranslate; + +// The 256-frame input buffer fills in about 5.1 seconds at the usual 20 ms frame cadence. +// Fail the connection first so buffer overflow does not terminate the conversation instead. +const CONNECT_TIMEOUT: Duration = Duration::from_secs(5); + +async fn connect_with_timeout(connection: impl Future) -> Result { + timeout(CONNECT_TIMEOUT, connection) + .await + .context("Azure connection timed out") +} diff --git a/services/azure/src/synthesize.rs b/services/azure/src/synthesize.rs index a4aa028f..a7f6c1d2 100644 --- a/services/azure/src/synthesize.rs +++ b/services/azure/src/synthesize.rs @@ -14,7 +14,7 @@ use context_switch_core::{ AudioFrame, BillingRecord, BillingSchedule, Conversation, Input, Service, }; -use crate::Host; +use crate::{Host, connect_with_timeout}; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -64,7 +64,8 @@ impl Service for AzureSynthesize { .enable_session_end() .with_audio_format(azure_audio_format); - let client = synthesizer::Client::connect(host.auth.clone(), config).await?; + let client = + connect_with_timeout(synthesizer::Client::connect(host.auth.clone(), config)).await??; let language = params.language; let (mut input, output) = conversation.start()?; diff --git a/services/azure/src/transcribe.rs b/services/azure/src/transcribe.rs index 91baf5fd..d71aa16c 100644 --- a/services/azure/src/transcribe.rs +++ b/services/azure/src/transcribe.rs @@ -13,7 +13,7 @@ use context_switch_core::{ speech_gate::make_speech_gate_processor_soft_rms, }; -use crate::Host; +use crate::{Host, connect_with_timeout}; #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] @@ -90,7 +90,8 @@ impl Service for AzureTranscribe { } .set_output_format(recognizer::OutputFormat::Detailed); - let client = recognizer::Client::connect(host.auth.clone(), config).await?; + let client = + connect_with_timeout(recognizer::Client::connect(host.auth.clone(), config)).await??; let (mut input, output) = conversation.start()?; diff --git a/services/azure/src/translate.rs b/services/azure/src/translate.rs index 5535e3a9..2da16f1c 100644 --- a/services/azure/src/translate.rs +++ b/services/azure/src/translate.rs @@ -6,7 +6,7 @@ use futures::StreamExt; use serde::{Deserialize, Serialize}; use tracing::{debug, error}; -use crate::Host; +use crate::{Host, connect_with_timeout}; use context_switch_core::{ AudioFormat, AudioFrame, BillingRecord, BillingSchedule, Conversation, Input, OutputModality, OutputPath, Service, @@ -74,7 +74,8 @@ impl Service for AzureTranslate { } }; - let client = translator::Client::connect(host.auth.clone(), config).await?; + let client = + connect_with_timeout(translator::Client::connect(host.auth.clone(), config)).await??; let (mut input, output) = conversation.start()?; From b7722c3b62d3b282afd6a5da207288febcba6676 Mon Sep 17 00:00:00 2001 From: Armin Sander Date: Wed, 22 Jul 2026 11:11:37 +0200 Subject: [PATCH 2/2] Bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ad9642d8..12304a31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ members = [ ] [workspace.package] -version = "3.4.0" +version = "3.4.1" edition = "2024" license = "MIT" repository = "https://github.com/pragmatrix/context-switch"