-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyzed_yomi.py
90 lines (76 loc) · 2.66 KB
/
analyzed_yomi.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import json
import numpy as np
from analyze import analyze
def main():
# yomifile = "/home/gisuperu/Desktop/procon33_sports/origin_data/JKspeech/{}.wav"
# outjson = "/home/gisuperu/Desktop/procon33_sports/yomi.json"
yomifile = "./origin_data/JKspeech/{}.wav"
outjson = "./yomi.json"
outjson_msk = "./mask.json"
yomi_data = dict({})
for i in range(1, 45):
data = analyze.analyze(yomifile.format("J"+str(i).zfill(2)))
yomi_data["J"+str(i).zfill(2)] = {"size": len(data), "data": data}
data = analyze.analyze(yomifile.format("E"+str(i).zfill(2)))
yomi_data["E"+str(i).zfill(2)] = {"size": len(data), "data": data}
print(i, end=" ")
ran = 1000000000
for key in yomi_data.keys():
ran = yomi_data[key]["size"] if ran > yomi_data[key]["size"] else ran
print(ran)
averageJP = []
averageEN = []
average = []
sd = []
sdJP = []
sdEN = []
for i in range(ran):
numJP = 0
numEN = 0
num = 0
average.append(0)
averageJP.append(0)
averageEN.append(0)
for data in yomi_data.keys():
if data[0] == 'E':
average[i] += yomi_data[data]["data"][i]
averageEN[i] += yomi_data[data]["data"][i]
numEN += 1
num += 1
elif data[0] == 'J':
average[i] += yomi_data[data]["data"][i]
averageJP[i] += yomi_data[data]["data"][i]
numJP += 1
num += 1
# print("num: "+str(num))
# print("numJP: "+str(numJP))
# print("numEN: "+str(numEN))
average[i] /= num
averageJP[i] /= numJP
averageEN[i] /= numEN
sd.append(0)
sdJP.append(0)
sdEN.append(0)
for data in yomi_data.keys():
if data[0] == 'E':
sd[i] += (yomi_data[data]["data"][i] - average[i])**2
sdEN[i] += (yomi_data[data]["data"][i] - average[i])**2
elif data[0] == 'J':
sd[i] += (yomi_data[data]["data"][i] - average[i])**2
sdJP[i] += (yomi_data[data]["data"][i] - average[i])**2
sd[i] /= num
sdJP[i] /= numJP
sdEN[i] /= numEN
np.sqrt(sd)
np.sqrt(sdJP)
np.sqrt(sdEN)
for i in range(len(sd)):
if sd[i] < 700:
sd[i] = 0.00001
with open(outjson, "w+") as file:
json.dump(yomi_data, file, indent=4)
mask = dict({"ave":average, "aveJP":averageJP, "aveEN":averageEN, "sd":sd, "sdJP":sdJP, "sdEN":sdEN})
with open(outjson_msk, "w+") as file:
json.dump(mask, file, indent=4)
if __name__ == '__main__':
main()