fix(recognition): play stop sound after audio thread joins to prevent capture on short recordings (#436)

Moves play_stop_sound() to after audio_thread.join() but before the
final buffer processing. This closes the race where the audio thread's
in-flight chunk could capture the stop cue for short (≤ ~192 ms) recordings,
while still feeling immediate compared to the original placement after all
recognition cleanup.
This commit is contained in:
Jatin K Malik
2026-05-30 14:41:08 -07:00
committed by GitHub
parent a267f500dd
commit c39f9ce431
2 changed files with 7 additions and 6 deletions
+3 -2
View File
@@ -226,7 +226,7 @@ class TestStartStopRecognition(unittest.TestCase):
mgr.stop_recognition()
self.assertFalse(mgr.should_record)
def test_stop_sound_plays_before_audio_thread_join(self):
def test_stop_sound_plays_after_audio_thread_join(self):
mgr = _make_manager()
mgr.state = RecognitionState.LISTENING
mgr.should_record = True
@@ -241,7 +241,8 @@ class TestStartStopRecognition(unittest.TestCase):
):
mgr.stop_recognition()
self.assertEqual(events[:2], ["sound", "join"])
# sound must play after the audio thread has joined so the cue cannot be captured
self.assertEqual(events[:2], ["join", "sound"])
def test_stop_sound_guard_chunk_calculation(self):
mgr = _make_manager()