Spaces:
Runtime error
Runtime error
kevinwang676
commited on
Commit
•
ad81144
1
Parent(s):
2a71b56
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,11 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import tempfile
|
4 |
from openai import OpenAI
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# Set an environment variable for key
|
7 |
#os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY')
|
@@ -23,6 +28,18 @@ enhance_model = SpectralMaskEnhancement.from_hparams(
|
|
23 |
|
24 |
knn_vc = torch.hub.load('bshall/knn-vc', 'knn_vc', prematched=True, trust_repo=True, pretrained=True, device='cpu')
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def voice_change(audio_in, audio_ref):
|
28 |
samplerate1, data1 = wavfile.read(audio_in)
|
@@ -76,25 +93,40 @@ with app:
|
|
76 |
gr.Markdown("# <center>🌟 - OpenAI TTS + AI变声</center>")
|
77 |
gr.Markdown("### <center>🎶 地表最强文本转语音模型 + 3秒实时AI变声,支持中文!Powered by [OpenAI TTS](https://platform.openai.com/docs/guides/text-to-speech) and [KNN-VC](https://github.com/bshall/knn-vc) </center>")
|
78 |
gr.Markdown("### <center>🌊 更多精彩应用,敬请关注[滔滔AI](http://www.talktalkai.com);滔滔AI,为爱滔滔!💕</center>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='请在此填写您的OpenAI API Key')
|
82 |
-
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='请选择模型(tts-1推理更快,tts-1-hd音质更好)', value='tts-1')
|
83 |
-
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='请选择一个说话人', value='alloy')
|
84 |
-
with gr.Row():
|
85 |
-
with gr.Column():
|
86 |
-
inp_text = gr.Textbox(label="请填写您想生成的文本(中英文皆可)", placeholder="想说却还没说的 还很多 攒着是因为想写成歌", lines=5)
|
87 |
-
btn_text = gr.Button("一键开启真实拟声吧", variant="primary")
|
88 |
-
|
89 |
-
with gr.Column():
|
90 |
-
inp1 = gr.Audio(type="filepath", label="OpenAI TTS真实拟声", interactive=False)
|
91 |
-
inp2 = gr.Audio(type="filepath", label="请上传AI变声的参照音频(决定变声后的语音音色)")
|
92 |
-
btn1 = gr.Button("一键开启AI变声吧", variant="primary")
|
93 |
-
with gr.Column():
|
94 |
-
out1 = gr.Audio(type="filepath", label="AI变声后的专属音频")
|
95 |
-
btn_text.click(tts, [inp_text, model, voice, api_key], inp1)
|
96 |
-
btn1.click(voice_change, [inp1, inp2], out1)
|
97 |
-
|
98 |
gr.Markdown("### <center>注意❗:请不要生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及个人娱乐使用。Get your OpenAI API Key [here](https://platform.openai.com/api-keys).</center>")
|
99 |
gr.HTML('''
|
100 |
<div class="footer">
|
|
|
2 |
import os
|
3 |
import tempfile
|
4 |
from openai import OpenAI
|
5 |
+
from tts_voice import tts_order_voice
|
6 |
+
import edge_tts
|
7 |
+
import tempfile
|
8 |
+
import anyio
|
9 |
+
|
10 |
|
11 |
# Set an environment variable for key
|
12 |
#os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY')
|
|
|
28 |
|
29 |
knn_vc = torch.hub.load('bshall/knn-vc', 'knn_vc', prematched=True, trust_repo=True, pretrained=True, device='cpu')
|
30 |
|
31 |
+
language_dict = tts_order_voice
|
32 |
+
|
33 |
+
async def text_to_speech_edge(text, language_code):
|
34 |
+
voice = language_dict[language_code]
|
35 |
+
communicate = edge_tts.Communicate(text, voice)
|
36 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
37 |
+
tmp_path = tmp_file.name
|
38 |
+
|
39 |
+
await communicate.save(tmp_path)
|
40 |
+
|
41 |
+
return "语音合成完成:{}".format(text), tmp_path
|
42 |
+
|
43 |
|
44 |
def voice_change(audio_in, audio_ref):
|
45 |
samplerate1, data1 = wavfile.read(audio_in)
|
|
|
93 |
gr.Markdown("# <center>🌟 - OpenAI TTS + AI变声</center>")
|
94 |
gr.Markdown("### <center>🎶 地表最强文本转语音模型 + 3秒实时AI变声,支持中文!Powered by [OpenAI TTS](https://platform.openai.com/docs/guides/text-to-speech) and [KNN-VC](https://github.com/bshall/knn-vc) </center>")
|
95 |
gr.Markdown("### <center>🌊 更多精彩应用,敬请关注[滔滔AI](http://www.talktalkai.com);滔滔AI,为爱滔滔!💕</center>")
|
96 |
+
with gr.Tab("🤗 OpenAI TTS")
|
97 |
+
with gr.Row(variant='panel'):
|
98 |
+
api_key = gr.Textbox(type='password', label='OpenAI API Key', placeholder='请在此填写您的OpenAI API Key')
|
99 |
+
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='请选择模型(tts-1推理更快,tts-1-hd音质更好)', value='tts-1')
|
100 |
+
voice = gr.Dropdown(choices=['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'], label='请选择一个说话人', value='alloy')
|
101 |
+
with gr.Row():
|
102 |
+
with gr.Column():
|
103 |
+
inp_text = gr.Textbox(label="请填写您想生成的文本(中英文皆可)", placeholder="想说却还没说的 还很多 攒着是因为想写成歌", lines=5)
|
104 |
+
btn_text = gr.Button("一键开启真实拟声吧", variant="primary")
|
105 |
+
|
106 |
+
with gr.Column():
|
107 |
+
inp1 = gr.Audio(type="filepath", label="OpenAI TTS真实拟声", interactive=False)
|
108 |
+
inp2 = gr.Audio(type="filepath", label="请上传AI变声的参照音频(决定变声后的语音音色)")
|
109 |
+
btn1 = gr.Button("一键开启AI变声吧", variant="primary")
|
110 |
+
with gr.Column():
|
111 |
+
out1 = gr.Audio(type="filepath", label="AI变声后的专属音频")
|
112 |
+
btn_text.click(tts, [inp_text, model, voice, api_key], inp1)
|
113 |
+
btn1.click(voice_change, [inp1, inp2], out1)
|
114 |
+
with gr.Tab("⚡ Edge TTS"):
|
115 |
+
with gr.Row():
|
116 |
+
input_text = gr.inputs.Textbox(lines=5, placeholder="想说却还没说的 还很多 攒着是因为想写成歌", label="请填写您想生成的文本(中英文皆可)")
|
117 |
+
default_language = list(language_dict.keys())[0]
|
118 |
+
language = gr.inputs.Dropdown(choices=list(language_dict.keys()), default=default_language, label="请选择文本对应的语言")
|
119 |
+
btn_edge = gr.Button("一键开启真实拟声吧", variant="primary")
|
120 |
+
output_text = gr.outputs.Textbox(label="输出文本", visible=False)
|
121 |
+
output_audio = gr.outputs.Audio(type="filepath", label="Edge TTS真实拟声")
|
122 |
+
|
123 |
+
with gr.Row():
|
124 |
+
inp_vc = gr.Audio(type="filepath", label="请上传AI变声的参照音频(决定变声后的语音音色)")
|
125 |
+
btn_vc = gr.Button("一键开启AI变声吧", variant="primary")
|
126 |
+
out_vc = gr.Audio(type="filepath", label="AI变声后的专属音频")
|
127 |
+
btn_vc.click(voice_change, [output_audio, inp_vc], out_vc)
|
128 |
|
129 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
gr.Markdown("### <center>注意❗:请不要生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及个人娱乐使用。Get your OpenAI API Key [here](https://platform.openai.com/api-keys).</center>")
|
131 |
gr.HTML('''
|
132 |
<div class="footer">
|