kevinwang676 commited on
Commit
a53c904
·
verified ·
1 Parent(s): f6ef3c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -1,7 +1,9 @@
 
1
  import gradio as gr
2
  from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError
3
 
4
- def generate_voice(text, voice_name):
 
5
  try:
6
  audio = generate(
7
  text[:5000], # Limit to 250 characters
@@ -23,12 +25,13 @@ with gr.Blocks() as app:
23
  gr.Markdown("# <center>🌊💕🎶 11Labs TTS</center>")
24
  with gr.Column():
25
  with gr.Row():
 
26
  inp1 = gr.Textbox(label="需要语音合成的文本")
27
  inp2 = gr.Dropdown(choices=[ voice.name for voice in all_voices ], label='请选择一个说话人音色', info="试听音色链接:https://huggingface.co/spaces/elevenlabs/tts", value='Rachel')
28
- btn = gr.Button("一键AI配音")
29
  with gr.Row():
30
  out1 = gr.Audio(label="为您合成的音频文件", type="filepath")
31
- btn.click(generate_voice, [inp1, inp2], [out1])
32
 
33
  app.launch(share=False, show_error=True)
34
 
 
1
+ import os
2
  import gradio as gr
3
  from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError
4
 
5
+ def generate_voice(api_key, text, voice_name):
6
+ os.environ["ELEVEN_API_KEY"] = api_key
7
  try:
8
  audio = generate(
9
  text[:5000], # Limit to 250 characters
 
25
  gr.Markdown("# <center>🌊💕🎶 11Labs TTS</center>")
26
  with gr.Column():
27
  with gr.Row():
28
+ inp0 = gr.Textbox(type='password', label='请输入您的11Labs API Key')
29
  inp1 = gr.Textbox(label="需要语音合成的文本")
30
  inp2 = gr.Dropdown(choices=[ voice.name for voice in all_voices ], label='请选择一个说话人音色', info="试听音色链接:https://huggingface.co/spaces/elevenlabs/tts", value='Rachel')
31
+ btn = gr.Button("一键AI配音", variant="primary")
32
  with gr.Row():
33
  out1 = gr.Audio(label="为您合成的音频文件", type="filepath")
34
+ btn.click(generate_voice, [inp0, inp1, inp2], [out1])
35
 
36
  app.launch(share=False, show_error=True)
37