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,87 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { fileCard } from '../../helpers/files'
|
||||
import type { TranscriptJobStatus } from '@shumai/dtos'
|
||||
|
||||
test.use({ fileOptions: { mediaType: 'video' } })
|
||||
|
||||
test('selects a transcription language from the video context menu and tracks the job', async ({
|
||||
file,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, projectId, fileId, fileName } = file
|
||||
let status: TranscriptJobStatus = { taskId: 'previous-transcript', status: 'completed' }
|
||||
const expectedLanguages = ['zh', 'en']
|
||||
let submissions = 0
|
||||
await page.route('**/api/signup-info', async (route) => {
|
||||
const response = await route.fetch()
|
||||
await route.fulfill({ json: { ...(await response.json()), transcriptionEnabled: true } })
|
||||
})
|
||||
await page.route('**/api/transcription/languages', (route) =>
|
||||
route.fulfill({
|
||||
json: {
|
||||
model: 'whisper-tiny',
|
||||
languages: [
|
||||
{ code: 'en', name: 'English' },
|
||||
{ code: 'zh', name: 'Chinese' },
|
||||
],
|
||||
},
|
||||
}),
|
||||
)
|
||||
await page.route(`**/api/files/${fileId}/transcription-status`, (route) =>
|
||||
route.fulfill({ json: status }),
|
||||
)
|
||||
await page.route(`**/api/files/${fileId}/transcripts`, async (route) => {
|
||||
expect(route.request().postDataJSON()).toEqual({ language: expectedLanguages[submissions] })
|
||||
const taskId = `transcript-task-${++submissions}`
|
||||
status = { taskId, status: 'processing' }
|
||||
await route.fulfill({ status: 202, json: { kind: 'queued', taskId } })
|
||||
})
|
||||
|
||||
await expect
|
||||
.poll(() =>
|
||||
prisma.asset.findUnique({
|
||||
where: { id: fileId },
|
||||
select: { status: true, media: true },
|
||||
}),
|
||||
)
|
||||
.toMatchObject({ status: 'processed', media: { proxyType: 'video' } })
|
||||
await prisma.asset.update({ where: { id: fileId }, data: { status: 'processing' } })
|
||||
const [signupInfo] = await Promise.all([
|
||||
page.waitForResponse('**/api/signup-info'),
|
||||
page.goto(`/projects/${projectId}`),
|
||||
])
|
||||
expect(await signupInfo.json()).toMatchObject({ transcriptionEnabled: true })
|
||||
const action = page.getByRole('menuitem', { name: 'Generate Transcripts' })
|
||||
await fileCard(page, fileName).click({ button: 'right' })
|
||||
await expect(action).toBeDisabled()
|
||||
await prisma.asset.update({ where: { id: fileId }, data: { status: 'processed' } })
|
||||
await page.reload()
|
||||
const openDialog = async () => {
|
||||
await fileCard(page, fileName).click({ button: 'right' })
|
||||
await action.click()
|
||||
}
|
||||
await openDialog()
|
||||
const dialog = page.getByRole('dialog', { name: 'Generate Transcripts' })
|
||||
const language = dialog.getByRole('combobox', { name: 'Language' })
|
||||
const generate = dialog.getByRole('button', { name: 'Generate', exact: true })
|
||||
await expect(dialog.getByRole('status')).toHaveText('Transcript generated.')
|
||||
await expect(language).toHaveValue('Auto')
|
||||
await language.fill('Chi')
|
||||
await dialog.getByRole('option', { name: 'Chinese' }).click()
|
||||
await expect(language).toHaveValue('Chinese')
|
||||
await generate.click()
|
||||
await expect(dialog.getByRole('status')).toHaveText('Generating transcript…')
|
||||
await dialog.getByRole('button', { name: 'Close', exact: true }).click()
|
||||
await expect(dialog).toBeHidden()
|
||||
status = { taskId: status.taskId, status: 'completed' }
|
||||
|
||||
await openDialog()
|
||||
await expect(generate).toBeEnabled()
|
||||
await language.fill('Eng')
|
||||
await dialog.getByRole('option', { name: 'English' }).click()
|
||||
await generate.click()
|
||||
await expect(dialog.getByRole('status')).toHaveText('Generating transcript…')
|
||||
status = { taskId: status.taskId, status: 'completed' }
|
||||
await expect(dialog).toBeHidden()
|
||||
await expect(page.getByText('Transcript generated.', { exact: true })).toBeVisible()
|
||||
})
|
||||
Reference in New Issue
Block a user