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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion external/azure-speech-sdk-rs
15 changes: 15 additions & 0 deletions services/azure/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<T>(connection: impl Future<Output = T>) -> Result<T> {
timeout(CONNECT_TIMEOUT, connection)
.await
.context("Azure connection timed out")
}
5 changes: 3 additions & 2 deletions services/azure/src/synthesize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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()?;
Expand Down
5 changes: 3 additions & 2 deletions services/azure/src/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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()?;

Expand Down
5 changes: 3 additions & 2 deletions services/azure/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()?;

Expand Down
Loading