fix(asr): do not call InputFinished for a never-ending stream
A live caption stream never ends: the boundary of an utterance is silence, not end-of-input, so InputFinished (which means "no more audio ever") does not apply. Drop it and rely on the trailing audio alone; keep a short silence padding as a safety net for end-of-file cases. Verified that the file path still emits the final character without InputFinished. 实时字幕的音频流永不结束,一句话的边界是"静音"而不是"输入结束",所以 不该调用语义为"再也不会有音频"的 InputFinished。改为只补一小段静音兜底, 实测文件模式的结果依然完整。文档也一并更正。
This commit is contained in:
1 parent
bd921b1ac5
commit
b37b9eb779
2 files changed
+9
-4
No files matched your search
@@ -67,7 +67,11 @@ IAsr(src/core/iasr.h)
|
||||
|
||||
1. **sherpa-onnx 的预编译库是旧 C++ ABI**(`_GLIBCXX_USE_CXX11_ABI=0`),和 Qt 的新 ABI 冲突,
|
||||
C++ API 链接不上。**必须用它的 C API**(`sherpa-onnx/c-api/c-api.h`,`extern "C"`,无名字改写)。
|
||||
2. **结束时要补一小段静音**(`streamFinish()` 里补 0.3s)再 `InputFinished`,否则最后一个字会被截掉。
|
||||
2. **末尾要补一小段静音**(`streamFinish()` 里补 0.3s),否则最后一个字会被截掉。
|
||||
但**不需要 `InputFinished`**:实时字幕的音频流永不结束,一句话的边界是「静音」而不是「输入结束」,
|
||||
`InputFinished` 的语义只对文件成立。实测只补静音(不调 `InputFinished`)结果就是完整的。
|
||||
真实场景里那段尾部静音本来就会被喂进去(VAD 判定静音要 0.8s,这 0.8s 已经送给模型了),
|
||||
所以补静音只是个兜底。
|
||||
|
||||
## 自动语言识别
|
||||
|
||||
|
||||
@@ -92,9 +92,10 @@ std::string SherpaAsr::streamFinish()
|
||||
const std::vector<float> silence(pad, 0.0f);
|
||||
SherpaOnnxOnlineStreamAcceptWaveform(d->stream, 16000, silence.data(), (int32_t) pad);
|
||||
d->drain();
|
||||
// 通知不再有输入,把尾部一并解出来
|
||||
SherpaOnnxOnlineStreamInputFinished(d->stream);
|
||||
d->drain();
|
||||
// 注意:这里**不调用 InputFinished**。
|
||||
// 实时字幕的音频流是永不结束的,一句话的边界是"静音"而不是"输入结束";
|
||||
// InputFinished 的语义(再也不会有音频了)对文件才成立,对我们不适用。
|
||||
// 只需要补一小段静音,让模型把最后一个字吐出来即可。
|
||||
return d->resultText();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user