Skip to content

Commit 1aa8203

Browse files
committed
fix: bailian asr support reconnect
1 parent 74c595a commit 1aa8203

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/ai/bailian/realtime_asr.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ impl ParaformerRealtimeV2Asr {
125125
log::debug!("Received message: {:?}", text);
126126

127127
let response: ResponseMessage = serde_json::from_str(&text)?;
128+
if response.header.task_id != self.task_id {
129+
log::warn!(
130+
"Received message for different task_id: {}",
131+
response.header.task_id
132+
);
133+
continue;
134+
}
128135

129136
if response.is_task_started() {
130137
log::info!("Recognition task started");

src/services/ws/stable/asr.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,19 @@ impl ParaformerASRSession {
4343
}
4444
ClientMsg::StartChat => {
4545
log::info!("`{id}` starting paraformer asr");
46-
self.start_pcm_recognition().await.map_err(|e| {
47-
anyhow::anyhow!("`{id}` error starting paraformer asr: {e}")
48-
})?;
46+
if let Err(e) = self.start_pcm_recognition().await {
47+
log::warn!(
48+
"`{id}` error starting paraformer asr: {e}, attempting to reconnect..."
49+
);
50+
self.reconnect().await.map_err(|e| {
51+
anyhow::anyhow!("`{id}` error reconnecting paraformer asr: {e}")
52+
})?;
53+
log::info!("`{id}` paraformer asr reconnected successfully");
54+
self.start_pcm_recognition().await.map_err(|e| {
55+
anyhow::anyhow!("`{id}` error starting paraformer asr: {e}")
56+
})?;
57+
}
58+
4959
continue;
5060
}
5161
}

0 commit comments

Comments
 (0)