ChancesYuan commited on
Commit
165a887
1 Parent(s): 89951bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -1,7 +1,7 @@
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")
@@ -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
- # 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
 
 
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