Spaces:
Runtime error
Runtime error
File size: 1,337 Bytes
33efd3a |
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 29 30 31 32 33 34 35 |
from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError
def generate_voice(text, voice_name):
try:
audio = generate(
text[:5000], # Limit to 250 characters
voice=voice_name,
model="eleven_multilingual_v2"
)
with open("output" + ".mp3", mode='wb') as f:
f.write(audio)
return "output.mp3"
except UnauthenticatedRateLimitError as e:
raise gr.Error("Thanks for trying out ElevenLabs TTS! You've reached the free tier limit. Please provide an API key to continue.")
except Exception as e:
raise gr.Error(e)
all_voices = voices()
with gr.Blocks() as app:
gr.Markdown("# <center>🌊💕🎶 11Labs TTS</center>")
with gr.Column():
with gr.Row():
inp1 = gr.Textbox(label="需要语音合成的文本")
inp2 = gr.Dropdown(choices=[ voice.name for voice in all_voices ], label='请选择一个说话人音色', info="试听音色链接:https://huggingface.co/spaces/elevenlabs/tts", value='Rachel')
btn = gr.Button("一键AI配音")
with gr.Row():
out1 = gr.Audio(label="为您合成的音频文件", type="filepath")
btn.click(generate_voice, [inp1, inp2], [out1])
app.launch(share=False, show_error=True)
|