typesdigital commited on
Commit
a207c1d
·
1 Parent(s): 6942ee3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Set the API key
24
+ set_api_key("f868e836c02c78b7ee9075d1e116a139")
25
+
26
+ st.title("🎤 World's most advanced Text-to-Speech")
27
+
28
+ description = """
29
+ 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!
30
+ """
31
+
32
+
33
+ st.markdown(description)
34
+
35
+ # Input text
36
+ input_text = st.text_area(
37
+ "Input Text (250 characters max)",
38
+ value="Hahaha OHH MY GOD! This is SOOO funny, I-I am Eleven a text-to-speech system!",
39
+ max_chars=250
40
+ )
41
+
42
+ # Voice selection
43
+ all_voices = voices()
44
+ input_voice = st.selectbox(
45
+ "Voice",
46
+ options=[voice.name for voice in all_voices],
47
+ index=0
48
+ )
49
+
50
+ # Model selection
51
+ input_model = st.radio(
52
+ "Model",
53
+ options=["eleven_monolingual_v1", "eleven_multilingual_v1"],
54
+ index=0
55
+ )
56
+
57
+ # Generate voice
58
+ if st.button("Generate Voice"):
59
+ try:
60
+ audio = generate_voice(input_text, input_voice, input_model)
61
+ st.audio(audio, format='audio/wav')
62
+ except UnauthenticatedRateLimitError:
63
+ st.error("Thanks for trying out ElevenLabs TTS! You've reached the free tier limit. Please provide an API key to continue.")
64
+ except Exception as e:
65
+ st.error(str(e))