From 0b1e4e8dc7e524d9ab997e6bf01e0bece783d94e Mon Sep 17 00:00:00 2001 From: James Teh Date: Thu, 9 Nov 2023 12:43:06 +1000 Subject: [PATCH] playWaveFile: Repeatedly call stop until we're certain the previous file playback has been stopped. --- source/nvwave.py | 11 ++++++++--- user_docs/en/changes.t2t | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/nvwave.py b/source/nvwave.py index d756b4ffa35..63106ef24d8 100644 --- a/source/nvwave.py +++ b/source/nvwave.py @@ -686,7 +686,14 @@ def playWaveFile( f = wave.open(fileName,"r") if f is None: raise RuntimeError("can not open file %s"%fileName) if fileWavePlayer is not None: - fileWavePlayer.stop() + # There are several race conditions where the background thread might feed + # audio after we call stop here in the main thread. Some of these are + # difficult to fix with locks because they involve switches between Python + # and blocking native code. Just keep calling stop until we know that the + # backgroundd thread is done, which means it was successfully stopped. The + # background thread sets fileWavePlayer to None when it is done. + while fileWavePlayer: + fileWavePlayer.stop() if not decide_playWaveFile.decide( fileName=fileName, asynchronous=asynchronous, @@ -711,8 +718,6 @@ def play(): # player for the next file anyway - so just destroy it now. fileWavePlayer = None - if asynchronous and fileWavePlayerThread is not None: - fileWavePlayerThread.join() fileWavePlayer = WavePlayer( channels=f.getnchannels(), samplesPerSec=f.getframerate(), diff --git a/user_docs/en/changes.t2t b/user_docs/en/changes.t2t index 35ddd453661..69ebbef3bfb 100644 --- a/user_docs/en/changes.t2t +++ b/user_docs/en/changes.t2t @@ -53,6 +53,7 @@ It is also updated with UIA enabled, when typing text and braille is tethered to - When using say all or commands which spell text, pauses between sentences or characters no longer gradually decrease over time. (#15739) - NVDA no longer sometimes freezes when speaking a large amount of text. (#15752) - More objects which contain useful text are detected, and text content is displayed in braille. (#15605) +- NVDA no longer freezes briefly when multiple sounds are played in rapid succession. (#15757) - == Changes for Developers ==