Skip to content

Commit dfa2beb

Browse files
committed
fix: send EndResponse when asr is empty
1 parent f685c39 commit dfa2beb

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/services/ws.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ async fn get_whisper_asr_text(
458458
let is_speech = response.map(|r| !r.timestamps.is_empty()).unwrap_or(true);
459459
if !is_speech {
460460
log::info!("VAD detected no speech, ignore this audio");
461-
continue;
461+
return Ok(String::new());
462462
}
463463
}
464464
std::fs::write(format!("./record/{id}/asr.last.wav"), &wav_data)?;
@@ -480,7 +480,7 @@ async fn get_whisper_asr_text(
480480
let text = text.join("\n");
481481
log::info!("ASR result: {:?}", text);
482482
if text.is_empty() || text.trim().starts_with("(") {
483-
continue;
483+
return Ok(String::new());
484484
}
485485
return Ok(hanconv::tw2sp(text));
486486
}
@@ -572,11 +572,7 @@ async fn get_paraformer_v2_text(
572572
break;
573573
}
574574
}
575-
if text.is_empty() {
576-
continue;
577-
} else {
578-
return Ok(text);
579-
}
575+
return Ok(text);
580576
} else {
581577
// recording
582578
let wav_data = crate::util::pcm_to_wav(
@@ -618,6 +614,9 @@ async fn submit_to_ai(
618614
asr_result: String,
619615
) -> anyhow::Result<()> {
620616
let message = asr_result;
617+
if message.is_empty() {
618+
return Err(anyhow::anyhow!("empty asr result"));
619+
}
621620

622621
tx.send(WsCommand::AsrResult(vec![message.clone()]))?;
623622

0 commit comments

Comments
 (0)