Spaces:
Runtime error
Runtime error
ChancesYuan
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoProcessor, BarkModel
|
3 |
import scipy
|
4 |
-
|
5 |
|
6 |
# Load the processor and model
|
7 |
processor = AutoProcessor.from_pretrained("suno/bark")
|
@@ -12,18 +12,23 @@ def generate_audio(text):
|
|
12 |
voice_preset = "v2/en_speaker_6"
|
13 |
inputs = processor(text, voice_preset=voice_preset)
|
14 |
audio_array = model.generate(**inputs)
|
|
|
15 |
audio_array = audio_array.cpu().numpy().squeeze()
|
16 |
sample_rate = model.generation_config.sample_rate
|
17 |
-
|
18 |
-
# Write the output to a .wav file
|
19 |
-
scipy.io.wavfile.write("bark_out.wav", rate=sample_rate, data=audio_array)
|
20 |
-
return "bark_out.wav"
|
21 |
|
22 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
iface = gr.Interface(
|
24 |
fn=generate_audio,
|
25 |
-
inputs=
|
26 |
-
outputs=
|
|
|
27 |
allow_flagging="never"
|
28 |
)
|
29 |
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoProcessor, BarkModel
|
3 |
import scipy
|
4 |
+
import numpy as np
|
5 |
|
6 |
# Load the processor and model
|
7 |
processor = AutoProcessor.from_pretrained("suno/bark")
|
|
|
12 |
voice_preset = "v2/en_speaker_6"
|
13 |
inputs = processor(text, voice_preset=voice_preset)
|
14 |
audio_array = model.generate(**inputs)
|
15 |
+
# Move the tensor to CPU and convert to numpy array
|
16 |
audio_array = audio_array.cpu().numpy().squeeze()
|
17 |
sample_rate = model.generation_config.sample_rate
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
# Saving the audio file temporarily
|
20 |
+
output_file = '/tmp/bark_out.wav'
|
21 |
+
scipy.io.wavfile.write(output_file, rate=sample_rate, data=audio_array)
|
22 |
+
|
23 |
+
# Return the path to the saved audio file
|
24 |
+
return output_file
|
25 |
+
|
26 |
+
# Define the Gradio interface
|
27 |
iface = gr.Interface(
|
28 |
fn=generate_audio,
|
29 |
+
inputs="text",
|
30 |
+
outputs="audio",
|
31 |
+
examples=[["Hello, my dog is cute"]],
|
32 |
allow_flagging="never"
|
33 |
)
|
34 |
|