|
@@ -519,6 +519,9 @@ class Recognizer(AudioSource):
|
|
|
phrase_buffer_count = int(math.ceil(self.phrase_threshold / seconds_per_buffer)) # minimum number of buffers of speaking audio before we consider the speaking audio a phrase
|
|
phrase_buffer_count = int(math.ceil(self.phrase_threshold / seconds_per_buffer)) # minimum number of buffers of speaking audio before we consider the speaking audio a phrase
|
|
|
non_speaking_buffer_count = int(math.ceil(self.non_speaking_duration / seconds_per_buffer)) # maximum number of buffers of non-speaking audio to retain before and after a phrase
|
|
non_speaking_buffer_count = int(math.ceil(self.non_speaking_duration / seconds_per_buffer)) # maximum number of buffers of non-speaking audio to retain before and after a phrase
|
|
|
|
|
|
|
|
|
|
+ logging.info((seconds_per_buffer, pause_buffer_count))
|
|
|
|
|
+ logging.info((source.CHUNK, source.SAMPLE_RATE))
|
|
|
|
|
+
|
|
|
# read audio input for phrases until there is a phrase that is long enough
|
|
# read audio input for phrases until there is a phrase that is long enough
|
|
|
elapsed_time = 0 # number of seconds of audio read
|
|
elapsed_time = 0 # number of seconds of audio read
|
|
|
buffer = b"" # an empty buffer means that the stream has ended and there is no data left to read
|
|
buffer = b"" # an empty buffer means that the stream has ended and there is no data left to read
|
|
@@ -548,7 +551,7 @@ class Recognizer(AudioSource):
|
|
|
target_energy = energy * self.dynamic_energy_ratio
|
|
target_energy = energy * self.dynamic_energy_ratio
|
|
|
self.energy_threshold = self.energy_threshold * damping + target_energy * (1 - damping)
|
|
self.energy_threshold = self.energy_threshold * damping + target_energy * (1 - damping)
|
|
|
|
|
|
|
|
- #logging.info('Waiting for start of phrase (energy: %i; energy threshold: %i)', energy, self.energy_threshold)
|
|
|
|
|
|
|
+ logging.info('Waiting for start of phrase (energy: %i; energy threshold: %i)', energy, self.energy_threshold)
|
|
|
|
|
|
|
|
# read audio input until the phrase ends
|
|
# read audio input until the phrase ends
|
|
|
pause_count, phrase_count = 0, 0
|
|
pause_count, phrase_count = 0, 0
|
|
@@ -573,11 +576,12 @@ class Recognizer(AudioSource):
|
|
|
if pause_count > pause_buffer_count: # end of the phrase
|
|
if pause_count > pause_buffer_count: # end of the phrase
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
- #logging.info('Waiting for end of phrase (energy: %i; energy threshold: %i)', energy, self.energy_threshold)
|
|
|
|
|
|
|
+ logging.info('Waiting for end of phrase (energy: %i; energy threshold: %i)', energy, self.energy_threshold)
|
|
|
|
|
+
|
|
|
|
|
+ logging.info((phrase_count, pause_count, phrase_buffer_count, len(buffer)))
|
|
|
|
|
|
|
|
# check how long the detected phrase is, and retry listening if the phrase is too short
|
|
# check how long the detected phrase is, and retry listening if the phrase is too short
|
|
|
- phrase_count -= pause_count # exclude the buffers for the pause before the phrase
|
|
|
|
|
- if phrase_count >= phrase_buffer_count or len(buffer) == 0 or True: break # phrase is long enough or we've reached the end of the stream, so stop listening
|
|
|
|
|
|
|
+ if phrase_count - pause_count >= phrase_buffer_count or len(buffer) == 0: break # phrase is long enough or we've reached the end of the stream, so stop listening
|
|
|
|
|
|
|
|
# obtain frame data
|
|
# obtain frame data
|
|
|
for i in range(pause_count - non_speaking_buffer_count): frames.pop() # remove extra non-speaking frames at the end
|
|
for i in range(pause_count - non_speaking_buffer_count): frames.pop() # remove extra non-speaking frames at the end
|