Spaces:
Runtime error
Runtime error
File size: 973 Bytes
67e9e37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import gradio as gr
from transformers import AutoProcessor, BarkModel
import scipy
from IPython.display import Audio
# Load the processor and model
processor = AutoProcessor.from_pretrained("suno/bark")
model = BarkModel.from_pretrained("suno/bark")
def generate_audio(text):
# Your preset may vary
voice_preset = "v2/en_speaker_6"
inputs = processor(text, voice_preset=voice_preset)
audio_array = model.generate(**inputs)
audio_array = audio_array.cpu().numpy().squeeze()
sample_rate = model.generation_config.sample_rate
# Write the output to a .wav file
scipy.io.wavfile.write("bark_out.wav", rate=sample_rate, data=audio_array)
return "bark_out.wav"
# Create the Gradio interface
iface = gr.Interface(
fn=generate_audio,
inputs=gr.inputs.Textbox(label="标入prompt(input)"),
outputs=gr.outputs.Audio(label="生成音频(button)", type="file"),
allow_flagging="never"
)
# Launch the interface
iface.launch()
|