Skip to content

Commit

Permalink
add to suport audio name , audio.wav , full audio path
Browse files Browse the repository at this point in the history
  • Loading branch information
lpscr committed Oct 30, 2024
1 parent b7a1746 commit e941976
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/f5_tts/train/finetune_gradio.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,22 @@ def format_seconds_to_hms(seconds):
return "{:02d}:{:02d}:{:02d}".format(hours, minutes, int(seconds))


def get_correct_audio_path(audio_input, base_path="wavs"):
# Case 1: If it's a full path, use it directly
if os.path.isabs(audio_input):
file_audio = audio_input

# Case 2: If it has .wav but is not a full path
elif audio_input.endswith(".wav") and not os.path.isabs(audio_input):
file_audio = os.path.join(base_path, audio_input)

# Case 3: If only the name (no .wav and not a full path)
elif not audio_input.endswith(".wav") and not os.path.isabs(audio_input):
file_audio = os.path.join(base_path, audio_input + ".wav")

return file_audio


def create_metadata(name_project, ch_tokenizer, progress=gr.Progress()):
path_project = os.path.join(path_data, name_project)
path_project_wavs = os.path.join(path_project, "wavs")
Expand Down Expand Up @@ -764,7 +780,7 @@ def create_metadata(name_project, ch_tokenizer, progress=gr.Progress()):
continue
name_audio, text = sp_line[:2]

file_audio = os.path.join(path_project_wavs, name_audio + ".wav")
file_audio = get_correct_audio_path(name_audio, path_project_wavs)

if not os.path.isfile(file_audio):
error_files.append([file_audio, "error path"])
Expand Down

0 comments on commit e941976

Please sign in to comment.