ChancesYuan commited on
Commit
67e9e37
·
verified ·
1 Parent(s): b6f7631

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoProcessor, BarkModel
3
+ import scipy
4
+ from IPython.display import Audio
5
+
6
+ # Load the processor and model
7
+ processor = AutoProcessor.from_pretrained("suno/bark")
8
+ model = BarkModel.from_pretrained("suno/bark")
9
+
10
+ def generate_audio(text):
11
+ # Your preset may vary
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
+ # Create the Gradio interface
23
+ iface = gr.Interface(
24
+ fn=generate_audio,
25
+ inputs=gr.inputs.Textbox(label="标入prompt(input)"),
26
+ outputs=gr.outputs.Audio(label="生成音频(button)", type="file"),
27
+ allow_flagging="never"
28
+ )
29
+
30
+ # Launch the interface
31
+ iface.launch()