flavioschneider commited on
Commit
3b1f0f3
1 Parent(s): fecf0c5

feat: add gradio demo

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +89 -0
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Tts
3
  emoji: 🌍
4
  colorFrom: yellow
5
  colorTo: pink
 
1
  ---
2
+ title: ElevenLabs TTS
3
  emoji: 🌍
4
  colorFrom: yellow
5
  colorTo: pink
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import gradio as gr
3
+ import numpy as np
4
+ from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError
5
+
6
+ def generate_voice(text, voice_name, model_name, api_key):
7
+ try:
8
+ audio = generate(text, voice=voice_name, model=model_name, api_key=api_key)
9
+ except UnauthenticatedRateLimitError as e:
10
+ raise gr.Error("Thanks for trying out ElevenLabs TTS! You've reached the free tier limit. Please provide an API key to continue.")
11
+ except Exception as e:
12
+ raise gr.Error(e)
13
+ return (44100, np.frombuffer(audio, dtype=np.int16))
14
+
15
+ badges = """
16
+ <div style="display: flex">
17
+ <span style="margin-right: 5px">
18
+
19
+ [ ![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white) ](https://github.com/elevenlabs-python)
20
+
21
+ </span>
22
+ <span>
23
+
24
+ [ ![](https://dcbadge.vercel.app/api/server/elevenlabs) ](https://discord.gg/elevenlabs)
25
+
26
+ </span>
27
+ </div>
28
+ """
29
+
30
+ description = """
31
+ A demo of the world's most advanced TTS systems, made by [ElevenLabs](https://elevenlabs.io). Eleven Monolingual is designed to generate highly realistic voices in English, where Eleven Multilingual is a single model supporting multiple languages including English, German, Polish, Spanish, Italian, French, Portuguese, and Hindi.
32
+ """
33
+
34
+ with gr.Blocks() as block:
35
+ gr.Markdown("# ElevenLabs TTS")
36
+ gr.Markdown(badges)
37
+ gr.Markdown(description)
38
+
39
+ input_text = gr.Textbox(
40
+ label="Input Text",
41
+ lines=2,
42
+ value="Hi! I'm Eleven, the worlds most advanced TTS system.",
43
+ elem_id="input_text"
44
+ )
45
+
46
+ all_voices = voices()
47
+ input_voice = gr.Dropdown(
48
+ [ voice.name for voice in all_voices ],
49
+ value=random.choice(all_voices).name,
50
+ label="Voice",
51
+ elem_id="input_voice"
52
+ )
53
+
54
+ input_model = gr.Radio(
55
+ ["eleven_monolingual_v1", "eleven_multilingual_v1"],
56
+ label="Model",
57
+ value="eleven_multilingual_v1",
58
+ elem_id="input_model",
59
+ )
60
+
61
+ input_api_key = gr.Textbox(
62
+ label="API Key (Optional)",
63
+ lines=1,
64
+ elem_id="input_api_key"
65
+ )
66
+
67
+ run_button = gr.Button(
68
+ text="Generate Voice",
69
+ type="button"
70
+ )
71
+
72
+ out_audio = gr.Audio(
73
+ label="Generated Voice",
74
+ type="numpy",
75
+ elem_id="out_audio"
76
+ )
77
+
78
+ inputs = [input_text, input_voice, input_model, input_api_key]
79
+ outputs = [out_audio]
80
+
81
+ run_button.click(
82
+ fn=generate_voice,
83
+ inputs=inputs,
84
+ outputs=outputs,
85
+ queue=True
86
+ )
87
+
88
+ block.queue()
89
+ block.launch()