Playing around with converting times to milliseconds for elan
@@ -9,6 +9,7 @@ import torch
from itertools import groupby
import pympi
import string
+from pprint import pprint
from transformers import (
Wav2Vec2ForCTC,
@@ -132,6 +133,7 @@ class HFTransformersTranscription(BaseTranscription):
# Add times to ids
duration_sec = input_values.shape[1] / sample_rate
+ print('time per token:', duration_sec)
time_from_index = lambda index: index / len(predicted_ids) * duration_sec
generate_timestamps = lambda item: (time_from_index(item[0]), item[1])
@@ -152,9 +154,6 @@ class HFTransformersTranscription(BaseTranscription):
split_ids_w_time = [list(group)
for key, group in word_groups if not key]
- print('words:', words)
- print(split_ids_w_time, flush=True)
-
# make sure that there are the same number of id-groups as words.
# Otherwise something is wrong
assert len(split_ids_w_time) == len(words)
@@ -166,6 +165,10 @@ class HFTransformersTranscription(BaseTranscription):
word_start_times.append(min(_times))
word_end_times.append(max(_times))
+ print('words:', words)
+ pprint(word_start_times)
+ pprint(word_end_times)
+ print(flush=True)
return words, word_start_times, word_end_times
def _save_transcription(self, transcription: str) -> None:
@@ -180,7 +183,9 @@ class HFTransformersTranscription(BaseTranscription):
tier = 'spk1' # No idea what this is for
result.add_tier(tier)
+ to_millis = lambda seconds: int(seconds * 1000)
for word, start, end in zip(*utterances):
+ start, end = to_millis(start), to_millis(end)
result.add_annotation(id_tier=tier, start=start, end=end, value=word)
pympi.Elan.to_eaf(self.elan_path, result)
