CASLL commited on
Commit
11865e2
1 Parent(s): 3bdcbc3

Update create_wav.py

Browse files
Files changed (1) hide show
  1. 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
- repo_id = "cvssp/audioldm-s-full-v2"
6
- pipe = AudioLDMPipeline.from_pretrained(repo_id, torch_dtype=torch.float16)
7
- pipe = pipe.to("cpu")
8
 
9
- def create(prompt:str, name_file: str):
10
- prompt = prompt
11
- audio = pipe(prompt, num_inference_steps=10, audio_length_in_s=5.0).audios[0]
 
12
 
13
- # save the audio sample as a .wav file
14
- scipy.io.wavfile.write(f'{name_file}.wav', rate=16000, data=audio)
15
 
16
- # Assuming your file is named 'audio_file.mp3'
17
- audio_file = f'{name_file}.wav'
18
 
19
- # Play the audio file
20
- return audio_file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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