Add vad clear api for better performance (#366)
* Add vad clear api for better performance * rename to make naming consistent and remove macro * Fix linker error * Fix Vad.kt
This commit is contained in:
@@ -493,12 +493,17 @@ int32_t SherpaOnnxVoiceActivityDetectorDetected(
|
||||
return p->impl->IsSpeechDetected();
|
||||
}
|
||||
|
||||
SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorPop(
|
||||
void SherpaOnnxVoiceActivityDetectorPop(
|
||||
SherpaOnnxVoiceActivityDetector *p) {
|
||||
p->impl->Pop();
|
||||
}
|
||||
|
||||
SHERPA_ONNX_API const SherpaOnnxSpeechSegment *
|
||||
void SherpaOnnxVoiceActivityDetectorClear(
|
||||
SherpaOnnxVoiceActivityDetector *p) {
|
||||
p->impl->Clear();
|
||||
}
|
||||
|
||||
const SherpaOnnxSpeechSegment *
|
||||
SherpaOnnxVoiceActivityDetectorFront(SherpaOnnxVoiceActivityDetector *p) {
|
||||
const sherpa_onnx::SpeechSegment &segment = p->impl->Front();
|
||||
|
||||
|
||||
@@ -580,6 +580,10 @@ SherpaOnnxVoiceActivityDetectorDetected(SherpaOnnxVoiceActivityDetector *p);
|
||||
SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorPop(
|
||||
SherpaOnnxVoiceActivityDetector *p);
|
||||
|
||||
// Clear current speech segments.
|
||||
SHERPA_ONNX_API void SherpaOnnxVoiceActivityDetectorClear(
|
||||
SherpaOnnxVoiceActivityDetector *p);
|
||||
|
||||
// Return the first speech segment.
|
||||
// The user has to use SherpaOnnxDestroySpeechSegment() to free the returned
|
||||
// pointer to avoid memory leak.
|
||||
|
||||
@@ -76,6 +76,8 @@ class VoiceActivityDetector::Impl {
|
||||
|
||||
void Pop() { segments_.pop(); }
|
||||
|
||||
void Clear() { std::queue<SpeechSegment>().swap(segments_); }
|
||||
|
||||
const SpeechSegment &Front() const { return segments_.front(); }
|
||||
|
||||
void Reset() {
|
||||
@@ -121,6 +123,8 @@ bool VoiceActivityDetector::Empty() const { return impl_->Empty(); }
|
||||
|
||||
void VoiceActivityDetector::Pop() { impl_->Pop(); }
|
||||
|
||||
void VoiceActivityDetector::Clear() { impl_->Clear(); }
|
||||
|
||||
const SpeechSegment &VoiceActivityDetector::Front() const {
|
||||
return impl_->Front();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ class VoiceActivityDetector {
|
||||
void AcceptWaveform(const float *samples, int32_t n);
|
||||
bool Empty() const;
|
||||
void Pop();
|
||||
void Clear();
|
||||
const SpeechSegment &Front() const;
|
||||
|
||||
bool IsSpeechDetected() const;
|
||||
|
||||
@@ -124,6 +124,8 @@ class SherpaOnnxVad {
|
||||
|
||||
void Pop() { vad_.Pop(); }
|
||||
|
||||
void Clear() { vad_.Clear();}
|
||||
|
||||
const SpeechSegment &Front() const { return vad_.Front(); }
|
||||
|
||||
bool IsSpeechDetected() const { return vad_.IsSpeechDetected(); }
|
||||
@@ -556,6 +558,14 @@ JNIEXPORT void JNICALL Java_com_k2fsa_sherpa_onnx_Vad_pop(JNIEnv *env,
|
||||
model->Pop();
|
||||
}
|
||||
|
||||
SHERPA_ONNX_EXTERN_C
|
||||
JNIEXPORT void JNICALL Java_com_k2fsa_sherpa_onnx_Vad_clear(JNIEnv *env,
|
||||
jobject /*obj*/,
|
||||
jlong ptr) {
|
||||
auto model = reinterpret_cast<sherpa_onnx::SherpaOnnxVad *>(ptr);
|
||||
model->Clear();
|
||||
}
|
||||
|
||||
// see
|
||||
// https://stackoverflow.com/questions/29043872/android-jni-return-multiple-variables
|
||||
static jobject NewInteger(JNIEnv *env, int32_t value) {
|
||||
|
||||
Reference in New Issue
Block a user