-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvgenerator.py
134 lines (113 loc) · 3.32 KB
/
csvgenerator.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import GoogleAPI
import Merge
import json
import pandas as pd
"""
googlewavuri = 'gs://loza2018/sbc0014Mon.wav'
google_transcription = json.loads(
GoogleAPI.getResponseFromGoogleCloud(googlewavuri))
gogle = open('google1sbc14', 'w+')
gogle.write(json.dumps(google_transcription))
"""
def the_func():
googlers = open('google1sbc13', 'r')
filecsv = '2h1-drugie.csv'
matrix = pd.read_csv(filecsv,header=None)
google_transcription_s = googlers.read()
google_trans = json.loads(google_transcription_s)
results = []
for row in matrix.iterrows():
name = row[1][3]
first_word = 0
last_word = 0
error = 999999999
start = float(row[1][1])
end = float(row[1][2])
for i in range(len(google_trans)):
g_start = google_trans[i]["start"]
if g_start > end:
last_word = i
break
for i in range(len(google_trans)):
g_end = google_trans[i]["end"]
if g_end > start:
first_word = i
break
res = []
for trans in google_trans[first_word:last_word]:
res.append(trans["word"])
results.append([
name,
res
])
return results
if __name__ == "__main__":
results = the_func()
for res in results:
print("{}, {}".format(
res[0],
' '.join(res[1])
))
"""
dockers = open('dockers','r')
googlers = open('google','r')
google_transcription_s = googlers.read()
docker_speakers_s = dockers.read()
google_transcription = json.loads(google_transcription_s)
docker_speakers = json.loads(docker_speakers_s)
kolekcja = []
idx=0
for i in docker_speakers:
last_google=0
start = i['start']
end = i['end']
kolekcja.append((i['speaker'],[]))
for j in google_transcription:
end_google = j['end']
start_google = j['start']
if end_google<=float(end):
kolekcja[idx][1].append(j['word'])
google_transcription = google_transcription[last_google:]
last_google+=1
idx+=1
"""
"""
[
[1, string ],
[2, string ],
...
]
"""
'''def the_func():
dockers = open('dockers','r')
googlers = open('google1','r')
google_transcription_s = googlers.read()
docker_speakers_s = dockers.read()
google_trans = json.loads(google_transcription_s)
docker_speakers = json.loads(docker_speakers_s)
results = []
google_iter = 0
for speaker in docker_speakers:
error = 999999999
for i in range(google_iter, len(google_trans)):
new_error = abs(float(speaker["end"]) - google_trans[i]["end"])
if new_error <= error:
error = new_error
else:
results.append([
int(speaker["speaker"]),
' '.join([
trans["word"] for trans in google_trans[google_iter:i]
])
])
google_iter = i + 1
break
if google_iter != len(google_trans):
results[-1][1] += ' ' + ' '.join([trans["word"]
for trans in google_trans[google_iter:]])
return results
if __name__ == "__main__":
results = the_func()
for res in results:
print("{}: {}".format(res[0], res[1]))
'''