mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 07:34:25 +00:00
feat(transcript): add Chinese script choices
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
"@shumai/workflow-core": "workspace:*",
|
||||
"adm-zip": "0.6.0",
|
||||
"jittered-fractional-indexing": "1.0.1",
|
||||
"opencc-js": "1.4.2",
|
||||
"sharp": "0.35.4",
|
||||
"typebox": "1.3.22",
|
||||
"ulid": "3.0.2",
|
||||
|
||||
@@ -14,6 +14,7 @@ import { transcriptService } from '@shumai/core/src/transcript/transcript'
|
||||
import { selectPrimaryAudioStream } from '@shumai/core/src/transcode/transcode'
|
||||
import { prisma } from '@shumai/db'
|
||||
import {
|
||||
chineseTranscriptLanguageSchema,
|
||||
selectTranscriptVideoProxyKey,
|
||||
transcriptionErrors,
|
||||
transcriptVideoStatuses,
|
||||
@@ -180,7 +181,17 @@ export const transcribeAudioActivity = defineStep(async function transcribeAudio
|
||||
export const saveTranscriptActivity = defineStep(async function saveTranscriptActivity(
|
||||
params: Parameters<typeof transcriptService.saveResult>[0],
|
||||
): Promise<void> {
|
||||
if (!(await transcriptService.saveResult(params))) {
|
||||
let { segments } = params
|
||||
const script = chineseTranscriptLanguageSchema.safeParse(params.language)
|
||||
if (script.success) {
|
||||
const { Converter } = await import('opencc-js')
|
||||
const convert =
|
||||
script.data === 'zh-Hans'
|
||||
? Converter({ from: 't', to: 'cn' })
|
||||
: Converter({ from: 'cn', to: 't' })
|
||||
segments = segments.map((segment) => ({ ...segment, text: convert(segment.text) }))
|
||||
}
|
||||
if (!(await transcriptService.saveResult({ ...params, segments }))) {
|
||||
throw ApplicationFailure.create({ message: 'Video is no longer available', nonRetryable: true })
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { logger } from '@shumai/core/src/logger'
|
||||
import { getTranscriptionProviderLanguage } from '@shumai/core/src/transcript/local-transcription'
|
||||
import type { WorkflowTask } from '@shumai/db'
|
||||
import { ApplicationFailure, isDbosWorkflowCancelledError } from '@shumai/workflow-core'
|
||||
import { deleteS3ObjectActivity } from '../activities/ai'
|
||||
@@ -24,8 +25,15 @@ export async function transcribeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
const audioKey = `temp/transcripts/${taskId}.wav`
|
||||
try {
|
||||
await extractTranscriptAudioActivity({ assetId, taskId, audioKey, teamId })
|
||||
const transcript = await transcribeAudioActivity({ taskId, audioKey, teamId, ...request })
|
||||
if (request.language && transcript.language && request.language !== transcript.language) {
|
||||
const providerLanguage = getTranscriptionProviderLanguage(request.language)
|
||||
const transcript = await transcribeAudioActivity({
|
||||
taskId,
|
||||
audioKey,
|
||||
teamId,
|
||||
language: providerLanguage,
|
||||
model: request.model,
|
||||
})
|
||||
if (providerLanguage && transcript.language && providerLanguage !== transcript.language) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Transcription returned an unexpected language',
|
||||
nonRetryable: true,
|
||||
@@ -35,7 +43,7 @@ export async function transcribeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
taskId,
|
||||
assetId,
|
||||
model: request.model,
|
||||
language: transcript.language,
|
||||
language: transcript.language === null ? null : (request.language ?? transcript.language),
|
||||
segments: transcript.segments.map((segment) => ({
|
||||
startMs: Math.round(segment.start * 1000),
|
||||
endMs: Math.round(segment.end * 1000),
|
||||
|
||||
Reference in New Issue
Block a user