Skip to content

Commit

Permalink
Don't try converting to text if no speech detected
Browse files Browse the repository at this point in the history
  • Loading branch information
paulovcmedeiros committed Nov 15, 2023
1 parent 8b3cb0c commit e2ece16
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pyrobbot/text_to_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def callback(indata, frames, time, status): # noqa: ARG001
)
last_inactivity_checked = datetime.now()
user_is_speaking = True
speech_detected = False
with contextlib.suppress(KeyboardInterrupt):
while user_is_speaking:
new_data = q.get()
Expand All @@ -138,13 +139,12 @@ def callback(indata, frames, time, status): # noqa: ARG001
user_is_speaking = (
speech_likelihood >= self.speech_likelihood_threshold
)
if user_is_speaking:
speech_detected = True
last_inactivity_checked = now

# Detect if there was any sound at all, skip the conversion if not
recorded_audio = np.frombuffer(raw_buffer.getvalue(), dtype=np.int16)
max_intensity = np.max(np.absolute(recorded_audio))
if max_intensity < self.inactivity_sound_intensity_threshold:
logger.debug("No sound detected")
if not speech_detected:
logger.debug("No speech detected")
return ""

logger.debug("Converting audio to text...")
Expand Down

0 comments on commit e2ece16

Please sign in to comment.