This commit is contained in:
yumoqing 2025-11-06 15:16:03 +08:00
parent d88483d341
commit ee1f718152

View File

@ -40,22 +40,17 @@ class MyLongTask(LongTasks):
return await f(model, fpath)
def transcribe(self, model, fpath):
segments, info = model.transcribe(fpath, beam_size=5)
segments, info = model.transcribe(fpath, beam_size=5, word_timestamps=True)
segments = list(segments)
debug(f'{segments=}')
words = []
for s in segments:
if s.words:
words.append([[word.start, word.end, word.word] for word in s.words])
return {
'language': info.language,
'language_probability': info.language_probability,
'content': ' '.join([s.text for s in segments]),
'words': words,
'segments': [[segment.start,
segment.end,
segment.text
] for segment in segments]
'segments': [[s.start,
s.end,
s.text,
[[w.start, w.end, w.word] for w in s.words]
] for s in segments]
}