Spaces:
Running
Running
as
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import cv2
|
|
5 |
|
6 |
def BeatSwap(audiofile, pattern: str = 'test', scale:float = 1, shift:float = 0, caching:bool = True, variableBPM:bool = False):
|
7 |
print()
|
8 |
-
print(f'path = {audiofile}, pattern = "{pattern}", scale = {scale}, shift = {shift}, caching = {caching}, variable BPM = {variableBPM}'
|
9 |
if pattern == '' or pattern is None: pattern = 'test'
|
10 |
if caching is not False: caching == True
|
11 |
if variableBPM is not True: variableBPM == False
|
@@ -16,7 +16,8 @@ def BeatSwap(audiofile, pattern: str = 'test', scale:float = 1, shift:float = 0,
|
|
16 |
shift=bm.utils._safer_eval(shift)
|
17 |
except: shift = 0
|
18 |
if scale <0: scale = -scale
|
19 |
-
if scale < 0.
|
|
|
20 |
if audiofile is not None:
|
21 |
try:
|
22 |
song=bm.song(audio=audiofile,log=False)
|
@@ -27,16 +28,19 @@ def BeatSwap(audiofile, pattern: str = 'test', scale:float = 1, shift:float = 0,
|
|
27 |
print(f'Audiofile is {audiofile}')
|
28 |
return
|
29 |
try:
|
30 |
-
print(f'
|
31 |
if len(song.audio[0]) > (song.sr*1800):
|
32 |
song.audio = np.array(song.audio, copy=False)
|
33 |
song.audio = song.audio[:,:song.sr*1800]
|
34 |
except Exception as e: print(f'Reducing audio size failed, why? {e}')
|
35 |
lib = 'madmom.BeatDetectionProcessor' if variableBPM is False else 'madmom.BeatTrackingProcessor'
|
36 |
-
song.path = song.path.split('.')[
|
|
|
|
|
37 |
song.beatmap_generate(lib=lib, caching=caching)
|
38 |
song.beatmap_shift(shift)
|
39 |
song.beatmap_scale(scale)
|
|
|
40 |
try:
|
41 |
song.image_generate()
|
42 |
image = bm.image.bw_to_colored(song.image)
|
@@ -47,6 +51,7 @@ def BeatSwap(audiofile, pattern: str = 'test', scale:float = 1, shift:float = 0,
|
|
47 |
except Exception as e:
|
48 |
print(f'Image generation failed: {e}')
|
49 |
image = np.asarray([[0.5,-0.5],[-0.5,0.5]])
|
|
|
50 |
song.beatswap(pattern=pattern, scale=1, shift=0)
|
51 |
song.audio = (np.clip(np.asarray(song.audio), -1, 1) * 32766).astype(np.int16).T
|
52 |
#song.write_audio(output=bm.outputfilename('',song.filename, suffix=' (beatswap)'))
|
|
|
5 |
|
6 |
def BeatSwap(audiofile, pattern: str = 'test', scale:float = 1, shift:float = 0, caching:bool = True, variableBPM:bool = False):
|
7 |
print()
|
8 |
+
print(f'path = {audiofile}, pattern = "{pattern}", scale = {scale}, shift = {shift}, caching = {caching}, variable BPM = {variableBPM}')
|
9 |
if pattern == '' or pattern is None: pattern = 'test'
|
10 |
if caching is not False: caching == True
|
11 |
if variableBPM is not True: variableBPM == False
|
|
|
16 |
shift=bm.utils._safer_eval(shift)
|
17 |
except: shift = 0
|
18 |
if scale <0: scale = -scale
|
19 |
+
if scale < 0.02: scale = 0.02
|
20 |
+
print('Loading auidofile...')
|
21 |
if audiofile is not None:
|
22 |
try:
|
23 |
song=bm.song(audio=audiofile,log=False)
|
|
|
28 |
print(f'Audiofile is {audiofile}')
|
29 |
return
|
30 |
try:
|
31 |
+
print(f'Scale = {scale}, shift = {shift}, length = {len(song.audio[0])/song.sr}')
|
32 |
if len(song.audio[0]) > (song.sr*1800):
|
33 |
song.audio = np.array(song.audio, copy=False)
|
34 |
song.audio = song.audio[:,:song.sr*1800]
|
35 |
except Exception as e: print(f'Reducing audio size failed, why? {e}')
|
36 |
lib = 'madmom.BeatDetectionProcessor' if variableBPM is False else 'madmom.BeatTrackingProcessor'
|
37 |
+
song.path = song.path.split('.')[:-2][:-8]+'.'+song.path.split('.')[-1]
|
38 |
+
print(f'path: {song.path}')
|
39 |
+
print('Generating beatmap...')
|
40 |
song.beatmap_generate(lib=lib, caching=caching)
|
41 |
song.beatmap_shift(shift)
|
42 |
song.beatmap_scale(scale)
|
43 |
+
print('Generating image...')
|
44 |
try:
|
45 |
song.image_generate()
|
46 |
image = bm.image.bw_to_colored(song.image)
|
|
|
51 |
except Exception as e:
|
52 |
print(f'Image generation failed: {e}')
|
53 |
image = np.asarray([[0.5,-0.5],[-0.5,0.5]])
|
54 |
+
print('Beatswapping...')
|
55 |
song.beatswap(pattern=pattern, scale=1, shift=0)
|
56 |
song.audio = (np.clip(np.asarray(song.audio), -1, 1) * 32766).astype(np.int16).T
|
57 |
#song.write_audio(output=bm.outputfilename('',song.filename, suffix=' (beatswap)'))
|