-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
replay.py
161 lines (129 loc) · 3.77 KB
/
replay.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# mimic("focus code"); actions.sleep(1); actions.speech.replay("/path/to/recording.flac")
from talon import actions, speech_system
from os import walk, path
import json
import re
delimiter = ","
expected = {}
accepted = 0
match_expected = 0
res = ""
filename = ""
def store_results():
out_file = path.join(actions.path.user_home(), "Downloads", "replay.csv")
with open(out_file, "a", encoding="utf-8") as f:
f.write(res)
def read_expected(dir):
expected_file = path.join(dir, "expected.json")
try:
with open(expected_file, encoding="utf-8") as f:
return json.load(f)
except Exception:
return {}
def get_spoken_phrase_from_file_name(filename: str) -> str:
if re.match(r"^\d+-", filename):
return filename.split("-")[1]
return filename.split("-")[0]
def on_pre_phrase(phrase):
global accepted, match_expected, res
spoken = " ".join(phrase["phrase"])
if spoken:
accepted += 1
else:
spoken = "[REJECTED]"
if expected:
if filename not in expected:
print("--- MISSING EXPECTED: {filename}")
else:
ext = expected[filename]
res += f"{ext}{delimiter}"
if ext == spoken:
match_expected += 1
else:
res += spoken
else:
res += spoken
phrase["phrase"] = []
if "parsed" in phrase:
phrase["parsed"]._sequence = []
def replay_files(files):
global res, filename
speech_system.register("pre:phrase", on_pre_phrase)
res += f"Filename{delimiter}Original{delimiter}"
if expected:
res += f"Expected{delimiter}"
res += f"{speech_system.engine.engine}\n"
for file in files:
filename = path.basename(file)[:-5]
# print(f'"{filename}": "",')
phrase = get_spoken_phrase_from_file_name(filename)
res += f"{filename}{delimiter}{phrase}{delimiter}"
actions.speech.replay(file)
res += "\n"
res += f"> Accepted {accepted} / {len(files)}\n"
if expected:
res += f"> Expected {match_expected} / {len(files)}\n"
res += "\n"
store_results()
print(f"Accepted {accepted} / {len(files)}\n")
print(f"Expected {match_expected} / {len(files)}\n")
speech_system.unregister("pre:phrase", on_pre_phrase)
def replay_dir(dir):
global expected
expected = read_expected(dir)
for dirpath, dirnames, filenames in walk(dir):
filenames = [path.join(dirpath, f) for f in filenames if f.endswith(".flac")]
replay_files(filenames)
# replay_dir("C:\\Users\\andre\\AppData\\Roaming\\talon\\rejects\\rejected with speech")
# replay_dir("C:\\Users\\andre\\AppData\\Roaming\\talon\\rejects\\rejected only noises")
# replay_dir("C:\\Users\\andre\\AppData\\Roaming\\talon\\recordings d problems")
# replay_files(
# [
# "C:\\Users\\andre\AppData\\Roaming\\talon\\recordings d problems\\gust-8jKb5cdq.flac"
# ]
# )
# Rejected with speech (-604)
# b108: 202 / 202
# D-20: 64 / 202
# Rejected only noises (-604)
# b108: 71 / 500
# D-20: 1 / 500
# Problems (-604)
# b108: 73 / 104
# D-20: 64 / 104
# Rejected with speech (-596)
# b108: 202 / 202
# D-28: 33 / 202
# D-19: 63 / 202
# D-11: 109 / 202
# D-06: 109 / 202
# Rejected only noises (-596)
# b108: 71 / 500
# D-28: 1 / 500
# D-19: 1 / 500
# D-11: 4 / 500
# D-06: 4 / 500
# Problems (-596)
# b108: 70 / 79
# D-28: 21 / 79
# D-19: 46 / 79
# D-11: 43 / 79
# D-06: 43 / 79
# Rejected with speech (attempted hotfix)
# b108: 198 / 202
# D-28: 162 / 202
# D-19: 184 / 202
# D-11: 178 / 202
# D-06: 178 / 202
# Rejected only noises (attempted hotfix)
# b108: 23 / 500
# D-28: 8 / 500
# D-19: 10 / 500
# D-11: 8 / 500
# D-06: 8 / 500
# Problems (attempted hotfix)
# b108: 56 / 79
# D-28: 30 / 79
# D-19: 42 / 79
# D-11: 40 / 79
# D-06: 40 / 79