Update app.py
Browse files
app.py
CHANGED
@@ -2,10 +2,10 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import shutil
|
4 |
|
5 |
-
from huggingface_hub import snapshot_download
|
6 |
import numpy as np
|
7 |
from scipy.io import wavfile
|
8 |
-
|
9 |
model_ids = [
|
10 |
'suno/bark',
|
11 |
]
|
@@ -13,7 +13,7 @@ model_ids = [
|
|
13 |
for model_id in model_ids:
|
14 |
model_name = model_id.split('/')[-1]
|
15 |
snapshot_download(model_id, local_dir=f'checkpoints/{model_name}')
|
16 |
-
|
17 |
#from TTS.tts.configs.bark_config import BarkConfig
|
18 |
#from TTS.tts.models.bark import Bark
|
19 |
|
@@ -89,57 +89,9 @@ def infer(prompt, input_wav_file):
|
|
89 |
for item in contents:
|
90 |
print(item)
|
91 |
|
92 |
-
return "output.wav", f"bark_voices/{file_name}/{contents[1]}"
|
93 |
-
|
94 |
-
def infer_with_npz(prompt, input_wav_file):
|
95 |
-
print("NEW GENERATION WITH EXISTING .NPZ")
|
96 |
-
# Path to your WAV file
|
97 |
-
source_path = input_wav_file
|
98 |
-
# Extract the file name without the extension
|
99 |
-
file_name = os.path.splitext(os.path.basename(source_path))[0]
|
100 |
-
# List all the files and subdirectories in the given directory
|
101 |
-
contents = os.listdir(f"bark_voices/{file_name}")
|
102 |
-
# Print the contents
|
103 |
-
for item in contents:
|
104 |
-
print(item)
|
105 |
-
|
106 |
-
first_item = contents[0] # Index 0 corresponds to the first item
|
107 |
-
item_path = os.path.join(f"bark_voices/{file_name}", first_item)
|
108 |
-
os.remove(item_path)
|
109 |
|
110 |
-
"""
|
111 |
-
print("BEGINNING GENERATION")
|
112 |
-
# cloning a speaker.
|
113 |
-
text = prompt
|
114 |
-
# It assumes that you have a speaker file in `bark_voices/speaker_n/speaker.npz`
|
115 |
-
output_dict = model.synthesize(
|
116 |
-
text,
|
117 |
-
config,
|
118 |
-
speaker_id=f"{file_name}",
|
119 |
-
voice_dirs="bark_voices/"
|
120 |
-
)
|
121 |
-
|
122 |
-
print(output_dict)
|
123 |
|
124 |
-
print("WRITING WAVE FILE")
|
125 |
-
|
126 |
-
sample_rate = 24000 # Replace with the actual sample rate
|
127 |
-
|
128 |
-
wavfile.write(
|
129 |
-
'output.wav',
|
130 |
-
sample_rate,
|
131 |
-
output_dict['wav']
|
132 |
-
)
|
133 |
-
"""
|
134 |
-
# Print again the contents
|
135 |
-
contents = os.listdir(f"bark_voices/{file_name}")
|
136 |
-
for item in contents:
|
137 |
-
print(item)
|
138 |
-
|
139 |
-
return 'output.wav'
|
140 |
-
|
141 |
-
def uploaded_audio():
|
142 |
-
return gr.update(visible=True), gr.update(visible=False)
|
143 |
css = """
|
144 |
#col-container {max-width: 780px; margin-left: auto; margin-right: auto;}
|
145 |
"""
|
@@ -180,29 +132,7 @@ with gr.Blocks(css=css) as demo:
|
|
180 |
],
|
181 |
outputs = [
|
182 |
cloned_out,
|
183 |
-
npz_file
|
184 |
-
submit_btn,
|
185 |
-
submit_with_npz_btn
|
186 |
-
]
|
187 |
-
)
|
188 |
-
|
189 |
-
submit_with_npz_btn.click(
|
190 |
-
fn = infer_with_npz,
|
191 |
-
inputs = [
|
192 |
-
prompt,
|
193 |
-
audio_in
|
194 |
-
],
|
195 |
-
outputs = [
|
196 |
-
cloned_out
|
197 |
-
]
|
198 |
-
)
|
199 |
-
|
200 |
-
audio_in.upload(
|
201 |
-
fn=uploaded_audio,
|
202 |
-
inputs=[],
|
203 |
-
outputs=[
|
204 |
-
submit_btn,
|
205 |
-
submit_with_npz_btn
|
206 |
]
|
207 |
)
|
208 |
|
|
|
2 |
import os
|
3 |
import shutil
|
4 |
|
5 |
+
#from huggingface_hub import snapshot_download
|
6 |
import numpy as np
|
7 |
from scipy.io import wavfile
|
8 |
+
"""
|
9 |
model_ids = [
|
10 |
'suno/bark',
|
11 |
]
|
|
|
13 |
for model_id in model_ids:
|
14 |
model_name = model_id.split('/')[-1]
|
15 |
snapshot_download(model_id, local_dir=f'checkpoints/{model_name}')
|
16 |
+
"""
|
17 |
#from TTS.tts.configs.bark_config import BarkConfig
|
18 |
#from TTS.tts.models.bark import Bark
|
19 |
|
|
|
89 |
for item in contents:
|
90 |
print(item)
|
91 |
|
92 |
+
return "output.wav", f"bark_voices/{file_name}/{contents[1]}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
css = """
|
96 |
#col-container {max-width: 780px; margin-left: auto; margin-right: auto;}
|
97 |
"""
|
|
|
132 |
],
|
133 |
outputs = [
|
134 |
cloned_out,
|
135 |
+
npz_file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
]
|
137 |
)
|
138 |
|