From 4ed1c695fe33c914885c747eb69ded9a2e7c9536 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Thu, 11 Jul 2024 21:14:07 +0800 Subject: [PATCH] fix "words" in json response --- whisper_fastapi.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/whisper_fastapi.py b/whisper_fastapi.py index 7dbf421..534d1ec 100644 --- a/whisper_fastapi.py +++ b/whisper_fastapi.py @@ -126,6 +126,7 @@ def stream_builder( language=language, task=task, initial_prompt=initial_prompt, + word_timestamps=True, ) print( "Detected language '%s' with probability %f" @@ -139,6 +140,8 @@ def stream_builder( pbar.update(end - last_pos) last_pos = end data = segment._asdict() + if data.get('words') is not None: + data["words"] = [i._asdict() for i in data["words"]] data["total"] = info.duration yield data