File size: 2,164 Bytes
d7346fe
 
ad1f4e3
74ac3a9
 
d7346fe
74ac3a9
 
 
 
 
 
d7346fe
74ac3a9
 
d7346fe
74ac3a9
d7346fe
74ac3a9
d7346fe
 
 
 
 
93c448b
 
74ac3a9
 
d7346fe
 
74ac3a9
 
 
 
93c448b
 
74ac3a9
d7346fe
 
74ac3a9
 
 
 
d7346fe
 
 
74ac3a9
 
 
d7346fe
d004af0
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
import gradio as gr
from TTS.api import TTS

# Initialize TTS models
tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False, gpu=False)

def text_to_speech(text: str, speaker_wav, speaker_wav_file, language: str):
    if speaker_wav_file and not speaker_wav:
        speaker_wav = speaker_wav_file
    file_path = "output.wav"
    if speaker_wav is not None:
        tts.tts_to_file(text, speaker_wav=speaker_wav, language=language, file_path=file_path)
    else:
        tts.tts_to_file(text, speaker=tts.speakers[0], language=language, file_path=file_path)
    return file_path

title = "Prateek's Voice Cloning Demo"

def toggle(choice):
    if choice == "mic":
        return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
    else:
        return gr.update(visible=False, value=None), gr.update(visible=True, value=None)



with gr.Blocks() as demo:
    gr.Markdown("# 🎙️ Prateek's Voice Cloning Demo")
    with gr.Row():
        with gr.Column():
            text_input = gr.Textbox(label="Enter the text you want to convert to speech", value="", max_lines=3)
            lan_input = gr.Radio(label="Language", choices=["en"], value="en", visible=False)
            radio = gr.Radio(["Record your voice", "Upload an audio file"], value="mic",
                             label="How would you like to provide your voice sample?")
            audio_input_mic = gr.Audio(label="Record your voice", sources=["microphone"], type="filepath", visible=True)

            audio_input_file = gr.Audio(label="Upload an audio file", type="filepath", visible=False)

            with gr.Row():
                with gr.Column():
                    btn_clear = gr.Button("Clear")
                with gr.Column():
                    btn = gr.Button("Generate Speech", variant="primary")
        with gr.Column():
            audio_output = gr.Audio(label="Generated Speech")

    btn.click(text_to_speech, inputs=[text_input, audio_input_mic,
              audio_input_file, lan_input], outputs=audio_output)
    radio.change(toggle, radio, [audio_input_mic, audio_input_file])

demo.launch(share=True)