79253549

Date: 2024-12-05 06:06:25
Score: 0.5
Natty:
Report link

When silence is detected AcceptWaveform() returns True and you can retrieve the result with Result(). If it returns False you can retrieve a partial result with PartialResult(). The FinalResult() means the stream is ended, buffers are flushed and you retrieve the remaining result which could be silence.

What you could do is

import json
                
text = []    
with open(audio_file, "rb") as audio:
    while True:
        data = audio.read(4000)
        if len(data) == 0:
             break
        # if silence detected save result
        if recognizer.AcceptWaveform(data):
            text.append(json.loads(rec.Result())["text"])
text.append(json.loads(rec.FinalResult())["text"])


and you get a list of sentences.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): When
  • Low reputation (1):
Posted by: Lewis