Spaces:
Sleeping
Sleeping
Commit
·
1b0d41c
1
Parent(s):
7ac35fc
Text to speak generation
Browse files- .gitignore +3 -1
- __pycache__/app.cpython-311.pyc +0 -0
- app.py +29 -3
- requirements.txt +5 -0
.gitignore
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
hf/
|
2 |
-
remote-origin.txt
|
|
|
|
|
|
1 |
hf/
|
2 |
+
remote-origin.txt
|
3 |
+
*.wav
|
4 |
+
new\ audio.wav
|
__pycache__/app.cpython-311.pyc
ADDED
Binary file (1.84 kB). View file
|
|
app.py
CHANGED
@@ -1,7 +1,33 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import BarkModel, AutoProcessor
|
3 |
+
import torch
|
4 |
+
from scipy.io.wavfile import write as write_wav
|
5 |
+
import os
|
6 |
|
7 |
+
'''
|
8 |
+
This app runs a text to voice transformer
|
9 |
|
10 |
+
'''
|
11 |
+
### Because we are using CPU we add this code: ###
|
12 |
+
device = "cpu"
|
13 |
+
# load in fp16
|
14 |
+
model = BarkModel.from_pretrained("suno/bark-small").to(device)
|
15 |
+
processor = AutoProcessor.from_pretrained("suno/bark")
|
16 |
+
|
17 |
+
voice_preset = "v2/en_speaker_3"
|
18 |
+
|
19 |
+
def generate_audio(text, preset, output_file_name = "bark_generation"):
|
20 |
+
file_name = output_file_name + ".wav"
|
21 |
+
inputs = processor(text, voice_preset)
|
22 |
+
audio_array = model.generate(**inputs)
|
23 |
+
audio_array = audio_array.cpu().numpy().squeeze()
|
24 |
+
sample_rate = model.generation_config.sample_rate
|
25 |
+
write_wav(file_name, sample_rate, audio_array)
|
26 |
+
return file_name
|
27 |
+
|
28 |
+
#Presets drop down
|
29 |
+
presets = ["v2/en_speaker_0", "v2/en_speaker_1", "v2/en_speaker_2", "v2/en_speaker_3","v2/en_speaker_4", "v2/en_speaker_5", "v2/en_speaker_6", "v2/en_speaker_9"]
|
30 |
+
|
31 |
+
#Gradio interface
|
32 |
+
iface = gr.Interface(fn=generate_audio, inputs=["text", gr.components.Dropdown(choices=presets),"text"], outputs="audio")
|
33 |
iface.launch()
|
requirements.txt
CHANGED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
accelerate
|
5 |
+
scipy
|