Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -23,40 +23,50 @@ torch.load = original_load
|
|
23 |
|
24 |
def generate_speech(reference_audio, text):
|
25 |
"""
|
26 |
-
Generate speech audio
|
27 |
|
28 |
Parameters:
|
29 |
-
reference_audio (str):
|
30 |
text (str): Text to convert to speech.
|
31 |
|
32 |
Returns:
|
33 |
-
str: Path to the generated audio file
|
34 |
"""
|
35 |
-
#
|
36 |
-
|
|
|
37 |
|
38 |
-
#
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
write_wav(temp_file_path, SAMPLE_RATE, audio_array)
|
43 |
-
temp_file.close()
|
44 |
|
45 |
return temp_file_path
|
46 |
|
47 |
# Build the Gradio interface
|
48 |
-
with gr.Blocks(title="
|
49 |
-
gr.Markdown("##
|
50 |
-
gr.Markdown(
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
57 |
audio_output = gr.Audio(label="Generated Speech", interactive=False)
|
58 |
|
59 |
-
#
|
|
|
60 |
generate_btn.click(
|
61 |
fn=generate_speech,
|
62 |
inputs=[audio_input, text_input],
|
|
|
23 |
|
24 |
def generate_speech(reference_audio, text):
|
25 |
"""
|
26 |
+
Generate speech audio using a pre-defined speaker.
|
27 |
|
28 |
Parameters:
|
29 |
+
reference_audio (str): Path to uploaded audio (ignored in this version).
|
30 |
text (str): Text to convert to speech.
|
31 |
|
32 |
Returns:
|
33 |
+
str: Path to the generated audio file.
|
34 |
"""
|
35 |
+
# Use a pre-defined speaker since custom voice cloning isn't supported
|
36 |
+
history_prompt = "v2/en_speaker_6" # Pre-defined speaker ID
|
37 |
+
audio_array = generate_audio(text, history_prompt=history_prompt)
|
38 |
|
39 |
+
# Save the audio to a temporary file
|
40 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
|
41 |
+
write_wav(temp_file.name, SAMPLE_RATE, audio_array)
|
42 |
+
temp_file_path = temp_file.name
|
|
|
|
|
43 |
|
44 |
return temp_file_path
|
45 |
|
46 |
# Build the Gradio interface
|
47 |
+
with gr.Blocks(title="Text-to-Speech with Bark") as app:
|
48 |
+
gr.Markdown("## Text-to-Speech with Bark")
|
49 |
+
gr.Markdown(
|
50 |
+
"Enter text to hear it in a pre-defined voice. "
|
51 |
+
"Custom voice cloning from uploaded audio is not supported in this version."
|
52 |
+
)
|
53 |
|
54 |
+
# Input components
|
55 |
+
audio_input = gr.Audio(
|
56 |
+
type="filepath",
|
57 |
+
label="Upload Your Voice Sample (English, Ignored)",
|
58 |
+
visible=True # Kept for future functionality, but ignored
|
59 |
+
)
|
60 |
+
text_input = gr.Textbox(
|
61 |
+
label="Enter Text to Convert to Speech",
|
62 |
+
placeholder="e.g., I love chocolate"
|
63 |
+
)
|
64 |
|
65 |
+
# Output component
|
66 |
audio_output = gr.Audio(label="Generated Speech", interactive=False)
|
67 |
|
68 |
+
# Button to trigger generation
|
69 |
+
generate_btn = gr.Button("Generate Speech")
|
70 |
generate_btn.click(
|
71 |
fn=generate_speech,
|
72 |
inputs=[audio_input, text_input],
|