Spaces:
Runtime error
Runtime error
Update create_wav.py
Browse files- create_wav.py +32 -12
create_wav.py
CHANGED
@@ -1,20 +1,40 @@
|
|
1 |
import scipy
|
2 |
import torch
|
3 |
from diffusers import AudioLDMPipeline
|
|
|
4 |
|
5 |
-
|
6 |
-
pipe = AudioLDMPipeline.from_pretrained(repo_id, torch_dtype=torch.float16)
|
7 |
-
pipe = pipe.to("cpu")
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
audio_file = f'{name_file}.wav'
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import scipy
|
2 |
import torch
|
3 |
from diffusers import AudioLDMPipeline
|
4 |
+
from diffusers import AudioLDM2Pipeline
|
5 |
|
6 |
+
def processing(prompt:str, name_file: str, model:str):
|
|
|
|
|
7 |
|
8 |
+
if model == "good":
|
9 |
+
repo_id = "cvssp/audioldm-s-full-v2"
|
10 |
+
pipe = AudioLDMPipeline.from_pretrained(repo_id, torch_dtype=torch.float16)
|
11 |
+
pipe = pipe.to("cuda")
|
12 |
|
13 |
+
prompt = prompt
|
14 |
+
audio = pipe(prompt, num_inference_steps=100, audio_length_in_s=5).audios[0]
|
15 |
|
16 |
+
scipy.io.wavfile.write(f'{name_file}.wav', rate=16000, data=audio)
|
|
|
17 |
|
18 |
+
elif model == "better":
|
19 |
+
repo_id = "cvssp/audioldm2"
|
20 |
+
pipe = AudioLDM2Pipeline.from_pretrained(repo_id, torch_dtype=torch.float16)
|
21 |
+
pipe = pipe.to("cuda")
|
22 |
+
|
23 |
+
prompt = prompt
|
24 |
+
negative_prompt = "Low quality."
|
25 |
+
|
26 |
+
generator = torch.Generator("cuda").manual_seed(0)
|
27 |
+
|
28 |
+
audio = pipe(
|
29 |
+
prompt,
|
30 |
+
negative_prompt=negative_prompt,
|
31 |
+
num_inference_steps=200,
|
32 |
+
audio_length_in_s=10.0,
|
33 |
+
num_waveforms_per_prompt=3,
|
34 |
+
generator=generator
|
35 |
+
).audios
|
36 |
+
|
37 |
+
scipy.io.wavfile.write(f'{name_file}.wav', rate=16000, data=audio[0])
|
38 |
+
|
39 |
+
audio_file = f'{name_file}.wav'
|
40 |
+
return audio_file
|