mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 14:34:40 +00:00
fix(video): transcribe from the smallest full proxy
This commit is contained in:
@@ -2938,6 +2938,7 @@ export class AssetService {
|
||||
type: a.type,
|
||||
targetType: a.type === AssetType.symlink ? a.target?.type : null,
|
||||
status: latestVersion.status,
|
||||
mediaType: latestVersion.mediaType,
|
||||
proxyType,
|
||||
latestChildren,
|
||||
preview,
|
||||
|
||||
@@ -10,6 +10,17 @@ describe('TranscriptService', () => {
|
||||
let projectId: string
|
||||
const model = 'whisper-tiny'
|
||||
const segments = [{ startMs: 125, endMs: 1425, text: 'Original segment' }]
|
||||
const media: PrismaJson.MediaInfo = {
|
||||
proxyType: 'video',
|
||||
duration: 2,
|
||||
filesize: 0,
|
||||
frames: 50,
|
||||
imageTranscodes: [],
|
||||
videoTranscodes: [{ key: 'files/transcript-video-480p.mp4', width: 854, height: 480 }],
|
||||
finishedAt: '2026-01-01T00:00:00Z',
|
||||
metadata: null,
|
||||
original: null,
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.stubEnv('EMBEDDING_PROVIDER', 'gemma-embedding-2-openai')
|
||||
@@ -24,6 +35,7 @@ describe('TranscriptService', () => {
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
mediaType: 'video/mp4',
|
||||
media,
|
||||
project: { connect: { id: projectId } },
|
||||
storageKey: { create: { key: 'files/transcript-video.mp4' } },
|
||||
},
|
||||
@@ -146,6 +158,43 @@ describe('TranscriptService', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('requires completed transcoding and a full proxy before queuing', async () => {
|
||||
await prisma.asset.update({ where: { id: assetId }, data: { status: 'processing' } })
|
||||
await expect(transcriptService.generate(assetId, null)).rejects.toMatchObject({ status: 400 })
|
||||
|
||||
const preview = { key: 'files/transcript-video-180p.mp4', width: 320, height: 180 }
|
||||
await prisma.asset.update({
|
||||
where: { id: assetId },
|
||||
data: {
|
||||
status: 'processed',
|
||||
media: { ...media, videoTranscodes: [], videoPreview: preview },
|
||||
},
|
||||
})
|
||||
await expect(transcriptService.generate(assetId, null)).rejects.toMatchObject({
|
||||
status: 400,
|
||||
message: transcriptionErrors.noProxy,
|
||||
})
|
||||
expect(await prisma.workflowTask.count({ where: { assetId } })).toBe(0)
|
||||
})
|
||||
|
||||
it('rejects an audio-only proxy even when the file was uploaded with a video MIME type', async () => {
|
||||
await prisma.asset.update({
|
||||
where: { id: assetId },
|
||||
data: {
|
||||
media: {
|
||||
...media,
|
||||
proxyType: 'audio',
|
||||
videoTranscodes: [{ key: 'files/transcript-video-audio-proxy.mp4', width: 0, height: 0 }],
|
||||
},
|
||||
},
|
||||
})
|
||||
await expect(transcriptService.generate(assetId, null)).rejects.toMatchObject({
|
||||
status: 400,
|
||||
message: transcriptionErrors.noProxy,
|
||||
})
|
||||
expect(await prisma.workflowTask.count({ where: { assetId } })).toBe(0)
|
||||
})
|
||||
|
||||
it('persists languages independently and preserves saved text on replay and requests for an existing language', async () => {
|
||||
const enTaskId = await generateAndStart('en')
|
||||
const first = { taskId: enTaskId, assetId, model, language: 'en', segments }
|
||||
@@ -204,21 +253,24 @@ describe('TranscriptService', () => {
|
||||
expect(await prisma.assetTranscript.count({ where: { assetId } })).toBe(0)
|
||||
})
|
||||
|
||||
it('preserves a failed job and translates known failure reasons', async () => {
|
||||
const taskId = await generateAndStart(null)
|
||||
await prisma.workflowTask.update({
|
||||
where: { id: taskId },
|
||||
data: {
|
||||
it.each(['tooLarge', 'noProxy'] as const)(
|
||||
'preserves a failed job with reason %s',
|
||||
async (reason) => {
|
||||
const taskId = await generateAndStart(null)
|
||||
await prisma.workflowTask.update({
|
||||
where: { id: taskId },
|
||||
data: {
|
||||
status: 'failed',
|
||||
output: { error: transcriptionErrors[reason] },
|
||||
},
|
||||
})
|
||||
await transcriptService.saveResult({ taskId, assetId, model, language: 'en', segments })
|
||||
expect(await transcriptService.getStatus(assetId)).toEqual({
|
||||
taskId,
|
||||
status: 'failed',
|
||||
output: { error: transcriptionErrors.tooLarge },
|
||||
},
|
||||
})
|
||||
await transcriptService.saveResult({ taskId, assetId, model, language: 'en', segments })
|
||||
expect(await transcriptService.getStatus(assetId)).toEqual({
|
||||
taskId,
|
||||
status: 'failed',
|
||||
reason: 'tooLarge',
|
||||
})
|
||||
expect(await prisma.assetTranscript.count({ where: { assetId } })).toBe(0)
|
||||
})
|
||||
reason,
|
||||
})
|
||||
expect(await prisma.assetTranscript.count({ where: { assetId } })).toBe(0)
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
type WorkflowTask,
|
||||
} from '@shumai/db'
|
||||
import {
|
||||
selectTranscriptVideoProxyKey,
|
||||
transcriptionErrors,
|
||||
type GenerateTranscriptResult,
|
||||
type SavedTranscript,
|
||||
@@ -81,13 +82,15 @@ export class TranscriptService {
|
||||
status: 'processed',
|
||||
isDeleted: false,
|
||||
mediaType: { startsWith: 'video/' },
|
||||
storageKey: { status: 'active', isArchived: false },
|
||||
},
|
||||
select: { project: { select: { id: true, teamId: true } } },
|
||||
select: { media: true, project: { select: { id: true, teamId: true } } },
|
||||
})
|
||||
if (!asset?.project) {
|
||||
throw new HTTPException(400, { message: 'Transcripts require a processed video file' })
|
||||
}
|
||||
if (!selectTranscriptVideoProxyKey(asset.media)) {
|
||||
throw new HTTPException(400, { message: transcriptionErrors.noProxy })
|
||||
}
|
||||
|
||||
const active = await tx.workflowTask.findFirst({
|
||||
where: { assetId, type, status: { in: ['pending', 'processing'] } },
|
||||
@@ -138,7 +141,9 @@ export class TranscriptService {
|
||||
? 'tooLarge'
|
||||
: error.includes(transcriptionErrors.noAudio)
|
||||
? 'noAudio'
|
||||
: 'unknown'
|
||||
: error.includes(transcriptionErrors.noProxy)
|
||||
? 'noProxy'
|
||||
: 'unknown'
|
||||
return { status: 'failed', taskId: task.id, reason }
|
||||
}
|
||||
const transcript = task.output?.transcription
|
||||
|
||||
Reference in New Issue
Block a user