From d051bf2691703b62d75c9c9f7462c35680943267 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 10 Mar 2024 11:49:05 +0800 Subject: [PATCH] Transcript: Use Whisper response without LF. (#163). v5.14.5 --- DEVELOPER.md | 2 ++ platform/transcript.go | 22 ++-------------------- ui/src/pages/ScenarioTranscript.js | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/DEVELOPER.md b/DEVELOPER.md index 32c1f9f8..9267680f 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -1144,6 +1144,7 @@ The following are the update records for the SRS Stack server. * HLS: Set m3u8 expire time to 1s for LLHLS. v5.14.4 * HLS: Use fast cache for HLS config. v5.14.4 * Transcript: Support set the force_style for overlay subtitle. v5.14.5 + * Transcript: Use Whisper response without LF. (#163). v5.14.5 * v5.13: * Fix bug for vlive and transcript. v5.13.1 * Support AWS Lightsail install script. v5.13.2 @@ -1178,6 +1179,7 @@ The following are the update records for the SRS Stack server. * Release stable version and support debugging. [v5.13.28](https://github.com/ossrs/srs-stack/releases/tag/v5.13.28) * HLS: Set m3u8 expire time to 1s for LLHLS. v5.13.29 * Transcript: Support set the force_style for overlay subtitle. v5.13.30 + * Transcript: Use Whisper response without LF. (#163). v5.13.31 * v5.12 * Refine local variable name conf to config. v5.12.1 * Add forced exit on timeout for program termination. v5.12.1 diff --git a/platform/transcript.go b/platform/transcript.go index 4e3b62d7..61fd641c 100644 --- a/platform/transcript.go +++ b/platform/transcript.go @@ -1646,26 +1646,8 @@ func (v *TranscriptTask) DriveAsrQueue(ctx context.Context) error { srt.WriteString(fmt.Sprintf("%02d:%02d:%02d,%03d\n", int(e.Hours()), int(e.Minutes())%60, int(e.Seconds())%60, int(e.Milliseconds())%1000)) - // Limit each line of text, write a new line if exceed. - lineMaxSize := 45 - words := strings.Split(srtSegment.Text, " ") - var current string - for _, word := range words { - if word == "" { - continue - } - - if len(current)+len(word) < lineMaxSize { - current += word + " " - continue - } - - srt.WriteString(fmt.Sprintf("%v\n", current)) - current = word + " " - } - if current != "" { - srt.WriteString(fmt.Sprintf("%v\n", current)) - } + // Write the subtitle text. + srt.WriteString(fmt.Sprintf("%v\n", srtSegment.Text)) // Insert a new line. srt.WriteString("\n") diff --git a/ui/src/pages/ScenarioTranscript.js b/ui/src/pages/ScenarioTranscript.js index 4df0a8cb..1a5b5b81 100644 --- a/ui/src/pages/ScenarioTranscript.js +++ b/ui/src/pages/ScenarioTranscript.js @@ -192,6 +192,9 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default size: Number(segment.size / 1024.0), eac: Number(segment.eac), asrc: Number(segment.asrc), + // The max length of the subtitle text in asrs array. + asrsMaxLength: Math.max(...segment.asrs.map(asr => asr.text.length)), + asrsMaxWords: Math.max(...segment.asrs.map(asr => asr.text.split(' ').length)), // Rules: // 1. Always allow to clear the first segment, that is only one segment in the queue. // 2. Prevent the first segment from clearing subtitles, as it may have already been added @@ -225,6 +228,9 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default eac: Number(segment.eac), asrc: Number(segment.asrc), olc: Number(segment.olc), + // The max length of the subtitle text in asrs array. + asrsMaxLength: Math.max(...segment.asrs.map(asr => asr.text.length)), + asrsMaxWords: Math.max(...segment.asrs.map(asr => asr.text.split(' ').length)), }; }); setOverlayQueue(queue); @@ -420,6 +426,7 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default Duration EAC ASRC + Segments Size Text {t('transcript.action')} @@ -433,6 +440,9 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default {`${segment.duration.toFixed(1)}`}s {`${segment.eac.toFixed(1)}`}ms {`${segment.asrc.toFixed(1)}`}ms + + {segment.asrs.length}/{segment.asrsMaxLength}/{segment.asrsMaxWords} + {`${segment.size.toFixed(1)}`}KB {segment.asr} @@ -464,6 +474,7 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default EAC ASRC OLC + Segments Size Text @@ -478,6 +489,9 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default {`${segment.asrc.toFixed(1)}`}ms {`${segment.olc.toFixed(1)}`}ms {`${segment.size.toFixed(1)}`}MB + + {segment.asrs.length}/{segment.asrsMaxLength}/{segment.asrsMaxWords} + {segment.asr} ; })}