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:
+7
-7
@@ -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
|
||||||
|
|
||||||
try:
|
# Close the file before reading it back (required on Windows)
|
||||||
model_state = tts_model.get_state_for_audio_prompt(
|
try:
|
||||||
Path(temp_file.name), truncate=True
|
model_state = tts_model.get_state_for_audio_prompt(Path(temp_file_path), truncate=True)
|
||||||
)
|
finally:
|
||||||
finally:
|
os.unlink(temp_file_path)
|
||||||
os.unlink(temp_file.name)
|
|
||||||
else:
|
else:
|
||||||
# Use default global model state
|
# Use default global model state
|
||||||
model_state = global_model_state
|
model_state = global_model_state
|
||||||
|
|||||||
Reference in New Issue
Block a user