-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathextendQuery.py
More file actions
54 lines (31 loc) · 1.38 KB
/
extendQuery.py
File metadata and controls
54 lines (31 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import audioread as ar
import CacheUtils as cu
import os
def clipAudio(dirPath, fileName, clip_len, max_clip):
filePath = os.path.join(dirPath, fileName)
audioID = fileName.split(".")[0]
with ar.audio_open(filePath) as a:
seconds = a.duration
max_duration = int(min(seconds//clip_len, max_clip) * clip_len)
for i in range(0,max_duration,clip_len):
newFilePath = os.path.join(dirPath, "{}_{}.mp3".format(audioID, i))
print("[clipAudio]",filePath,"from",i,"to",i+clip_len)
os.system("ffmpeg -i {} -ss {} -t {} -acodec copy {}".\
format(filePath, i, clip_len, newFilePath))
os.system("rm {}".format(filePath))
def extendQueryByClip(test, version, clip_len=20, max_clip=10):
print("[extendQueryByClip] extending", test, "to version", version)
newTestName = "{}_{}".format(test, version)
os.system("cp -r {} {}".format(test, newTestName))
for artist in cu.listdir(newTestName):
dirPath = os.path.join(newTestName, artist)
for song in cu.listdir(dirPath):
clipAudio(dirPath, song, clip_len, max_clip)
extendQueryByClip("live", "clip10", 10, 10)
extendQueryByClip("live", "clip20", 20, 10)
extendQueryByClip("live", "clip30", 30, 10)
extendQueryByClip("live", "clip40", 40, 10)
extendQueryByClip("cover", "clip10", 10, 10)
extendQueryByClip("cover", "clip20", 20, 10)
extendQueryByClip("cover", "clip30", 30, 10)
extendQueryByClip("cover", "clip40", 40, 10)