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 lines17517617717817918025 unmodified lines206207208209210211212213214215216217218219220221222223224225226227228229230231110 unmodified lines3423433443453463473483493503513523533545 unmodified lines3603613623633643653669 unmodified lines37637737837938038138238338438521 unmodified lines40740840941041141241312 unmodified lines426427428429174 unmodified lines)E2TTS_model_cfg = dict(dim=1024, depth=24, heads=16, ff_mult=4)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= 1200000ckpt_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= 1200000ckpt_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)audio, sr = ref_audioif audio.shape[0] > 1:audio = torch.mean(audio, dim=0, keepdim=True)110 unmodified linesif 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_audio,chunk_length_s=30,batch_size=128,5 unmodified linesprint("Using custom reference text...")return ref_audio, ref_textdef infer(ref_audio, ref_text, gen_text, model,ckpt_file,file_vocab, 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 linesprint(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)def process(ref_audio, ref_text, text_gen, model,ckpt_file,file_vocab, remove_silence):main_voice = {"ref_audio":ref_audio, "ref_text":ref_text}if "voices" not in config:voices = {"main": main_voice}21 unmodified linesref_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)generated_audio_segments.append(audio)if generated_audio_segments:12 unmodified linesprint(f.name)process(ref_audio, ref_text, gen_text, model,ckpt_file,vocab_file, remove_silence)174 unmodified lines17517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520625 unmodified lines232233234235236237238110 unmodified lines3493503513523533543555 unmodified lines3613623633643653663679 unmodified lines37737837938038138238338438538621 unmodified lines40840941041141241341412 unmodified lines427428429430174 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= 1200000ckpt_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= 1200000ckpt_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, remove_silence, cross_fade_duration=0.15):audio, sr = ref_audioif audio.shape[0] > 1:audio = torch.mean(audio, dim=0, keepdim=True)110 unmodified linesif not ref_text.strip():print("No reference text provided, transcribing reference audio...")ref_text = asr_pipe(ref_audio,chunk_length_s=30,batch_size=128,5 unmodified linesprint("Using custom reference text...")return ref_audio, ref_textdef 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 linesprint(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, remove_silence, cross_fade_duration)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 linesref_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,remove_silence)generated_audio_segments.append(audio)if generated_audio_segments:12 unmodified linesprint(f.name)process(ref_audio, ref_text, gen_text, model, remove_silence)
inference-cli.py+33-32