Amitesh007 commited on
Commit
12cda3a
1 Parent(s): f35f456

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError
4
+
5
+ def pad_buffer(audio):
6
+ # Pad buffer to multiple of 2 bytes
7
+ buffer_size = len(audio)
8
+ element_size = np.dtype(np.int16).itemsize
9
+ if buffer_size % element_size != 0:
10
+ audio = audio + b'\0' * (element_size - (buffer_size % element_size))
11
+ return audio
12
+
13
+ def generate_voice(text, voice_name, model_name):
14
+ audio = generate(
15
+ text[:250], # Limit to 250 characters
16
+ voice=voice_name,
17
+ model=model_name
18
+ )
19
+ audio_data = np.frombuffer(pad_buffer(audio), dtype=np.int16)
20
+ audio_bytes = audio_data.tobytes()
21
+ return audio_bytes
22
+
23
+ st.title("🎤 World's most advanced Text-to-Speech")
24
+
25
+ description = """
26
+ 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. Sign up on [ElevenLabs](https://elevenlabs.io) to get fast access, long-form generation, voice cloning, API keys, and more!
27
+ """
28
+
29
+
30
+ st.markdown(description)
31
+
32
+ input_text = st.text_area(
33
+ "Input Text (250 characters max)",
34
+ value="Hahaha OHH MY GOD! This is SOOO funny, I-I am Eleven a text-to-speech system!",
35
+ max_chars=250
36
+ )
37
+
38
+ all_voices = voices()
39
+ input_voice = st.selectbox(
40
+ "Voice",
41
+ options=[voice.name for voice in all_voices],
42
+ index=0
43
+ )
44
+
45
+ input_model = st.radio(
46
+ "Model",
47
+ options=["eleven_monolingual_v1", "eleven_multilingual_v1"],
48
+ index=0
49
+ )
50
+
51
+ if st.button("Generate Voice"):
52
+ try:
53
+ audio = generate_voice(input_text, input_voice, input_model)
54
+ st.audio(audio, format='audio/wav')
55
+ except UnauthenticatedRateLimitError:
56
+ st.error("Thanks for trying out ElevenLabs TTS! You've reached the free tier limit. Please provide an API key to continue.")
57
+ except Exception as e:
58
+ st.error(str(e))