Add py312 check for tempfile delete_on_close keyword

This commit is contained in:
SWivid
2025-05-22 23:10:29 +08:00
parent 2968aa184f
commit ecd1c3949a
2 changed files with 6 additions and 3 deletions

View File

@@ -42,6 +42,7 @@ from f5_tts.infer.utils_infer import (
preprocess_ref_audio_text,
remove_silence_for_generated_wav,
save_spectrogram,
tempfile_kwargs,
)
from f5_tts.model import DiT, UNetT
@@ -190,7 +191,7 @@ def infer(
# Remove silence
if remove_silence:
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
with tempfile.NamedTemporaryFile(suffix=".wav", **tempfile_kwargs) as f:
temp_path = f.name
try:
sf.write(temp_path, final_wave, final_sample_rate)
@@ -201,7 +202,7 @@ def infer(
final_wave = final_wave.squeeze().cpu().numpy()
# Save the spectrogram
with tempfile.NamedTemporaryFile(suffix=".png", delete_on_close=False) as tmp_spectrogram:
with tempfile.NamedTemporaryFile(suffix=".png", **tempfile_kwargs) as tmp_spectrogram:
spectrogram_path = tmp_spectrogram.name
save_spectrogram(combined_spectrogram, spectrogram_path)

View File

@@ -45,6 +45,8 @@ device = (
else "cpu"
)
tempfile_kwargs = {"delete_on_close": False} if sys.version_info >= (3, 12) else {"delete": False}
# -----------------------------------------
target_sample_rate = 24000
@@ -306,7 +308,7 @@ def preprocess_ref_audio_text(ref_audio_orig, ref_text, show_info=print):
ref_audio = _ref_audio_cache[audio_hash]
else: # first pass, do preprocess
with tempfile.NamedTemporaryFile(delete_on_close=False, suffix=".wav") as f:
with tempfile.NamedTemporaryFile(suffix=".wav", **tempfile_kwargs) as f:
temp_path = f.name
aseg = AudioSegment.from_file(ref_audio_orig)