Spaces:
Paused
Paused
zxsipola123456
commited on
Commit
•
06cc3bf
1
Parent(s):
199627b
Update app.py
Browse files
app.py
CHANGED
@@ -69,13 +69,28 @@ def tts(text, model, voice, api_key):
|
|
69 |
|
70 |
return temp_file.name
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
# Gradio 前端设计
|
73 |
app = gr.Blocks()
|
74 |
|
75 |
with app:
|
76 |
gr.Markdown("# <center>OpenAI TTS + 3秒实时AI变声+需要使用中转key</center>")
|
77 |
gr.Markdown("### <center>中转key购买地址[here](https://buy.sipola.cn),ai文案生成可使用中转key,请访问 [here](https://ai.sipola.cn)</center>")
|
78 |
-
with gr.Tab("TTS"):
|
79 |
with gr.Row(variant='panel'):
|
80 |
api_key = gr.Textbox(type='password', label='API Key', placeholder='请在此填写您的中转API Key')
|
81 |
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='请选择模型(tts-1推理更快,tts-1-hd音质更好)', value='tts-1')
|
@@ -83,51 +98,40 @@ with app:
|
|
83 |
with gr.Row():
|
84 |
with gr.Column():
|
85 |
inp_text = gr.Textbox(label="请填写您想生成的文本中英文皆可", placeholder="请输入ai生成的文案,不要超过300字,最好200字左右", lines=5)
|
86 |
-
btn_text = gr.Button("
|
87 |
with gr.Column():
|
88 |
inp1 = gr.Audio(type="filepath", label="OpenAI TTS真实拟声", interactive=False)
|
89 |
-
inp2 = gr.Audio(type="filepath", label="
|
90 |
-
btn1 = gr.Button("
|
91 |
with gr.Column():
|
92 |
out1 = gr.Audio(type="filepath", label="AI变声后的专属音频")
|
93 |
btn_text.click(tts, [inp_text, model, voice, api_key], inp1)
|
94 |
btn1.click(voice_change, [inp1, inp2], out1)
|
95 |
-
|
96 |
-
|
97 |
-
# input_text = gr.Textbox(lines=5, placeholder="请输入ai生成的文案,不要超过300字,最好200字左右", label="请填写您想生成的文本中英文皆可")
|
98 |
-
# default_language = list(language_dict.keys())[15]
|
99 |
-
# language = gr.Dropdown(choices=list(language_dict.keys()), value=default_language, label="请选择文本对应的语言")
|
100 |
-
# btn_edge = gr.Button("一键开启真实拟声吧", variant="primary")
|
101 |
-
# output_text = gr.Textbox(label="输出文本", visible=False)
|
102 |
-
# output_audio = gr.Audio(type="filepath", label="Edge TTS真实拟声")
|
103 |
-
|
104 |
-
# with gr.Row():
|
105 |
-
# inp_vc = gr.Audio(type="filepath", label="请上传AI变声的参照音频决定变声后的语音音色")
|
106 |
-
# btn_vc = gr.Button("一键开启AI变声吧", variant="primary")
|
107 |
-
# out_vc = gr.Audio(type="filepath", label="AI变声后的专属音频")
|
108 |
-
|
109 |
-
# btn_edge.click(lambda text, lang: anyio.run(text_to_speech_edge, text, lang), [input_text, language], [output_text, output_audio])
|
110 |
-
# btn_vc.click(voice_change, [output_audio, inp_vc], out_vc)
|
111 |
-
with gr.Tab("Edge TTS"):
|
112 |
with gr.Row():
|
113 |
with gr.Column():
|
114 |
input_text = gr.Textbox(label="请填写您想生成的文本中英文皆可",placeholder="请输入ai生成的文案,不要超过300字,最好200字左右",lines=5)
|
115 |
-
btn_edge = gr.Button("
|
116 |
with gr.Column():
|
117 |
default_language = list(language_dict.keys())[15]
|
118 |
language = gr.Dropdown(choices=list(language_dict.keys()), value=default_language, label="请选择文本对应的语言")
|
119 |
-
output_audio = gr.Audio(type="filepath", label="TTS真实拟声", interactive=False)
|
120 |
output_text = gr.Textbox(label="输出文本", visible=False)
|
121 |
with gr.Row():
|
122 |
with gr.Column():
|
123 |
-
inp_vc = gr.Audio(type="filepath", label="
|
124 |
-
btn_vc = gr.Button("
|
125 |
with gr.Column():
|
126 |
out_vc = gr.Audio(type="filepath", label="AI变声后的专属音频")
|
127 |
btn_edge.click(lambda text, lang: anyio.run(text_to_speech_edge, text, lang), [input_text, language], [output_text, output_audio])
|
128 |
btn_vc.click(voice_change, [output_audio, inp_vc], out_vc)
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
131 |
gr.HTML('''
|
132 |
<div class="footer">
|
133 |
<center><p>Power by sipola </p></center>
|
|
|
69 |
|
70 |
return temp_file.name
|
71 |
|
72 |
+
def validate_api_key(api_key):
|
73 |
+
try:
|
74 |
+
client = OpenAI(api_key=api_key, base_url='https://lmzh.top/v1')
|
75 |
+
# 测试调用一个简单的API来验证Key
|
76 |
+
response = client.models.list()
|
77 |
+
return True
|
78 |
+
except Exception:
|
79 |
+
return False
|
80 |
+
|
81 |
+
|
82 |
+
# 更新Edge TTS标签页状态的函数
|
83 |
+
def update_edge_tts_tab(api_key):
|
84 |
+
is_valid = validate_api_key(api_key)
|
85 |
+
return gr.update(interactive=is_valid)
|
86 |
+
|
87 |
# Gradio 前端设计
|
88 |
app = gr.Blocks()
|
89 |
|
90 |
with app:
|
91 |
gr.Markdown("# <center>OpenAI TTS + 3秒实时AI变声+需要使用中转key</center>")
|
92 |
gr.Markdown("### <center>中转key购买地址[here](https://buy.sipola.cn),ai文案生成可使用中转key,请访问 [here](https://ai.sipola.cn)</center>")
|
93 |
+
with gr.Tab("Openai-TTS"):
|
94 |
with gr.Row(variant='panel'):
|
95 |
api_key = gr.Textbox(type='password', label='API Key', placeholder='请在此填写您的中转API Key')
|
96 |
model = gr.Dropdown(choices=['tts-1','tts-1-hd'], label='请选择模型(tts-1推理更快,tts-1-hd音质更好)', value='tts-1')
|
|
|
98 |
with gr.Row():
|
99 |
with gr.Column():
|
100 |
inp_text = gr.Textbox(label="请填写您想生成的文本中英文皆可", placeholder="请输入ai生成的文案,不要超过300字,最好200字左右", lines=5)
|
101 |
+
btn_text = gr.Button("一键生成音频", variant="primary")
|
102 |
with gr.Column():
|
103 |
inp1 = gr.Audio(type="filepath", label="OpenAI TTS真实拟声", interactive=False)
|
104 |
+
inp2 = gr.Audio(type="filepath", label="请上传同文案相同参照音频,可自己读取同文案录音")
|
105 |
+
btn1 = gr.Button("一键AI变声合成", variant="primary")
|
106 |
with gr.Column():
|
107 |
out1 = gr.Audio(type="filepath", label="AI变声后的专属音频")
|
108 |
btn_text.click(tts, [inp_text, model, voice, api_key], inp1)
|
109 |
btn1.click(voice_change, [inp1, inp2], out1)
|
110 |
+
|
111 |
+
with gr.Tab("Fast TTS"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
with gr.Row():
|
113 |
with gr.Column():
|
114 |
input_text = gr.Textbox(label="请填写您想生成的文本中英文皆可",placeholder="请输入ai生成的文案,不要超过300字,最好200字左右",lines=5)
|
115 |
+
btn_edge = gr.Button("一键生成音频", variant="primary")
|
116 |
with gr.Column():
|
117 |
default_language = list(language_dict.keys())[15]
|
118 |
language = gr.Dropdown(choices=list(language_dict.keys()), value=default_language, label="请选择文本对应的语言")
|
119 |
+
output_audio = gr.Audio(type="filepath", label="TTS真实拟声", interactive=False, show_download_button=False)
|
120 |
output_text = gr.Textbox(label="输出文本", visible=False)
|
121 |
with gr.Row():
|
122 |
with gr.Column():
|
123 |
+
inp_vc = gr.Audio(type="filepath", label="请上传和文案相同参照音频,可自己读取文案录音或者用Openai-TTS同文案生成的��频")
|
124 |
+
btn_vc = gr.Button("一键AI变声合成", variant="primary")
|
125 |
with gr.Column():
|
126 |
out_vc = gr.Audio(type="filepath", label="AI变声后的专属音频")
|
127 |
btn_edge.click(lambda text, lang: anyio.run(text_to_speech_edge, text, lang), [input_text, language], [output_text, output_audio])
|
128 |
btn_vc.click(voice_change, [output_audio, inp_vc], out_vc)
|
129 |
+
# 监听API Key输入框的变化并更新Edge TTS标签页的状态
|
130 |
+
api_key.change(
|
131 |
+
update_edge_tts_tab,
|
132 |
+
inputs=[api_key],
|
133 |
+
outputs=[edge_tts_tab]
|
134 |
+
)
|
135 |
gr.HTML('''
|
136 |
<div class="footer">
|
137 |
<center><p>Power by sipola </p></center>
|