Skip to content

Commit d39b0c5

Browse files
committed
Fixed problem with not removing temporary audio file.
1 parent 43e9828 commit d39b0c5

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

F5TTS.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def create(self, voices, chunks, seed=-1, model="F5"):
154154

155155
class F5TTSAudioInputs:
156156
def __init__(self):
157-
self.wave_file = None
157+
self.wave_file_name = None
158158

159159
@classmethod
160160
def INPUT_TYPES(s):
@@ -181,28 +181,36 @@ def INPUT_TYPES(s):
181181
FUNCTION = "create"
182182

183183
def load_voice_from_input(self, sample_audio, sample_text):
184-
self.wave_file = tempfile.NamedTemporaryFile(
184+
wave_file = tempfile.NamedTemporaryFile(
185185
suffix=".wav", delete=False
186186
)
187+
self.wave_file_name = wave_file.name
188+
wave_file.close()
189+
190+
hasAudio = False
187191
for (batch_number, waveform) in enumerate(
188-
sample_audio["waveform"].cpu()):
192+
sample_audio["waveform"].cpu()
193+
):
189194
buff = io.BytesIO()
190195
torchaudio.save(
191196
buff, waveform, sample_audio["sample_rate"], format="WAV"
192197
)
193-
with open(self.wave_file.name, 'wb') as f:
198+
with open(self.wave_file_name, 'wb') as f:
194199
f.write(buff.getbuffer())
200+
hasAudio = True
195201
break
196-
r = F5TTSCreate.load_voice(self.wave_file.name, sample_text)
202+
if not hasAudio:
203+
raise FileNotFoundError("No audio input")
204+
r = F5TTSCreate.load_voice(self.wave_file_name, sample_text)
197205
return r
198206

199207
def remove_wave_file(self):
200-
if self.wave_file is not None:
208+
if self.wave_file_name is not None:
201209
try:
202-
os.unlink(self.wave_file.name)
203-
self.wave_file = None
210+
os.unlink(self.wave_file_name)
211+
self.wave_file_name = None
204212
except Exception as e:
205-
print("F5TTS: Cannot remove? "+self.wave_file.name)
213+
print("F5TTS: Cannot remove? "+self.wave_file_name)
206214
print(e)
207215

208216
def create(self, sample_audio, sample_text, speech, seed=-1, model="F5"):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-f5-tts"
33
description = "Text to speech with F5-TTS"
4-
version = "1.0.6"
4+
version = "1.0.7"
55
license = {text = "MIT License"}
66

77
[project.urls]

0 commit comments

Comments
 (0)