From 2d62797f282a4de3da2fb81a1aa79602603ffd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Volhejn?= <8401624+vvolhejn@users.noreply.github.com> Date: Wed, 21 Jan 2026 10:54:03 +0100 Subject: [PATCH] Fix temp file issue on windows (I hope) (#72) Thank you @Arihant25, re-integrating the changes from your PR because Gabriel is not here to do his fix. The plan was to get rid of the temporary file altogether and pass a file-like object, but in the meantime let's at least have something that works. --- pocket_tts/main.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pocket_tts/main.py b/pocket_tts/main.py index 0fbc057..c9711a1 100644 --- a/pocket_tts/main.py +++ b/pocket_tts/main.py @@ -39,7 +39,7 @@ cli_app = typer.Typer( # ------------------------------------------------------ # Global model instance -tts_model = None +tts_model: TTSModel | None = None global_model_state = None web_app = FastAPI( @@ -151,13 +151,13 @@ def text_to_speech( content = voice_wav.file.read() temp_file.write(content) temp_file.flush() + temp_file_path = temp_file.name - try: - model_state = tts_model.get_state_for_audio_prompt( - Path(temp_file.name), truncate=True - ) - finally: - os.unlink(temp_file.name) + # Close the file before reading it back (required on Windows) + try: + model_state = tts_model.get_state_for_audio_prompt(Path(temp_file_path), truncate=True) + finally: + os.unlink(temp_file_path) else: # Use default global model state model_state = global_model_state