File size: 1,419 Bytes
4110922
d33f32d
 
4110922
6afc51e
4110922
 
 
 
4af5dfa
4110922
4af5dfa
 
 
 
 
 
4110922
0a5aead
 
45fac78
0a5aead
 
45fac78
 
0a5aead
 
 
 
 
 
4af5dfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45fac78
 
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
import torch
from TTS.api import TTS
import gradio as gr
import os
import spaces



# Agree to Terms of service
# os.environ["COQUI_TOS_AGREED"] = "1"

def init_TTS():
    # Get device
    device = "cuda" if torch.cuda.is_available() else "cpu"
    # Initialize the TTS model
    tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
    return tts


@spaces.GPU
def generate_speech(text):
    # Generate speech using the provided text, speaker voice, and language
    file_path = "output.wav"
    speaker_wav = "/content/speaker.wav"
    language = "en"
    tts.tts_to_file(text=text,
                    file_path=file_path,
                    speaker_wav=speaker_wav,
                    language=language)
    return file_path



def main():

    # call init
    tts = init_TTS()
    
    # Create the Gradio interface
    interface = gr.Interface(
        fn=generate_speech,
        inputs=[
            gr.Textbox(label="Enter your text")
            #gr.Textbox(label="Path to target speaker WAV file", value="/content/speaker.wav")
            #gr.Dropdown(label="Language", choices=["en"], value="en")
        ],
        outputs="audio",
        title="Voice Synthesis with Coqui-XTTS",
        description="Synthesize speech using predefined target voice and language."
    )

    # Launch the interface
    interface.launch()
    return 0

if __name__ == "__main__":
    main()