File size: 1,162 Bytes
c962c9a
 
 
 
b04ebb9
 
c962c9a
582cf5b
b04ebb9
 
 
 
 
4c5bfad
b04ebb9
 
 
 
c962c9a
 
b04ebb9
4c5bfad
b04ebb9
c962c9a
 
 
 
a25c8ec
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
import gradio as gr
from TTS.api import TTS

# Init TTS
tts = TTS(TTS.list_models()[0], progress_bar=False, gpu=False)  # 多语言
zh_tts = TTS("tts_models/zh-CN/baker/tacotron2-DDC-GST", progress_bar=False, gpu=False)

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

inputs = [gr.Textbox(label="Input the text", value="", max_lines=3),
          gr.Audio(lable="Input your voice here", source="microphone", type="filepath"), 
            gr.Radio(label="Language", choices=["en", "中文", "fr-fr"], value="en")]
outputs = gr.Audio(label="Output")

demo = gr.Interface(fn=text_to_speech, inputs=inputs, outputs=outputs)

demo.launch()