kevinwang676 commited on
Commit
33efd3a
·
verified ·
1 Parent(s): 2e22474

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError
2
+
3
+ def generate_voice(text, voice_name):
4
+ try:
5
+ audio = generate(
6
+ text[:5000], # Limit to 250 characters
7
+ voice=voice_name,
8
+ model="eleven_multilingual_v2"
9
+ )
10
+ with open("output" + ".mp3", mode='wb') as f:
11
+ f.write(audio)
12
+ return "output.mp3"
13
+
14
+ except UnauthenticatedRateLimitError as e:
15
+ raise gr.Error("Thanks for trying out ElevenLabs TTS! You've reached the free tier limit. Please provide an API key to continue.")
16
+ except Exception as e:
17
+ raise gr.Error(e)
18
+
19
+ all_voices = voices()
20
+
21
+ with gr.Blocks() as app:
22
+ gr.Markdown("# <center>🌊💕🎶 11Labs TTS</center>")
23
+ with gr.Column():
24
+ with gr.Row():
25
+ inp1 = gr.Textbox(label="需要语音合成的文本")
26
+ inp2 = gr.Dropdown(choices=[ voice.name for voice in all_voices ], label='请选择一个说话人音色', info="试听音色链接:https://huggingface.co/spaces/elevenlabs/tts", value='Rachel')
27
+ btn = gr.Button("一键AI配音")
28
+ with gr.Row():
29
+ out1 = gr.Audio(label="为您合成的音频文件", type="filepath")
30
+ btn.click(generate_voice, [inp1, inp2], [out1])
31
+
32
+ app.launch(share=False, show_error=True)
33
+
34
+