Results_to_sentence : Give timestamps for each sentence #81
Unanswered
Abdurrafey-Siddiqui
asked this question in
Q&A
Replies: 1 comment
-
Try this: def captionize_whisper_result(result, max_line_length=300):
"""
Convert output from stable-whipesr to a list of captions.
It performs the following steps:
* Remove all lines that are made of nothing but symbols. For example ♪, !, ?
* Merge timestamped words into lines.
* For each line, remove starting and ending whitespaces.
inputs
result_segments: Output segments from the stable-whipesr model.
max_line_length: The maximal number of characters in the line. We recommend 300.
"""
result_segments = result.ori_dict['segments']
# Remove lines that are nothing but symbols.
timed_word_list = []
bad_segments = ["!", "?", "♪♪", "♪"]
for segment in result_segments:
if segment['text'] in bad_segments:
continue
timed_word_list += segment['words']
if timed_word_list == []: # Why are you giving an empty transcript?
return []
# Merge timestamped words into lines.
new_segments = [_copy_timed_word(timed_word_list[0])]
current_segment_length = 0
for timed_word in timed_word_list[1:]:
segment = new_segments[-1]
word = timed_word['word']
assert len(word) < max_line_length, f"Error: word length exceeds maximal caption line length {max_line_length}. The offending word is {word}."
if (len(segment) + len(word) > max_line_length) or _check_line_ending(segment['word']): # new caption line
new_segments.append(_copy_timed_word(timed_word))
else:
segment['word'] += word
segment['end'] = timed_word['end']
# For each line, remove starting and ending whitespaces.
for segment in new_segments:
segment['word'] = segment['word'].strip()
return new_segments |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, is there a way to make the AI group the words according to their sentences? Meaning from start of the sentence to the end. For now some of the words at the end of a long sentence get transferred to the next timestamps (in the SRT file). I'm trying to get the whole sentence (even if it is long) be grouped under one timestamp. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions