-
Hello, I’m facing an issue with the following code: text_batch = get_text_batch(result.segments)
translated_batch = translates(translate_to=translate_to, text_batch=text_batch)
result.segments = replace_text_batch(segments=result.segments, translated_batch=translated_batch)
def replace_text_batch(segments, translated_batch):
if len(segments) != len(translated_batch):
raise ValueError("Le nombre de segments et de textes traduits doit être identique.")
for i, segment in enumerate(segments):
segment.text = translated_batch[i]
return segments This code takes the text content of The replacement works as expected: result.split_by_length(max_words=10)
result.split_by_duration(max_dur=0.85)
result.to_srt_vtt(
filepath=srt_path,
segment_level=True, # Include segment-level timestamps
word_level=True, # Include word-level timestamps
min_dur=0.2, # Minimum duration for segments/words
strip=True # Remove spaces around text
) these operations fail. It seems that my Request for HelpDoes anyone know why this might be happening? I suspect the
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Which version of Stable-ts are you using? This line should raise an segment.text = translated_batch[i] This is because stable-ts/stable_whisper/result.py Lines 440 to 444 in c176ecd You have to replace the individual words of the segment in order to change the text of the segment itself: def replace_text_batch(segments, translated_batch):
if len(segments) != len(translated_batch):
raise ValueError("Le nombre de segments et de textes traduits doit être identique.")
for i, segment in enumerate(segments):
translated_words = translated_batch[i].split(' ')
assert len(segment.words) == len(translated_words)
for word, new_word in zip(segment, translated_words):
word.word = new_word
return segments |
Beta Was this translation helpful? Give feedback.
Which version of Stable-ts are you using?
This line should raise an
AttributeError
in the latest version:This is because
text
is a property of the all the words in thesegment
for results with word-timestamps.stable-ts/stable_whisper/result.py
Lines 440 to 444 in c176ecd
You have to replace the individual words of the segment in order to change the text of the segment itself: