Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,9 @@ 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 pad_buffer(audio):
|
| 7 |
-
# Pad buffer to multiple of 2 bytes
|
| 8 |
buffer_size = len(audio)
|
| 9 |
element_size = np.dtype(np.int16).itemsize
|
| 10 |
if buffer_size % element_size != 0:
|
|
@@ -15,7 +15,7 @@ def generate_voice(text, voice_name):
|
|
| 15 |
model_name = "eleven_multilingual_v1"
|
| 16 |
try:
|
| 17 |
audio = generate(
|
| 18 |
-
text[:250],
|
| 19 |
voice=voice_name,
|
| 20 |
model=model_name
|
| 21 |
)
|
|
@@ -25,10 +25,7 @@ def generate_voice(text, voice_name):
|
|
| 25 |
except Exception as e:
|
| 26 |
raise gr.Error(str(e))
|
| 27 |
|
| 28 |
-
# Fetch all available voices
|
| 29 |
all_voices = voices()
|
| 30 |
-
|
| 31 |
-
# Filter out the desired voices and set Antonio as default
|
| 32 |
desired_voices = ["Antonio"]
|
| 33 |
filtered_voices = [voice.name for voice in all_voices if voice.name in desired_voices]
|
| 34 |
|
|
@@ -52,13 +49,31 @@ out_audio = gr.Audio(
|
|
| 52 |
elem_id="out_audio"
|
| 53 |
)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
iface = gr.Interface(
|
| 56 |
fn=generate_voice,
|
| 57 |
inputs=[input_text, input_voice],
|
| 58 |
outputs=out_audio,
|
| 59 |
live=True,
|
| 60 |
theme="Monochrome",
|
| 61 |
-
concurrency_count=1
|
|
|
|
|
|
|
|
|
|
| 62 |
)
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
from elevenlabs import voices, generate, set_api_key, UnauthenticatedRateLimitError
|
| 5 |
+
import streamlit as st
|
| 6 |
|
| 7 |
def pad_buffer(audio):
|
|
|
|
| 8 |
buffer_size = len(audio)
|
| 9 |
element_size = np.dtype(np.int16).itemsize
|
| 10 |
if buffer_size % element_size != 0:
|
|
|
|
| 15 |
model_name = "eleven_multilingual_v1"
|
| 16 |
try:
|
| 17 |
audio = generate(
|
| 18 |
+
text[:250],
|
| 19 |
voice=voice_name,
|
| 20 |
model=model_name
|
| 21 |
)
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
raise gr.Error(str(e))
|
| 27 |
|
|
|
|
| 28 |
all_voices = voices()
|
|
|
|
|
|
|
| 29 |
desired_voices = ["Antonio"]
|
| 30 |
filtered_voices = [voice.name for voice in all_voices if voice.name in desired_voices]
|
| 31 |
|
|
|
|
| 49 |
elem_id="out_audio"
|
| 50 |
)
|
| 51 |
|
| 52 |
+
css = """
|
| 53 |
+
.gr-textbox {
|
| 54 |
+
font-size: 12px;
|
| 55 |
+
}
|
| 56 |
+
.gr-dropdown {
|
| 57 |
+
font-size: 12px;
|
| 58 |
+
}
|
| 59 |
+
.gr-audio {
|
| 60 |
+
width: 90%;
|
| 61 |
+
}
|
| 62 |
+
"""
|
| 63 |
+
|
| 64 |
iface = gr.Interface(
|
| 65 |
fn=generate_voice,
|
| 66 |
inputs=[input_text, input_voice],
|
| 67 |
outputs=out_audio,
|
| 68 |
live=True,
|
| 69 |
theme="Monochrome",
|
| 70 |
+
concurrency_count=1,
|
| 71 |
+
css=css,
|
| 72 |
+
width=320,
|
| 73 |
+
height=480
|
| 74 |
)
|
| 75 |
|
| 76 |
+
# Using Streamlit to display the Gradio app within Hugging Face Spaces
|
| 77 |
+
st.title("TTS App with ElevenLabs")
|
| 78 |
+
st.text("Enter your text and choose a voice to generate the speech!")
|
| 79 |
+
gr.Interface._display(iface)
|