mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 15:14:10 +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,50 @@
|
||||
import { logger } from '@shumai/core/src/logger'
|
||||
import type { WorkflowTask } from '@shumai/db'
|
||||
import { ApplicationFailure } from '@shumai/workflow-core'
|
||||
import { deleteS3ObjectActivity } from '../activities/ai'
|
||||
import {
|
||||
extractTranscriptAudioActivity,
|
||||
saveTranscriptActivity,
|
||||
transcribeAudioActivity,
|
||||
} from '../activities/transcription'
|
||||
|
||||
export async function transcribeVideoWorkflow(task: WorkflowTask): Promise<void> {
|
||||
const request = task.payload?.transcription
|
||||
if (!request) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Missing transcription request',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const taskId = task.id
|
||||
const assetId = task.assetId
|
||||
const audioKey = `temp/transcripts/${taskId}.wav`
|
||||
try {
|
||||
await extractTranscriptAudioActivity({ assetId, taskId, audioKey })
|
||||
const transcript = await transcribeAudioActivity({ taskId, audioKey, ...request })
|
||||
if (request.language && transcript.language && request.language !== transcript.language) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Transcription returned an unexpected language',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
await saveTranscriptActivity({
|
||||
taskId,
|
||||
assetId,
|
||||
model: request.model,
|
||||
language: transcript.language,
|
||||
segments: transcript.segments.map((segment) => ({
|
||||
startMs: Math.round(segment.start * 1000),
|
||||
endMs: Math.round(segment.end * 1000),
|
||||
text: segment.text,
|
||||
})),
|
||||
})
|
||||
} finally {
|
||||
try {
|
||||
await deleteS3ObjectActivity({ key: audioKey })
|
||||
} catch (error) {
|
||||
logger.error({ err: error, taskId, audioKey }, 'Failed to delete staged transcript audio')
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user