Skip to content

Commit

Permalink
Transcript: Use Whisper response without LF. (#163). v5.14.5
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Mar 10, 2024
1 parent 6b62ea6 commit d051bf2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
2 changes: 2 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 2 additions & 20 deletions platform/transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions ui/src/pages/ScenarioTranscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -420,6 +426,7 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default
<th>Duration</th>
<th title={t('transcript.eac')}>EAC</th>
<th title={t('transcript.asrc')}>ASRC</th>
<th>Segments</th>
<th>Size</th>
<th>Text</th>
<th>{t('transcript.action')}</th>
Expand All @@ -433,6 +440,9 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default
<td>{`${segment.duration.toFixed(1)}`}s</td>
<td>{`${segment.eac.toFixed(1)}`}ms</td>
<td>{`${segment.asrc.toFixed(1)}`}ms</td>
<td title={`There are ${segment.asrs.length} segments, max text length is ${segment.asrsMaxLength} bytes, max words is ${segment.asrsMaxWords}`}>
{segment.asrs.length}/{segment.asrsMaxLength}/{segment.asrsMaxWords}
</td>
<td>{`${segment.size.toFixed(1)}`}KB</td>
<td style={{textDecoration: segment.uca ? "line-through" : ''}}>{segment.asr}</td>
<td>
Expand Down Expand Up @@ -464,6 +474,7 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default
<th title={t('transcript.eac')}>EAC</th>
<th title={t('transcript.asrc')}>ASRC</th>
<th title={t('transcript.olc')}>OLC</th>
<th>Segments</th>
<th>Size</th>
<th>Text</th>
</tr>
Expand All @@ -478,6 +489,9 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default
<td>{`${segment.asrc.toFixed(1)}`}ms</td>
<td>{`${segment.olc.toFixed(1)}`}ms</td>
<td>{`${segment.size.toFixed(1)}`}MB</td>
<td title={`There are ${segment.asrs.length} segments, max text length is ${segment.asrsMaxLength} bytes, max words is ${segment.asrsMaxWords}`}>
{segment.asrs.length}/{segment.asrsMaxLength}/{segment.asrsMaxWords}
</td>
<td style={{textDecoration: segment.uca ? "line-through" : ''}}>{segment.asr}</td>
</tr>;
})}
Expand Down

0 comments on commit d051bf2

Please sign in to comment.