Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
from elevenlabs import clone, generate, set_api_key
|
4 |
-
from pydub import AudioSegment
|
5 |
|
6 |
# Set up ElevenLabs API Key
|
7 |
set_api_key("73bb17b223e2b0f90a403eaeaa3b4d35")
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
files=["./sample1.mp3", "./sample2.mp3"],
|
20 |
-
)
|
21 |
-
|
22 |
-
def generate_voice_output(text):
|
23 |
-
try:
|
24 |
-
# Generate audio for the provided text
|
25 |
-
audio = generate(text=text, voice=voice)
|
26 |
|
27 |
-
|
28 |
-
audio_numpy = (44100, np.frombuffer(audio, dtype=np.int16))
|
29 |
-
return audio_numpy
|
30 |
-
except Exception as e:
|
31 |
-
return str(e)
|
32 |
|
33 |
# Set up Gradio components and interface
|
34 |
input_text = gr.Textbox(label="Input Text", lines=2)
|
35 |
-
output_audio = gr.Audio(label="Generated Voice", type="
|
36 |
|
37 |
iface = gr.Interface(
|
38 |
-
fn=
|
39 |
inputs=input_text,
|
40 |
outputs=output_audio,
|
41 |
theme="Monochrome",
|
|
|
1 |
import gradio as gr
|
2 |
+
from elevenlabs import generate, stream, set_api_key
|
|
|
|
|
3 |
|
4 |
# Set up ElevenLabs API Key
|
5 |
set_api_key("73bb17b223e2b0f90a403eaeaa3b4d35")
|
6 |
|
7 |
+
def generate_streamed_audio(text):
|
8 |
+
audio_stream = generate(
|
9 |
+
text=text,
|
10 |
+
stream=True
|
11 |
+
)
|
12 |
+
# This is where we'd integrate the streaming into Gradio.
|
13 |
+
# However, Gradio's native components don't support audio streaming directly.
|
14 |
+
# As a workaround, we might need to save the streamed audio to a file and return that.
|
15 |
+
# But this is not true real-time streaming.
|
16 |
|
17 |
+
audio_filename = "temp_audio.mp3"
|
18 |
+
with open(audio_filename, "wb") as f:
|
19 |
+
for chunk in audio_stream:
|
20 |
+
f.write(chunk)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
return audio_filename
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Set up Gradio components and interface
|
25 |
input_text = gr.Textbox(label="Input Text", lines=2)
|
26 |
+
output_audio = gr.Audio(label="Generated Voice", type="file")
|
27 |
|
28 |
iface = gr.Interface(
|
29 |
+
fn=generate_streamed_audio,
|
30 |
inputs=input_text,
|
31 |
outputs=output_audio,
|
32 |
theme="Monochrome",
|