Open hyansuper opened 4 years ago
or maybe, if PartialResult() does not change, then it means silence?
def fun(recognizer, stream, timeout):
partial = ''
no_speech_count = 0
while True:
if recognizer.AcceptWaveform(stream.read(4000)):
return recognizer.Result()
elif partial != recognizer.PartialResult()['partial']:
partial = recognizer.PartialResult()['partial']
no_speech_count = 0
else: # partial ==recognizer.PartialResult()['partial'], so there's no new speech
no_speech_count += 4000 / samplerate / channels
if no_speech_count > timeout:
return recognizer.FinalResult()
Off-topic. But it might be useful. On the client side (browser/electron) I am using hark.
However, in fact, this is probably not the best way, due to the ability to write your own Audio-Worklet.
@hyansuper or maybe, if PartialResult() does not change, then it means silence?
works for me.
I want to end speech recognition and call FinalResult() when silence last longer than a timeout parameter. The pocketsphinx-python lib has a get_in_speech() function which seems to be doing the VAD thing, maybe we can implement similar function. [python psudo code]:
I notice there is a private function UpdateSilenceWeights, I don't know if it's related to voice activity detection.