File size: 1,803 Bytes
fca9b48
 
 
 
 
 
 
 
 
 
 
d27bf25
 
8c0f847
fca9b48
 
 
 
f43268d
fca9b48
 
f43268d
fca9b48
f43268d
fca9b48
f43268d
fca9b48
 
 
 
840a99d
fca9b48
 
 
1370e35
8c2cbbe
840a99d
 
 
fca9b48
a3eadde
30f76f3
 
fca9b48
 
f43268d
fca9b48
f88a2bc
fca9b48
513ec33
fca9b48
320bb9e
840a99d
f43268d
fca9b48
 
 
 
f43268d
fca9b48
707f4d4
 
840a99d
fca9b48
840a99d
fca9b48
 
 
 
 
 
 
 
 
f43268d
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import torch
import gradio as gr
import torchaudio
import time
from datetime import datetime
from tortoise.api import TextToSpeech
from tortoise.utils.text import split_and_recombine_text
from tortoise.utils.audio import load_audio, load_voice, load_voices

VOICE_OPTIONS = [
    "kasuri",
    "shanuka",
    "indian_f_1",
]

def inference(
    text,
    voice
):
    if text is None or text.strip() == "":
        raise gr.Error("Please provide text.")

    texts = split_and_recombine_text(text)

    voice_samples, conditioning_latents = load_voice(voice)

    start_time = time.time()

    for j, text in enumerate(texts):
        for audio_frame in tts.tts_with_preset(
            text,
            voice_samples=voice_samples,
            conditioning_latents=conditioning_latents,
            preset="ultra_fast",
            k=1
        ):
            yield (24000, audio_frame.cpu().detach().numpy())

def main():
    title = "Tortoise TTS"
    description = """
    """
    text = gr.Textbox(
        lines=4,
        label="Text:",
    )

    voice = gr.Dropdown(
        VOICE_OPTIONS, value="kasuri", label="Select voice:", type="value"
    )

    output_audio = gr.Audio(label="streaming audio:", streaming=True, autoplay=True)

    interface = gr.Interface(
        fn=inference,
        inputs=[
            text,
            voice
        ],
        title=title,
        description=description,
        outputs=[output_audio],
    )
    interface.queue().launch()

if __name__ == "__main__":
    tts = TextToSpeech(kv_cache=True, use_deepspeed=True, half=True)

    with open("Tortoise_TTS_Runs_Scripts.log", "a") as f:
        f.write(
            f"\n\n-------------------------Tortoise TTS Scripts Logs, {datetime.now()}-------------------------\n"
        )

    main()