mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 06:54:28 +00:00
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:
@@ -86,6 +86,7 @@ export const assetInfoSchema = z.object({
|
||||
type: z.string(),
|
||||
targetType: z.string().optional().nullable(),
|
||||
status: z.string(),
|
||||
mediaType: z.string().nullable().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
|
||||
latestChildren: z.array(childPreviewSchema).optional(),
|
||||
preview: previewInfoSchema.nullable().optional(),
|
||||
|
||||
@@ -26,6 +26,7 @@ export * from './search'
|
||||
export * from './share'
|
||||
export * from './skill'
|
||||
export * from './team'
|
||||
export * from './transcript'
|
||||
export * from './upload'
|
||||
export * from './user-metadata'
|
||||
export * from './versionStack'
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const transcriptLanguageCodeSchema = z.string().regex(/^[a-z]{2,3}$/)
|
||||
|
||||
export type SavedTranscriptLanguages = { languages: string[] }
|
||||
|
||||
export type TranscriptSegment = {
|
||||
id: string
|
||||
startMs: number
|
||||
endMs: number
|
||||
text: string
|
||||
}
|
||||
|
||||
export type SavedTranscript = {
|
||||
id: string
|
||||
language: string
|
||||
segments: TranscriptSegment[]
|
||||
}
|
||||
|
||||
export const generateTranscriptRequestSchema = z.object({
|
||||
language: transcriptLanguageCodeSchema.optional(),
|
||||
})
|
||||
|
||||
export const updateTranscriptSegmentRequestSchema = z.strictObject({
|
||||
text: z.string().refine((text) => !text.includes('\0')),
|
||||
})
|
||||
|
||||
export const transcriptLanguagesSchema = z.object({
|
||||
model: z.string().min(1),
|
||||
languages: z.array(z.object({ code: transcriptLanguageCodeSchema, name: z.string().min(1) })),
|
||||
})
|
||||
|
||||
interface TranscriptVideoProxy {
|
||||
key?: string
|
||||
resolution?: string
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
|
||||
export function selectTranscriptVideoProxyKey(
|
||||
media?: { videoTranscodes?: TranscriptVideoProxy[]; videoPreview?: { key?: string } } | null,
|
||||
): string | undefined {
|
||||
let selectedKey: string | undefined
|
||||
let smallestArea = Infinity
|
||||
for (const proxy of media?.videoTranscodes ?? []) {
|
||||
if (!proxy.key || proxy.key === media?.videoPreview?.key || proxy.resolution === '180p') {
|
||||
continue
|
||||
}
|
||||
|
||||
const area = proxy.width > 0 && proxy.height > 0 ? proxy.width * proxy.height : Infinity
|
||||
if (area < smallestArea) {
|
||||
selectedKey = proxy.key
|
||||
smallestArea = area
|
||||
}
|
||||
}
|
||||
return selectedKey
|
||||
}
|
||||
|
||||
export const transcriptionErrors = {
|
||||
noAudio: 'The video does not contain an audio track',
|
||||
noProxy: 'A completed full video proxy is required to generate transcripts',
|
||||
tooLarge: 'Audio exceeds the embedding server upload limit',
|
||||
} as const
|
||||
|
||||
export type GenerateTranscriptResult =
|
||||
| { kind: 'queued' | 'busy'; taskId: string }
|
||||
| { kind: 'existing'; transcriptId: string; language: string }
|
||||
| { kind: 'no_speech' }
|
||||
|
||||
export type TranscriptJobStatus =
|
||||
| { status: 'pending' | 'processing' | 'completed' | 'no_speech'; taskId: string }
|
||||
| { status: 'failed'; taskId: string; reason: keyof typeof transcriptionErrors | 'unknown' }
|
||||
Reference in New Issue
Block a user