Spaces:
Runtime error
Runtime error
genA.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from audiocraft.models import musicgen
|
3 |
+
from audiocraft.utils.notebook import display_audio
|
4 |
+
|
5 |
+
gcPU = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
6 |
+
|
7 |
+
audiocraft__music_gen__large = musicgen.MusicGen.get_pretrained('medium', device=gcPU)
|
8 |
+
audiocraft__music_gen__large.set_generation_params(duration=15) # for sample_rate=24KHz to get actual duration of 20sec
|
9 |
+
|
10 |
+
def func__MusicGen(ip):
|
11 |
+
print('[p] :: processing')
|
12 |
+
op = audiocraft__music_gen__large.generate(ip,progress=True)
|
13 |
+
for itr in range(0,len(ip)):
|
14 |
+
print('= ='*8)
|
15 |
+
print('[ip] :: ',end='\t')
|
16 |
+
display(ip[itr])
|
17 |
+
print('[op] :: ',end='\t')
|
18 |
+
display_audio(op[itr],sample_rate=32000) # 1sec=32KHz(here) i.e to get the audio in the specified duration, initialize sample_rate=32000
|
19 |
+
print('= ='*8)
|
20 |
+
|
21 |
+
ip = ' '
|
22 |
+
io = []
|
23 |
+
while(ip!=''):
|
24 |
+
ip = input('[ip] :: prompt : ') or ''
|
25 |
+
if(ip==''):
|
26 |
+
break
|
27 |
+
io.append(ip)
|
28 |
+
func__MusicGen(io)
|