Sync from GitHub repo
Browse filesThis Space is synced from the GitHub repo: https://github.com/SWivid/F5-TTS. Please submit contributions to the Space there
174 unmodified lines17517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520625 unmodified lines232233234209210211212213214215216217218219220221222223224225226227228235236237238110 unmodified lines3493503513453463473483493503513523533543555 unmodified lines3613623633633643653663679 unmodified lines37737837937938038138238238338438538621 unmodified lines40840941041041141241341412 unmodified lines427428429429430174 unmodified lines)E2TTS_model_cfg = dict(dim=1024, depth=24, heads=16, ff_mult=4)
if model == "F5-TTS":
if ckpt_file == "": repo_name= "F5-TTS" exp_name = "F5TTS_Base" ckpt_step= 1200000 ckpt_file = str(cached_path(f"hf://SWivid/{repo_name}/{exp_name}/model_{ckpt_step}.safetensors"))
ema_model = load_model(DiT, F5TTS_model_cfg, ckpt_file,vocab_file)
elif model == "E2-TTS": if ckpt_file == "": repo_name= "E2-TTS" exp_name = "E2TTS_Base" ckpt_step= 1200000 ckpt_file = str(cached_path(f"hf://SWivid/{repo_name}/{exp_name}/model_{ckpt_step}.safetensors")) ema_model = load_model(UNetT, E2TTS_model_cfg, ckpt_file,vocab_file)
asr_pipe = pipeline( "automatic-speech-recognition", model="openai/whisper-large-v3-turbo", torch_dtype=torch.float16, device=device,)
def chunk_text(text, max_chars=135): """ Splits the input text into chunks, each with a maximum number of characters.25 unmodified lines #if not Path(ckpt_path).exists(): #ckpt_path = str(cached_path(f"hf://SWivid/{repo_name}/{exp_name}/model_{ckpt_step}.safetensors"))
def infer_batch(ref_audio, ref_text, gen_text_batches, model,ckpt_file,file_vocab, remove_silence, cross_fade_duration=0.15): if model == "F5-TTS":
if ckpt_file == "": repo_name= "F5-TTS" exp_name = "F5TTS_Base" ckpt_step= 1200000 ckpt_file = str(cached_path(f"hf://SWivid/{repo_name}/{exp_name}/model_{ckpt_step}.safetensors"))
ema_model = load_model(DiT, F5TTS_model_cfg, ckpt_file,file_vocab)
elif model == "E2-TTS": if ckpt_file == "": repo_name= "E2-TTS" exp_name = "E2TTS_Base" ckpt_step= 1200000 ckpt_file = str(cached_path(f"hf://SWivid/{repo_name}/{exp_name}/model_{ckpt_step}.safetensors")) ema_model = load_model(UNetT, E2TTS_model_cfg, ckpt_file,file_vocab)
def infer_batch(ref_audio, ref_text, gen_text_batches, model, remove_silence, cross_fade_duration=0.15): audio, sr = ref_audio if audio.shape[0] > 1: audio = torch.mean(audio, dim=0, keepdim=True)110 unmodified lines
if not ref_text.strip(): print("No reference text provided, transcribing reference audio...") pipe = pipeline( "automatic-speech-recognition", model="openai/whisper-large-v3-turbo", torch_dtype=torch.float16, device=device, ) ref_text = pipe( ref_text = asr_pipe( ref_audio, chunk_length_s=30, batch_size=128,5 unmodified lines print("Using custom reference text...") return ref_audio, ref_text
def infer(ref_audio, ref_text, gen_text, model,ckpt_file,file_vocab, remove_silence, cross_fade_duration=0.15):def infer(ref_audio, ref_text, gen_text, model, remove_silence, cross_fade_duration=0.15): # Add the functionality to ensure it ends with ". " if not ref_text.endswith(". ") and not ref_text.endswith("。"): if ref_text.endswith("."):9 unmodified lines print(f'gen_text {i}', gen_text) print(f"Generating audio using {model} in {len(gen_text_batches)} batches, loading models...") return infer_batch((audio, sr), ref_text, gen_text_batches, model,ckpt_file,file_vocab, remove_silence, cross_fade_duration) return infer_batch((audio, sr), ref_text, gen_text_batches, model, remove_silence, cross_fade_duration)
def process(ref_audio, ref_text, text_gen, model,ckpt_file,file_vocab, remove_silence):def process(ref_audio, ref_text, text_gen, model, remove_silence): main_voice = {"ref_audio":ref_audio, "ref_text":ref_text} if "voices" not in config: voices = {"main": main_voice}21 unmodified lines ref_audio = voices[voice]['ref_audio'] ref_text = voices[voice]['ref_text'] print(f"Voice: {voice}") audio, spectragram = infer(ref_audio, ref_text, gen_text, model,ckpt_file,file_vocab, remove_silence) audio, spectragram = infer(ref_audio, ref_text, gen_text, model,remove_silence) generated_audio_segments.append(audio)
if generated_audio_segments:12 unmodified lines print(f.name)
process(ref_audio, ref_text, gen_text, model,ckpt_file,vocab_file, remove_silence)process(ref_audio, ref_text, gen_text, model, remove_silence)inference-cli.py+33-32