feat(video): add video transcripts (#559)

* feat(video): generate transcripts with the local embedding server

* feat(video): show saved transcripts in the player

* fix(video): preserve transcript seek timestamps

* fix(video): refine transcript viewing and generation

* feat(video): resize transcripts and follow playback earlier

* fix(video): animate transcript playback scrolling

* fix(video): transcribe from the smallest full proxy

* fix(video): refine the sync to playback button

* feat(video): edit transcript segment text inline

* fix(video): keep transcript segment highlighted over edit button

* docs(video): note embedding server version for transcripts
This commit is contained in:
Yiling-J
2026-12-04 13:49:25 +08:00
committed by GitHub
parent e420f03b35
commit d3899d1257
69 changed files with 7635 additions and 174 deletions
@@ -0,0 +1,66 @@
import { getGemmaOpenAiBaseUrl } from '@shumai/core/src/search/gemma-embedding-endpoint'
import { transcriptLanguageCodeSchema, transcriptLanguagesSchema } from '@shumai/dtos'
import { z } from 'zod'
const transcriptEndpoint = () => `${getGemmaOpenAiBaseUrl()}/audio/transcriptions`
export function isLocalTranscriptionEnabled(): boolean {
return process.env.EMBEDDING_PROVIDER === 'gemma-embedding-2-openai'
}
export async function listLocalTranscriptionLanguages() {
const response = await fetch(`${transcriptEndpoint()}/languages`, {
signal: AbortSignal.timeout(5_000),
})
if (!response.ok) throw new Error(`Transcription languages endpoint returned ${response.status}`)
return transcriptLanguagesSchema.parse(await response.json())
}
const transcriptResponseSchema = z
.object({
language: transcriptLanguageCodeSchema.nullable(),
segments: z.array(
z
.object({ start: z.number().min(0), end: z.number().min(0), text: z.string().min(1) })
.refine((segment) => segment.end >= segment.start && segment.end < 2_147_483),
),
})
.refine((result) => result.language !== null || result.segments.length === 0)
export class LocalTranscriptionError extends Error {
constructor(readonly status: number) {
super(`Transcription server returned HTTP ${status}`)
}
}
export async function transcribeLocalAudio({
audio,
language,
model,
signal,
}: {
audio: Blob
language: string | null
model: string
signal?: AbortSignal
}) {
const form = new FormData()
form.set('file', audio, 'audio.wav')
form.set('model', model)
form.set('response_format', 'verbose_json')
if (language) form.set('language', language)
const timeout = AbortSignal.timeout(90 * 60 * 1000)
const response = await fetch(transcriptEndpoint(), {
method: 'POST',
body: form,
redirect: 'error',
timeout: false,
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
})
if (!response.ok) {
await response.body?.cancel()
throw new LocalTranscriptionError(response.status)
}
return transcriptResponseSchema.parse(await response.json())
}