Add Flush to VAD so that the last segment can be detected. (#1099)
This commit is contained in:
@@ -590,6 +590,31 @@ static void VoiceActivityDetectorResetWrapper(const Napi::CallbackInfo &info) {
|
||||
SherpaOnnxVoiceActivityDetectorReset(vad);
|
||||
}
|
||||
|
||||
static void VoiceActivityDetectorFlushWrapper(const Napi::CallbackInfo &info) {
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
if (info.Length() != 1) {
|
||||
std::ostringstream os;
|
||||
os << "Expect only 1 argument. Given: " << info.Length();
|
||||
|
||||
Napi::TypeError::New(env, os.str()).ThrowAsJavaScriptException();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!info[0].IsExternal()) {
|
||||
Napi::TypeError::New(env, "Argument 0 should be a VAD pointer.")
|
||||
.ThrowAsJavaScriptException();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SherpaOnnxVoiceActivityDetector *vad =
|
||||
info[0].As<Napi::External<SherpaOnnxVoiceActivityDetector>>().Data();
|
||||
|
||||
SherpaOnnxVoiceActivityDetectorFlush(vad);
|
||||
}
|
||||
|
||||
void InitVad(Napi::Env env, Napi::Object exports) {
|
||||
exports.Set(Napi::String::New(env, "createCircularBuffer"),
|
||||
Napi::Function::New(env, CreateCircularBufferWrapper));
|
||||
@@ -636,4 +661,7 @@ void InitVad(Napi::Env env, Napi::Object exports) {
|
||||
|
||||
exports.Set(Napi::String::New(env, "voiceActivityDetectorReset"),
|
||||
Napi::Function::New(env, VoiceActivityDetectorResetWrapper));
|
||||
|
||||
exports.Set(Napi::String::New(env, "voiceActivityDetectorFlush"),
|
||||
Napi::Function::New(env, VoiceActivityDetectorFlushWrapper));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user