forked from Renovamen/Speech-Emotion-Recognition
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFile.py
48 lines (41 loc) · 1.41 KB
/
File.py
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
43
44
45
46
47
48
# 数据集整理
import os, shutil
DATA_PATH = "/Users/zou/Desktop/CASIA"
# 批量删除指定路径下所有非.wav文件
def remove(file_path):
for root, dirs, files in os.walk(file_path):
for item in files:
if not item.endswith('.wav'):
try:
print("Delete file: ", os.path.join(root, item))
os.remove(os.path.join(root, item))
except:
continue
# 批量按指定格式改名(不然把相同情感的音频整理到同一个文件夹时会重名)
def rename(file_path):
for root, dirs, files in os.walk(file_path):
for item in files:
if item.endswith('.wav'):
people_name = root.split('/')[-2]
emotion_name = root.split('/')[-1]
item_name = item[:-4] # 音频原名(去掉.wav)
old_path = os.path.join(root, item)
new_path = os.path.join(root, item_name + '-' + emotion_name + '-'+ people_name + '.wav') # 新音频地址
try:
os.rename(old_path, new_path)
print('converting ', old_path, ' to ', new_path)
except:
continue
# 把音频按情感分类,放在不同文件夹下
def move(file_path):
for root, dirs, files in os.walk(file_path):
for item in files:
if item.endswith('.wav'):
emotion_name = root.split('/')[-1]
old_path = os.path.join(root, item)
new_path = file_path + '/' + emotion_name + '/' + item
try:
shutil.move(old_path, new_path)
print("Move ", old_path, " to ", new_path)
except:
continue