summaryrefslogtreecommitdiff
path: root/asr.py
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2025-08-22 17:51:28 -0400
committervin <git@vineetk.net>2025-08-22 17:51:28 -0400
commit87e22ba091dae8d81da690a405c15b453c61a0c5 (patch)
tree504ba3549025a30623614e82c901ae253960ea90 /asr.py
parentcc2d05f027ef2672a96d1b780e5af44b03375af8 (diff)
add formatting
Diffstat (limited to 'asr.py')
-rw-r--r--asr.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/asr.py b/asr.py
index e598e4b..54b83eb 100644
--- a/asr.py
+++ b/asr.py
@@ -8,10 +8,19 @@ from tqdm import tqdm
8 8
9# converts TimestampedResult to JSON-serializable dictionary 9# converts TimestampedResult to JSON-serializable dictionary
10def result_to_dict(result, offset_seconds): 10def result_to_dict(result, offset_seconds):
11 token_map = [
12 [token, round(ts + offset_seconds, 2)]
13 for token, ts in zip(result.tokens, result.timestamps)
14 ]
15
16 start_time = token_map[0][1] if token_map else offset_seconds
17 end_time = token_map[-1][1] if token_map else offset_seconds
18
11 return { 19 return {
12 "text": result.text, 20 "text": result.text,
13 "tokens": result.tokens, 21 "start_time": start_time,
14 "timestamps": [ts + offset_seconds for ts in result.timestamps] 22 "end_time": end_time,
23 "token_map": token_map
15 } 24 }
16 25
17def main(input_file, output_file): 26def main(input_file, output_file):
@@ -56,7 +65,12 @@ def main(input_file, output_file):
56 transcript_results = model.recognize(np.copy(chunk)) 65 transcript_results = model.recognize(np.copy(chunk))
57 66
58 if transcript_results: 67 if transcript_results:
59 for result in transcript_results: 68 if not isinstance(transcript_results, list):
69 results_list = [transcript_results]
70 else:
71 results_list = transcript_results
72
73 for result in results_list:
60 full_transcript_data.append(result_to_dict(result, chunk_offset_seconds)) 74 full_transcript_data.append(result_to_dict(result, chunk_offset_seconds))
61 except Exception as e: 75 except Exception as e:
62 print(f" Error processing chunk {i + 1}: {e}") 76 print(f" Error processing chunk {i + 1}: {e}")