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:
@@ -0,0 +1,90 @@
|
||||
import { zValidator } from '@hono/zod-validator'
|
||||
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
|
||||
import { transcriptService } from '@shumai/core/src/transcript/transcript'
|
||||
import type { User } from '@shumai/db'
|
||||
import {
|
||||
generateTranscriptRequestSchema,
|
||||
transcriptLanguageCodeSchema,
|
||||
updateTranscriptSegmentRequestSchema,
|
||||
} from '@shumai/dtos'
|
||||
import { Hono } from 'hono'
|
||||
import { z } from 'zod'
|
||||
|
||||
const route = new Hono<{ Variables: { user: User } }>()
|
||||
.get('/transcription/languages', async (c) => c.json(await transcriptService.listLanguages()))
|
||||
.get('/files/:fileId/transcripts', async (c) => {
|
||||
const assetId = c.req.param('fileId')
|
||||
await authzService.hasPermission({
|
||||
user: c.get('user'),
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Asset,
|
||||
id: assetId,
|
||||
})
|
||||
return c.json(await transcriptService.listSavedLanguages(assetId))
|
||||
})
|
||||
.get(
|
||||
'/files/:fileId/transcripts/:language',
|
||||
zValidator('param', z.object({ fileId: z.string(), language: transcriptLanguageCodeSchema })),
|
||||
async (c) => {
|
||||
const { fileId, language } = c.req.valid('param')
|
||||
await authzService.hasPermission({
|
||||
user: c.get('user'),
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Asset,
|
||||
id: fileId,
|
||||
})
|
||||
return c.json(await transcriptService.getSavedTranscript(fileId, language))
|
||||
},
|
||||
)
|
||||
.patch(
|
||||
'/files/:fileId/transcripts/:language/segments/:segmentId',
|
||||
zValidator(
|
||||
'param',
|
||||
z.object({
|
||||
fileId: z.string(),
|
||||
language: transcriptLanguageCodeSchema,
|
||||
segmentId: z.string(),
|
||||
}),
|
||||
),
|
||||
zValidator('json', updateTranscriptSegmentRequestSchema),
|
||||
async (c) => {
|
||||
const { fileId, language, segmentId } = c.req.valid('param')
|
||||
await authzService.hasPermission({
|
||||
user: c.get('user'),
|
||||
permission: Permission.Edit,
|
||||
type: ResourceType.Asset,
|
||||
id: fileId,
|
||||
})
|
||||
const { text } = c.req.valid('json')
|
||||
return c.json(await transcriptService.updateSegmentText(fileId, language, segmentId, text))
|
||||
},
|
||||
)
|
||||
.post(
|
||||
'/files/:fileId/transcripts',
|
||||
zValidator('json', generateTranscriptRequestSchema),
|
||||
async (c) => {
|
||||
const assetId = c.req.param('fileId')
|
||||
await authzService.hasPermission({
|
||||
user: c.get('user'),
|
||||
permission: Permission.Edit,
|
||||
type: ResourceType.Asset,
|
||||
id: assetId,
|
||||
})
|
||||
|
||||
const { language } = c.req.valid('json')
|
||||
const result = await transcriptService.generate(assetId, language ?? null)
|
||||
return c.json(result, result.kind === 'queued' || result.kind === 'busy' ? 202 : 200)
|
||||
},
|
||||
)
|
||||
.get('/files/:fileId/transcription-status', async (c) => {
|
||||
const assetId = c.req.param('fileId')
|
||||
await authzService.hasPermission({
|
||||
user: c.get('user'),
|
||||
permission: Permission.Edit,
|
||||
type: ResourceType.Asset,
|
||||
id: assetId,
|
||||
})
|
||||
return c.json(await transcriptService.getStatus(assetId))
|
||||
})
|
||||
|
||||
export default route
|
||||
Reference in New Issue
Block a user