Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

test(meetings): live smoke test for Deepgram streaming language params

Louis Beaumonta928b519af3f
diff --git a/crates/screenpipe-audio/src/meeting_streaming/deepgram_live.rs b/crates/screenpipe-audio/src/meeting_streaming/deepgram_live.rs
index d6e848d76..c1f67dfe5 100644
--- a/crates/screenpipe-audio/src/meeting_streaming/deepgram_live.rs
+++ b/crates/screenpipe-audio/src/meeting_streaming/deepgram_live.rs
@@ -482,4 +482,168 @@ mod tests {
assert!(q.contains("language=es"), "got: {q}");
assert!(!q.contains("language=multi"), "got: {q}");
}
+
+ /// Decodes a bundled speech fixture into the linear16 PCM bytes Deepgram
+ /// expects, capped to ~10s so the live test stays quick. The fixture is
+ /// english — enough to prove the stream produces transcripts, not to judge
+ /// language-specific accuracy.
+ fn fixture_pcm() -> Vec<u8> {
+ let reader = hound::WavReader::open("test_data/poetic_kapil_gupta.wav")
+ .expect("open speech fixture");
+ let spec = reader.spec();
+ let samples: Vec<f32> = match spec.sample_format {
+ hound::SampleFormat::Int => {
+ let scale = 1.0 / (1i64 << (spec.bits_per_sample - 1)) as f32;
+ reader
+ .into_samples::<i32>()
+ .map(|s| s.expect("wav sample") as f32 * scale)
+ .collect()
+ }
+ hound::SampleFormat::Float => reader
+ .into_samples::<f32>()
+ .map(|s| s.expect("wav sample"))
+ .collect(),
+ };
+ let frame = MeetingAudioFrame {
+ samples: Arc::new(samples),
+ device_name: "test".to_string(),
+ device_type: DeviceType::Input,
+ sample_rate: spec.sample_rate,
+ channels: spec.channels,
+ captured_at_unix_ms: 0,
+ };
+ let mut pcm = encode_frame(&frame).expect("encode fixture");
+ // 16kHz mono 16-bit => 32_000 bytes per second.
+ pcm.truncate(320_000);
+ pcm
+ }
+
+ /// Streams the fixture to the live Deepgram socket and reports whether any
+ /// transcript came back and whether the server emitted an `Error` event
+ /// (which is how an unsupported `language` param surfaces).
+ async fn stream_outcome(api_key: &str, language: &str) -> (bool, Option<String>) {
+ let config = MeetingStreamingConfig {
+ enabled: true,
+ provider: MeetingStreamingProvider::DeepgramLive,
+ auth_token: None,
+ api_key: Some(api_key.to_string()),
+ endpoint: "wss://api.deepgram.com/v1/listen".to_string(),
+ model: Some("nova-3".to_string()),
+ language: Some(language.to_string()),
+ local_speaker_name: None,
+ persist_finals: true,
+ };
+
+ let mut url = Url::parse(&config.endpoint).unwrap();
+ configure_live_query(&mut url, &config);
+
+ let mut request = url.as_str().into_client_request().unwrap();
+ request.headers_mut().insert(
+ AUTHORIZATION,
+ HeaderValue::from_str(&auth_header(&config.provider, api_key)).unwrap(),
+ );
+ request.headers_mut().insert(
+ USER_AGENT,
+ HeaderValue::from_static("screenpipe-meeting-streaming-deepgram-test"),
+ );
+
+ let (ws, _) = connect_websocket_with_ipv4_fallback(request)
+ .await
+ .expect("deepgram live websocket handshake should succeed");
+ let (mut write, mut read) = ws.split();
+
+ let reader = tokio::spawn(async move {
+ let mut saw_transcript = false;
+ let mut error_text: Option<String> = None;
+ while let Some(Ok(message)) = read.next().await {
+ match message {
+ Message::Text(text) => {
+ let Ok(value) = serde_json::from_str::<Value>(&text) else {
+ continue;
+ };
+ match value.get("type").and_then(Value::as_str) {
+ Some("Results") => {
+ let transcript = value
+ .pointer("/channel/alternatives/0/transcript")
+ .and_then(Value::as_str)
+ .unwrap_or_default()
+ .trim();
+ if !transcript.is_empty() {
+ saw_transcript = true;
+ }
+ }
+ Some("Error") => {
+ error_text = Some(text.clone());
+ break;
+ }
+ _ => {}
+ }
+ }
+ Message::Close(_) => break,
+ _ => {}
+ }
+ }
+ (saw_transcript, error_text)
+ });
+
+ for chunk in fixture_pcm().chunks(3200) {
+ write
+ .send(Message::Binary(chunk.to_vec()))
+ .await
+ .expect("send audio chunk");
+ tokio::time::sleep(Duration::from_millis(40)).await;
+ }
+ let _ = write
+ .send(Message::Text(json!({ "type": "Finalize" }).to_string()))
+ .await;
+ let _ = write
+ .send(Message::Text(json!({ "type": "CloseStream" }).to_string()))
+ .await;
+ let _ = write.send(Message::Close(None)).await;
+
+ match tokio::time::timeout(Duration::from_secs(30), reader).await {
+ Ok(Ok(outcome)) => outcome,
+ Ok(Err(_)) => (false, Some("reader task panicked".to_string())),
+ Err(_) => (false, None),
+ }
+ }
+
+ /// Live smoke test against the real Deepgram streaming socket, gated on a
+ /// Deepgram API key in the environment (CI without the key skips it). This
+ /// closes the one gap unit tests can't: it proves the streaming server
+ /// *accepts* `language=multi` and `language=es` (no `Error` event) and that
+ /// audio frames yield transcript events. It does NOT assert that spanish
+ /// audio transcribes as spanish — the fixture is english, so confirming
+ /// non-english output still needs a live meeting or a localized fixture.
+ #[tokio::test]
+ async fn deepgram_live_streaming_accepts_language_params() {
+ let Some(api_key) = std::env::var("SCREENPIPE_MEETING_DEEPGRAM_API_KEY")
+ .ok()
+ .or_else(|| std::env::var("DEEPGRAM_API_KEY").ok())
+ .map(|key| key.trim().to_string())
+ .filter(|key| !key.is_empty())
+ else {
+ eprintln!(
+ "skipping deepgram live smoke test: set SCREENPIPE_MEETING_DEEPGRAM_API_KEY (or DEEPGRAM_API_KEY) to run it"
+ );
+ return;
+ };
+
+ for language in ["multi", "es"] {
+ let (saw_transcript, error) = stream_outcome(&api_key, language).await;
+ assert!(
+ error.is_none(),
+ "deepgram rejected language={language}: {error:?}"
+ );
+ // The english fixture matches `multi` (which includes english), so a
+ // transcript must come back. Under a forced `es` the same audio may
+ // yield nothing; we only require the param to be accepted there.
+ if language == "multi" {
+ assert!(
+ saw_transcript,
+ "expected a transcript Results event from language=multi"
+ );
+ }
+ }
+ }
}