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.
This commit is contained in:
Václav Volhejn
2026-01-21 10:54:03 +01:00
committed by GitHub
parent 9650c0775b
commit 2d62797f28
+5 -5
View File
@@ -39,7 +39,7 @@ cli_app = typer.Typer(
# ------------------------------------------------------ # ------------------------------------------------------
# Global model instance # Global model instance
tts_model = None tts_model: TTSModel | None = None
global_model_state = None global_model_state = None
web_app = FastAPI( web_app = FastAPI(
@@ -151,13 +151,13 @@ def text_to_speech(
content = voice_wav.file.read() content = voice_wav.file.read()
temp_file.write(content) temp_file.write(content)
temp_file.flush() temp_file.flush()
temp_file_path = temp_file.name
# Close the file before reading it back (required on Windows)
try: try:
model_state = tts_model.get_state_for_audio_prompt( model_state = tts_model.get_state_for_audio_prompt(Path(temp_file_path), truncate=True)
Path(temp_file.name), truncate=True
)
finally: finally:
os.unlink(temp_file.name) os.unlink(temp_file_path)
else: else:
# Use default global model state # Use default global model state
model_state = global_model_state model_state = global_model_state