Skip to content

Commit

Permalink
Expose VAD isDetected api to Swift (k2-fsa#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
yujinqiu authored Oct 12, 2023
1 parent 32da5ec commit f6566c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions sherpa-onnx/c-api/c-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions sherpa-onnx/c-api/c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion swift-api-examples/SherpaOnnx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f6566c8

Please sign in to comment.