-
Notifications
You must be signed in to change notification settings - Fork 11
/
getFinalEstimates.py
56 lines (44 loc) · 1.65 KB
/
getFinalEstimates.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
import csv,sys
from scipy.io import wavfile
import numpy as np
from numpy import genfromtxt
import os,glob
curdir = sys.argv[1]
datadir = sys.argv[2]
F = genfromtxt(curdir + "/tmp_data/features/ALUCs_out_individual.txt", delimiter='\t')
DATA = []
with open(curdir + "/tmp_data/features/ALUCs_out_individual.txt") as csv_file:
csv_reader = csv.reader(csv_file, delimiter='\t')
line_count = 0
for row in csv_reader:
DATA.append(row)
line_count += 1
fileid = []
for line in DATA:
s = line[0]
path, filename = os.path.split(s)
fileid.append(filename[0:-26])
uq_files = list(set(fileid))
text_file = open(curdir + "/ALICE_output.txt", "w")
text_file.write("FileID \t phonemes \t syllables \t words\n")
for file in uq_files:
count_phones = 0
count_syls = 0
count_words = 0
for i in range(0,len(fileid)):
if(file == fileid[i]):
count_phones = count_phones+float(DATA[i][1])
count_syls = count_syls+ float(DATA[i][2])
count_words = count_words+float(DATA[i][3])
text_file.write(str(file + "\t" + str(int(round(count_phones))) + "\t" + str(int(round(count_syls))) + "\t" + str(int(round(count_words))) + "\n"))
# Compare original files and output files to see if some are missing (no diarization output, i.e., no speech)
fileList_orig = sorted(glob.glob(datadir + '/*.wav'))
for file in fileList_orig:
path, filename = os.path.split(file)
exists = False
for file2 in uq_files:
if filename[0:-4] == file2:
exists = True
if not exists:
text_file.write(str(filename[0:-4] + "\t" + "0" + "\t" + "0" + "\t" + "0" + "\n"))
text_file.close()