tortoisse-tts / app.py
osanseviero's picture
osanseviero HF staff
Update app.py
8622a01
raw
history blame
No virus
2.27 kB
import IPython
import sys
import subprocess
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "--force-reinstall", "git+https://github.com/osanseviero/tortoise-tts.git"])
# entmax could not be installed at same time as torch
subprocess.check_call([sys.executable, "-m", "pip", "install", "entmax"])
from tortoise_tts.api import TextToSpeech
from tortoise_tts.utils.audio import load_audio, get_voices
import torch
import torchaudio
import gradio as gr
device = "cuda" if torch.cuda.is_available() else "cpu"
# This will download all the models used by Tortoise from the HF hub
tts = TextToSpeech(device="cuda")
voices = [
"angie",
"daniel",
"deniro",
"emma",
"freeman",
"geralt",
"halle",
"jlaw",
"lj",
"snakes",
"William",
]
voice_paths = get_voices()
print(voice_paths)
preset = "fast"
def inference(text, voice):
text = text[:256]
cond_paths = voice_paths[voice]
conds = []
print(voice_paths, voice, cond_paths)
for cond_path in cond_paths:
c = load_audio(cond_path, 22050)
conds.append(c)
print(text, conds, preset)
gen = tts.tts_with_preset(text, conds, preset)
print("gen")
torchaudio.save('generated.wav', gen.squeeze(0).cpu(), 24000)
return "generated.wav"
text = "Joining two modalities results in a surprising increase in generalization! What would happen if we combined them all?"
examples = [
[text, "angie"],
[text, "emma"],
["how are you doing this day", "freeman"]
]
block = gr.Blocks()
with block:
gr.Markdown("# TorToiSe")
gr.Markdown("A multi-voice TTS system trained with an emphasis on quality")
with gr.Tabs():
with gr.TabItem("Pre-recorded voices"):
iface = gr.Interface(
inference,
inputs=[
gr.inputs.Textbox(type="str", default=text, label="Text", lines=3),
gr.inputs.Dropdown(voices),
],
outputs="audio",
enable_queue=True,
examples=examples,
)
gr.Markdown("This demo shows the ultra fast option in the TorToiSe system. For more info check the <a href='https://github.com/neonbjb/tortoise-tts' target='_blank'>Repository</a>.",)
block.launch()
iface.launch(cache_examples=True)