From 8307a16bdcca8804043f879faa96ef5235c5e3e1 Mon Sep 17 00:00:00 2001 From: an-lee Date: Mon, 5 Aug 2024 11:59:26 +0800 Subject: [PATCH] Fix azure ai transcription handler (#931) * fix azure ai transcription handler * refactor --- enjoy/src/renderer/hooks/use-transcribe.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/enjoy/src/renderer/hooks/use-transcribe.tsx b/enjoy/src/renderer/hooks/use-transcribe.tsx index 464d3007..57205679 100644 --- a/enjoy/src/renderer/hooks/use-transcribe.tsx +++ b/enjoy/src/renderer/hooks/use-transcribe.tsx @@ -387,14 +387,14 @@ export const useTranscribe = () => { ); reco.stopContinuousRecognitionAsync(); - const transcript = results - .map((result) => result.DisplayText) - .join(" ") - .trim(); - const timeline: Timeline = []; results.forEach((result) => { + if (!result.DisplayText) return; + const best = take(sortedUniqBy(result.NBest, "Confidence"), 1)[0]; + if (!best.Words) return; + if (!best.Confidence || best.Confidence < 0.5) return; + const firstWord = best.Words[0]; const lastWord = best.Words[best.Words.length - 1]; @@ -407,6 +407,11 @@ export const useTranscribe = () => { }); }); + const transcript = timeline + .map((result) => result.text) + .join(" ") + .trim(); + resolve({ engine: "azure", model: "whisper",