annotate Code/time_freq_representation/utils.py @ 47:b0186d4a4496
tip
Move 7Digital dataset to Downloads
author |
Paulo Chiliguano <p.e.chiliguano@se14.qmul.ac.uk> |
date |
Sat, 09 Jul 2022 00:50:43 -0500 |
parents |
68a62ca32441 |
children |
|
rev |
line source |
p@24
|
1 """
|
p@24
|
2 Source code:
|
p@24
|
3 https://github.com/sidsig/ICASSP-MLP-Code/blob/master/utils.py
|
p@24
|
4 """
|
p@24
|
5
|
p@24
|
6 import os
|
p@24
|
7
|
p@24
|
8 def getFiles(root_dir,ext='.mp3',verbose=True) :
|
p@24
|
9 """
|
p@24
|
10 Returns a list of files
|
p@24
|
11 """
|
p@24
|
12 fileList=[]
|
p@24
|
13 if verbose:
|
p@24
|
14 print "Populating %s files..."%ext
|
p@24
|
15 for (root,dirs,files) in os.walk(root_dir):
|
p@24
|
16 for f in files:
|
p@24
|
17 if f.endswith(ext):
|
p@24
|
18 filePath=os.path.join(root,f)
|
p@24
|
19 fileList.append(filePath)
|
p@24
|
20 if verbose:
|
p@24
|
21 print "%i files found."%len(fileList)
|
p@24
|
22 return fileList
|
p@24
|
23
|
p@24
|
24 def parseFile(filePath):
|
p@24
|
25 """
|
p@24
|
26 Parses the file path and returns (root,fileName,ext)
|
p@24
|
27 """
|
p@24
|
28 root,file=os.path.split(filePath)
|
p@24
|
29 fileName,fileExt=os.path.splitext(file)
|
p@24
|
30 return (root,fileName,fileExt)
|
p@24
|
31
|
p@24
|
32 def read_file(filename):
|
p@24
|
33 """
|
p@24
|
34 Loads a file into a list
|
p@24
|
35 """
|
p@24
|
36 file_list=[l.strip() for l in open(filename,'r').readlines()]
|
p@24
|
37 return file_list
|
p@24
|
38
|
p@24
|
39 def writeFile(dataList,filename):
|
p@24
|
40 with open(filename,'w') as f:
|
p@24
|
41 f.writelines(dataList) |