|
@@ -540,7 +540,8 @@ class Recognizer(AudioSource):
|
|
|
|
|
|
|
|
# detect whether speaking has started on audio input
|
|
# detect whether speaking has started on audio input
|
|
|
energy = audioop.rms(buffer, source.SAMPLE_WIDTH) # energy of the audio signal
|
|
energy = audioop.rms(buffer, source.SAMPLE_WIDTH) # energy of the audio signal
|
|
|
- if energy > self.energy_threshold: break
|
|
|
|
|
|
|
+ if energy > self.energy_threshold:
|
|
|
|
|
+ break
|
|
|
|
|
|
|
|
# dynamically adjust the energy threshold using asymmetric weighted average
|
|
# dynamically adjust the energy threshold using asymmetric weighted average
|
|
|
if self.dynamic_energy_threshold:
|
|
if self.dynamic_energy_threshold:
|
|
@@ -560,7 +561,9 @@ class Recognizer(AudioSource):
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
buffer = source.stream.read(source.CHUNK)
|
|
buffer = source.stream.read(source.CHUNK)
|
|
|
- if len(buffer) == 0: break # reached end of the stream
|
|
|
|
|
|
|
+ if len(buffer) == 0:
|
|
|
|
|
+ break # reached end of the stream
|
|
|
|
|
+
|
|
|
frames.append(buffer)
|
|
frames.append(buffer)
|
|
|
phrase_count += 1
|
|
phrase_count += 1
|
|
|
|
|
|
|
@@ -570,6 +573,7 @@ class Recognizer(AudioSource):
|
|
|
pause_count = 0
|
|
pause_count = 0
|
|
|
else:
|
|
else:
|
|
|
pause_count += 1
|
|
pause_count += 1
|
|
|
|
|
+
|
|
|
if pause_count > pause_buffer_count: # end of the phrase
|
|
if pause_count > pause_buffer_count: # end of the phrase
|
|
|
break
|
|
break
|
|
|
|
|
|