diff --git a/sherpa-onnx/c-api/c-api.cc b/sherpa-onnx/c-api/c-api.cc index c08a3fef6..3f6b35466 100644 --- a/sherpa-onnx/c-api/c-api.cc +++ b/sherpa-onnx/c-api/c-api.cc @@ -488,6 +488,11 @@ int32_t SherpaOnnxVoiceActivityDetectorEmpty( return p->impl->Empty(); } +int32_t SherpaOnnxVoiceActivityDetectorDetected( + SherpaOnnxVoiceActivityDetector *p) { + return p->impl->IsSpeechDetected(); +} + SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorPop( SherpaOnnxVoiceActivityDetector *p) { p->impl->Pop(); diff --git a/sherpa-onnx/c-api/c-api.h b/sherpa-onnx/c-api/c-api.h index a5a341d27..b79b83072 100644 --- a/sherpa-onnx/c-api/c-api.h +++ b/sherpa-onnx/c-api/c-api.h @@ -570,6 +570,11 @@ SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorAcceptWaveform( SHERPA_ONNX_API int32_t SherpaOnnxVoiceActivityDetectorEmpty(SherpaOnnxVoiceActivityDetector *p); +// Return 1 if there is voice detected. +// Return 0 if voice is silent. +SHERPA_ONNX_API int32_t +SherpaOnnxVoiceActivityDetectorDetected(SherpaOnnxVoiceActivityDetector *p); + // Return the first speech segment. // It throws if SherpaOnnxVoiceActivityDetectorEmpty() returns 1. SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorPop( diff --git a/swift-api-examples/SherpaOnnx.swift b/swift-api-examples/SherpaOnnx.swift index 11dabcda0..53637011c 100644 --- a/swift-api-examples/SherpaOnnx.swift +++ b/swift-api-examples/SherpaOnnx.swift @@ -548,7 +548,11 @@ class SherpaOnnxVoiceActivityDetectorWrapper { } func isEmpty() -> Bool { - return SherpaOnnxVoiceActivityDetectorEmpty(vad) == 1 ? true : false + return SherpaOnnxVoiceActivityDetectorEmpty(vad) == 1 + } + + func isDetected() -> Bool { + return SherpaOnnxVoiceActivityDetectorDetected(vad) == 1 } func pop() {