Repository navigation
fix(tts): serialize shared playback stop and initialization - #242
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Related to #241.
StreamPlayer.stop()clearedis_playingand drained queued writes before acquiring the device lock. A concurrentinitialize()could reopen the output and publishis_playing=True; the unfinished stop would then detach that new stream, leavingis_playing=True, stream=None. Stopping while a native open was in progress could leave the same inconsistent state. A subsequent write can raiseaudio stream is not initialized.Serialize the stop's flag change, queue drain, and stream detachment/close under the existing reentrant device lock, matching
initialize(). No new state, retry, dependency, or platform branch is added.The defect is in the shared player and does not require AMD hardware to reproduce. This is a verified upstream race, but we have not established that it is the exact cause of the reporter's installation failure. It is independent of the GPT-SoVITS reference-loading changes in #238.
Change class
Owning layer: shared TTS output-stream lifecycle (
tts/playback.py).User-visible effect: concurrent stop/open operations leave either a stopped player or a usable replacement stream, rather than a playing flag with no stream. Existing playback-epoch invalidation still rejects stale audio.
Compatibility/migration: none; public APIs, device selection, backend routing, and bounded output-open recovery are unchanged.
Evidence
Windows / Python 3.12.10, CPU/model-less execution, synthetic PCM and mocked audio devices; no physical playback:
7b97e21c63b680d3ad53b1a14198dd52de882593: 6 failed, 10 passed intests/test_playback_device_recovery.py. Both stop/open orderings reproduce the inconsistent state. The fixed implementation passes all 16 cases.AMADEUS_E2E_NO_TTS=1 TTS_DEVICE=cpu WORK_WORKTREE_ISOLATION=0:python -B -m ruff check tts/playback.py tests/test_playback_device_recovery.pyandgit diff --check: passed.8b8ad82a771e064a79fd7decccdcd2eb2a676435, including Linux/macOS voice checks, Windows/Linux cu128, macOS MPS, the cu124 single-environment ladder, build, and desktop smoke checks. These do not constitute real headset or GPU playback validation.Remaining validation: no real AMD/NVIDIA GPU, reporter headset, or Fish Audio end-to-end run was performed. Please test first-utterance playback, subsequent turns, interruption followed by a new reply, and streaming with the normal PyAudio path. The reporter's exact source revision/package and any local audio-library edits still need confirmation before attributing the whole report to this race.
Final check