Spaces:
Runtime error
Runtime error
File size: 1,562 Bytes
6ddd7e4 3f3d89a b5b5082 7890f41 7b8a54e ad0617c 3c03d8e 7b8a54e ad0617c b5b5082 72db052 ad0617c b5b5082 ad0617c b5b5082 7890f41 b5b5082 58068be b5b5082 7b8a54e b5b5082 3f3d89a b5b5082 da528d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import spaces
import os
import sys
sys.path.append("neutts-air")
from neuttsair.neutts import NeuTTSAir
import gradio as gr
SAMPLES_PATH = os.path.join(os.getcwd(), "neutts-air", "samples")
DEFAULT_REF_TEXT = "So I'm live on radio. And I say, well, my dear friend James here clearly, and the whole room just froze. Turns out I'd completely misspoken and mentioned our other friend."
DEFAULT_REF_PATH = os.path.join(SAMPLES_PATH, "dave.wav")
DEFAULT_GEN_TEXT = "My name is Dave, and um, I'm from London."
tts = NeuTTSAir(
backbone_repo="neuphonic/neutts-air",
backbone_device="cuda",
codec_repo="neuphonic/neucodec",
codec_device="cuda"
)
@spaces.GPU()
def infer(ref_text, ref_audio_path, gen_text):
gr.Info("Starting inference request!")
gr.Info("Encoding reference...")
ref_codes = tts.encode_reference(ref_audio_path)
gr.Info(f"Generating audio for input text: {gen_text}")
wav = tts.infer(gen_text, ref_codes, ref_text)
return (24_000, wav)
demo = gr.Interface(
fn=infer,
inputs=[
gr.Textbox(label="Reference Text"),
gr.Audio(type="filepath", label="Reference Audio"),
gr.Textbox(label="Text to Generate"),
],
examples=[
[DEFAULT_REF_TEXT, DEFAULT_REF_PATH, DEFAULT_GEN_TEXT]
],
outputs=gr.Audio(type="numpy", label="Generated Speech"),
title="NeuTTS-Air☁️",
description="Upload a reference audio sample, provide the reference text, and enter new text to synthesize."
)
if __name__ == "__main__":
demo.launch(allowed_paths=[SAMPLES_PATH]) |