Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

feat: add standalone smart dubbing workspace

Joshua74bc8b95922b
diff --git a/apps/daemon/src/api/server.ts b/apps/daemon/src/api/server.ts
index 3b17856f..b65796fd 100644
--- a/apps/daemon/src/api/server.ts
+++ b/apps/daemon/src/api/server.ts
@@ -56,6 +56,7 @@ import {
} from '../creator/image/executor.js';
import { createClipExecutor } from '../creator/clip/executor.js';
import { createStickmanExecutor } from '../creator/stickman/executor.js';
+import { createSmartDubbingExecutor } from '../creator/smart-dubbing/executor.js';
import { createCreatorProjectCoverService } from '../creator/project-cover.js';
import {
createCreatorReferenceImageUploadService,
@@ -597,6 +598,9 @@ export async function buildServer(input: BuildServerInput) {
console.warn(`Creator optional runtime executors are unavailable: ${formatError(error)}`);
}
if (input.creatorExecutors === undefined) {
+ creatorExecutors.push(createSmartDubbingExecutor({
+ ttsService: krillinTtsService
+ }));
creatorExecutors.push(createImageExecutor({
configStore: creatorServicesConfigStore,
...(creatorFfmpegPath === undefined
diff --git a/apps/daemon/src/creator/krillin/tts-service.ts b/apps/daemon/src/creator/krillin/tts-service.ts
index b6837f26..bcae00c2 100644
--- a/apps/daemon/src/creator/krillin/tts-service.ts
+++ b/apps/daemon/src/creator/krillin/tts-service.ts
@@ -48,6 +48,7 @@ type ExecuteUtilityInput = {
config: CreatorServicesConfig;
args: string[];
launcherRoot: string;
+ signal?: AbortSignal;
};
export type KrillinTtsSynthesisRequest = {
@@ -58,6 +59,7 @@ export type KrillinTtsSynthesisRequest = {
format?: 'mp3' | 'wav';
speed?: number;
instructions?: string;
+ signal?: AbortSignal;
};
export type KrillinTtsSynthesisResult = {
@@ -188,7 +190,8 @@ export function createKrillinTtsService(input: {
const response = await executeUtility({
config: prepared.config,
args,
- launcherRoot
+ launcherRoot,
+ ...(request.signal === undefined ? {} : { signal: request.signal })
});
ensureSuccessfulResponse(response);
const content = await readFile(outputPath);
@@ -311,6 +314,13 @@ async function executePackagedKrillinUtility(input: ExecuteUtilityInput & {
resourceRoot: string;
timeoutMs: number;
}): Promise<KrillinUtilityResponse> {
+ if (input.signal?.aborted) {
+ throw new KrillinTtsServiceError(
+ 'creator_tts_upstream_error',
+ 'Speech synthesis was canceled',
+ 499
+ );
+ }
let manifest;
try {
manifest = readKrillinRuntimeManifest(input.resourceRoot);
@@ -368,6 +378,15 @@ async function executePackagedKrillinUtility(input: ExecuteUtilityInput & {
));
}, input.timeoutMs);
timeout.unref();
+ const abort = () => {
+ child.kill('SIGTERM');
+ fail(new KrillinTtsServiceError(
+ 'creator_tts_upstream_error',
+ 'Speech synthesis was canceled',
+ 499
+ ));
+ };
+ input.signal?.addEventListener('abort', abort, { once: true });
child.stdout.on('data', chunk => {
stdout = appendBounded(stdout, String(chunk));
});
@@ -397,6 +416,7 @@ async function executePackagedKrillinUtility(input: ExecuteUtilityInput & {
if (settled) return;
settled = true;
clearTimeout(timeout);
+ input.signal?.removeEventListener('abort', abort);
resolvePromise(response);
}
@@ -404,6 +424,7 @@ async function executePackagedKrillinUtility(input: ExecuteUtilityInput & {
if (settled) return;
settled = true;
clearTimeout(timeout);
+ input.signal?.removeEventListener('abort', abort);
reject(error);
}
});
diff --git a/apps/daemon/src/creator/smart-dubbing/executor.ts b/apps/daemon/src/creator/smart-dubbing/executor.ts
new file mode 100644
index 00000000..14525239
--- /dev/null
+++ b/apps/daemon/src/creator/smart-dubbing/executor.ts
@@ -0,0 +1,148 @@
+import {
+ smartDubbingStyles,
+ type CreatorJson,
+ type CreatorTtsProvider,
+ type SmartDubbingFormat,
+ type SmartDubbingStyle
+} from '@opencreator/protocol';
+import { createHash } from 'node:crypto';
+import { writeFile } from 'node:fs/promises';
+import { join } from 'node:path';
+import {
+ KrillinTtsServiceError,
+ type KrillinTtsService
+} from '../krillin/tts-service.js';
+import { smartDubbingInstructions } from '../../smart-dubbing/styles.js';
+import type { CreatorExecutor } from '../executor.js';
+import { CreatorExecutorError } from '../executor.js';
+
+export function createSmartDubbingExecutor(input: {
+ ttsService: Pick<KrillinTtsService, 'synthesize'>;
+}): CreatorExecutor {
+ return {
+ id: 'smart-dubbing',
+ async run(stage) {
+ stage.reportProgress({ phase: 'validating', percent: 5 });
+ const request = readRequest(stage.job.state);
+ if (stage.signal.aborted) {
+ throw new CreatorExecutorError('creator_stage_canceled', 'Creator stage was canceled');
+ }
+ stage.reportProgress({ phase: 'generating_voice', percent: 20 });
+ try {
+ const synthesis = await input.ttsService.synthesize({
+ text: request.text,
+ ...(request.provider === undefined ? {} : { provider: request.provider }),
+ ...(request.model === undefined ? {} : { model: request.model }),
+ ...(request.voiceCode === undefined ? {} : { voiceId: request.voiceCode }),
+ format: request.format,
+ speed: request.speed,
+ instructions: smartDubbingInstructions(request.style),
+ signal: stage.signal
+ });
+ if (stage.signal.aborted) {
+ throw new CreatorExecutorError('creator_stage_canceled', 'Creator stage was canceled');
+ }
+ stage.reportProgress({ phase: 'finalizing_output', percent: 90 });
+ const fileName = `OpenCreator-dubbing.${synthesis.format}`;
+ const path = join(stage.workdir, fileName);
+ await writeFile(path, synthesis.content, { mode: 0o600 });
+ const characterCount = [...request.text].length;
+ return {
+ outputs: [{
+ kind: 'dubbed_audio',
+ status: 'completed',
+ path,
+ metadata: {
+ fileName,
+ mime: synthesis.mime,
+ bytes: synthesis.content.length,
+ sha256: createHash('sha256').update(synthesis.content).digest('hex'),
+ provider: synthesis.provider,
+ model: synthesis.model,
+ voiceCode: synthesis.voiceId,
+ voiceName: request.voiceName ?? synthesis.voiceId,
+ style: request.style,
+ speed: request.speed,
+ format: synthesis.format,
+ characterCount,
+ settingsSnapshot: stage.job.state
+ }
+ }],
+ progress: {
+ phase: 'completed',
+ percent: 100,
+ completed: 1,
+ failed: 0,
+ total: 1
+ }
+ };
+ } catch (error) {
+ if (stage.signal.aborted) {
+ throw new CreatorExecutorError('creator_stage_canceled', 'Creator stage was canceled');
+ }
+ if (error instanceof CreatorExecutorError) throw error;
+ if (error instanceof KrillinTtsServiceError) {
+ const code = error.code === 'VALIDATION_FAILED'
+ ? 'creator_stage_input_missing'
+ : error.code;
+ throw new CreatorExecutorError(code, error.message);
+ }
+ throw new CreatorExecutorError(
+ 'creator_tts_upstream_error',
+ error instanceof Error ? error.message : 'Speech synthesis failed'
+ );
+ }
+ }
+ };
+}
+
+function readRequest(state: Record<string, CreatorJson>): {
+ text: string;
+ provider?: Exclude<CreatorTtsProvider, 'edge-tts'>;
+ model?: string;
+ voiceCode?: string;
+ voiceName?: string;
+ style: SmartDubbingStyle;
+ speed: number;
+ format: SmartDubbingFormat;
+} {
+ const text = readString(state.text)?.trim() ?? '';
+ if (!text || [...text].length > 5_000) {
+ throw new CreatorExecutorError(
+ 'creator_stage_input_missing',
+ 'Dubbing text must contain between 1 and 5000 characters'
+ );
+ }
+ const provider = readString(state.ttsProvider);
+ if (provider !== undefined && !['openai', 'aliyun', 'minimax'].includes(provider)) {
+ throw new CreatorExecutorError(
+ 'unsupported_capability',
+ 'The selected TTS provider does not support smart dubbing'
+ );
+ }
+ const style = readString(state.style) ?? 'natural';
+ if (!(smartDubbingStyles as readonly string[]).includes(style)) {
+ throw new CreatorExecutorError('creator_stage_input_missing', 'Dubbing style is invalid');
+ }
+ const speed = typeof state.speed === 'number' ? state.speed : 1;
+ if (!Number.isFinite(speed) || speed < 0.75 || speed > 1.25) {
+ throw new CreatorExecutorError('creator_stage_input_missing', 'Dubbing speed is invalid');
+ }
+ const format = state.format === 'wav' ? 'wav' : 'mp3';
+ return {
+ text,
+ ...(provider === undefined
+ ? {}
+ : { provider: provider as Exclude<CreatorTtsProvider, 'edge-tts'> }),
+ ...(readString(state.ttsModel) === undefined ? {} : { model: readString(state.ttsModel) }),
+ ...(readString(state.voiceCode) === undefined ? {} : { voiceCode: readString(state.voiceCode) }),
+ ...(readString(state.voiceName) === undefined ? {} : { voiceName: readString(state.voiceName) }),
+ style: style as SmartDubbingStyle,
+ speed,
+ format
+ };
+}
+
+function readString(value: CreatorJson | undefined): string | undefined {
+ return typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
+}
diff --git a/apps/daemon/src/creator/templates/registry.ts b/apps/daemon/src/creator/templates/registry.ts
index 400f13db..a734ead7 100644
--- a/apps/daemon/src/creator/templates/registry.ts
+++ b/apps/daemon/src/creator/templates/registry.ts
@@ -10,6 +10,7 @@ import {
} from './image-generation.js';
import { createAutoClipTemplate } from './auto-clip.js';
import { createStickmanVideoTemplate } from './stickman-video.js';
+import { createSmartDubbingTemplate } from './smart-dubbing.js';
import type {
CreatorTemplateDefinition,
CreatorTemplateRegistry
@@ -22,6 +23,7 @@ export {
createImageGenerationTemplate,
createLegacyImageGenerationTemplate,
createStickmanVideoTemplate,
+ createSmartDubbingTemplate,
createLegacyVideoDownloadTemplate,
createVideoDownloadTemplate,
createVideoTranslationTemplate
@@ -36,6 +38,7 @@ export function createDefaultCreatorTemplateRegistry(): CreatorTemplateRegistry
createCoverTemplate(),
createLegacyImageGenerationTemplate(),
createImageGenerationTemplate(),
+ createSmartDubbingTemplate(),
createAutoClipTemplate(),
createStickmanVideoTemplate()
]);
diff --git a/apps/daemon/src/creator/templates/smart-dubbing.ts b/apps/daemon/src/creator/templates/smart-dubbing.ts
new file mode 100644
index 00000000..c78767dd
--- /dev/null
+++ b/apps/daemon/src/creator/templates/smart-dubbing.ts
@@ -0,0 +1,44 @@
+import { smartDubbingStyles } from '@opencreator/protocol';
+import { z } from 'zod';
+import type { CreatorTemplateDefinition } from './types.js';
+
+const record = z.record(z.string(), z.unknown()) as never;
+
+export function createSmartDubbingTemplate(): CreatorTemplateDefinition {
+ return {
+ id: 'smart-dubbing',
+ version: 1,
+ renderer: 'smart-dubbing',
+ inputSchema: z.object({
+ text: z.string().max(5_000).default(''),
+ ttsProvider: z.enum(['openai', 'aliyun', 'minimax']).optional(),
+ ttsModel: z.string().max(256).optional(),
+ voiceCode: z.string().max(256).optional(),
+ voiceName: z.string().max(256).optional(),
+ style: z.enum(smartDubbingStyles).default('natural'),
+ speed: z.number().min(0.75).max(1.25).default(1),
+ format: z.enum(['mp3', 'wav']).default('mp3'),
+ currentStep: z.union([z.literal(0), z.literal(1), z.literal(2)]).default(0),
+ furthestStep: z.union([z.literal(0), z.literal(1), z.literal(2)]).default(0),
+ currentStage: z.string().nullable().default(null)
+ }).passthrough() as never,
+ stages: [{
+ id: 'tts',
+ executor: 'smart-dubbing',
+ allowedJobStatuses: ['draft', 'running', 'completed', 'failed', 'needs_input'],
+ inputArtifacts: [],
+ outputArtifacts: [{ kind: 'dubbed_audio', status: 'completed' }]
+ }],
+ actions: [
+ { id: 'update-settings', inputSchema: record, allowedStages: ['tts'] },
+ { id: 'run-stage', inputSchema: record, allowedStages: ['tts'] },
+ { id: 'undo-action', inputSchema: record, allowedStages: ['tts'] }
+ ],
+ outputs: [{ kind: 'dubbed_audio', required: true }],
+ agentGuidance: [
+ '帮助用户把文案转换为可下载的配音音频。',
+ '更新设置必须写入 input.patch,可调整 text、ttsProvider、ttsModel、voiceCode、voiceName、style、speed 和 format。',
+ '确认文案和音色后运行 tts 阶段,不得调用视频翻译模板或伪造音频结果。'
+ ].join(' ')
+ };
+}
diff --git a/apps/daemon/src/smart-dubbing/service.ts b/apps/daemon/src/smart-dubbing/service.ts
index 4bd866e6..8f8c401d 100644
--- a/apps/daemon/src/smart-dubbing/service.ts
+++ b/apps/daemon/src/smart-dubbing/service.ts
@@ -12,19 +12,11 @@ import {
KrillinTtsServiceError,
type KrillinTtsService
} from '../creator/krillin/tts-service.js';
+import { smartDubbingInstructions } from './styles.js';
const MAX_TEXT_LENGTH = 5_000;
const SAFE_RESULT_ID = /^[A-Za-z0-9_-]{12,64}$/;
-const styleInstructions: Record<SmartDubbingStyle, string> = {
- natural: 'Speak naturally with clear articulation and balanced pacing.',
- professional: 'Use a polished, confident, professional presentation style.',
- warm: 'Use a warm, friendly, approachable tone with gentle pacing.',
- energetic: 'Use an energetic, upbeat delivery while keeping every word clear.',
- calm: 'Use a calm, steady, reassuring tone with measured pauses.',
- storytelling: 'Use an expressive storytelling cadence with natural emphasis and pauses.'
-};
-
export type SmartDubbingService = {
generate(request: CreateSmartDubbingRequest): Promise<SmartDubbingResult>;
preview(request: CreateSmartDubbingRequest): Promise<{
@@ -85,7 +77,7 @@ export function createSmartDubbingService(input: {
voiceId: request.voice.trim(),
format: request.format,
speed: request.speed,
- instructions: styleInstructions[request.style]
+ instructions: smartDubbingInstructions(request.style)
});
} catch (error) {
throw mapTtsError(error);
diff --git a/apps/daemon/src/smart-dubbing/styles.ts b/apps/daemon/src/smart-dubbing/styles.ts
new file mode 100644
index 00000000..2e848103
--- /dev/null
+++ b/apps/daemon/src/smart-dubbing/styles.ts
@@ -0,0 +1,14 @@
+import type { SmartDubbingStyle } from '@opencreator/protocol';
+
+const styleInstructions: Record<SmartDubbingStyle, string> = {
+ natural: 'Speak naturally with clear articulation and balanced pacing.',
+ professional: 'Use a polished, confident, professional presentation style.',
+ warm: 'Use a warm, friendly, approachable tone with gentle pacing.',
+ energetic: 'Use an energetic, upbeat delivery while keeping every word clear.',
+ calm: 'Use a calm, steady, reassuring tone with measured pauses.',
+ storytelling: 'Use an expressive storytelling cadence with natural emphasis and pauses.'
+};
+
+export function smartDubbingInstructions(style: SmartDubbingStyle): string {
+ return styleInstructions[style];
+}
diff --git a/apps/daemon/test/integration/creator-smart-dubbing.test.ts b/apps/daemon/test/integration/creator-smart-dubbing.test.ts
new file mode 100644
index 00000000..b3ddb876
--- /dev/null
+++ b/apps/daemon/test/integration/creator-smart-dubbing.test.ts
@@ -0,0 +1,172 @@
+import { createDefaultCreatorServicesConfig } from '@opencreator/protocol';
+import type { FastifyInstance } from 'fastify';
+import { mkdtemp, rm } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { buildServer } from '../../src/api/server.js';
+import { createSmartDubbingExecutor } from '../../src/creator/smart-dubbing/executor.js';
+
+let server: FastifyInstance | undefined;
+let tempDir = '';
+
+afterEach(async () => {
+ await server?.close();
+ server = undefined;
+ if (tempDir) await rm(tempDir, { recursive: true, force: true });
+ tempDir = '';
+});
+
+describe('creator smart dubbing', () => {
+ it('runs TTS through Creator Job, Stage, Artifact and ResultSnapshot', async () => {
+ tempDir = await mkdtemp(join(tmpdir(), 'creator-smart-dubbing-'));
+ const config = createDefaultCreatorServicesConfig();
+ const audio = Buffer.from('creator-smart-dubbing-audio');
+ const synthesize = vi.fn(async () => ({
+ content: audio,
+ mime: 'audio/mpeg' as const,
+ provider: 'openai' as const,
+ model: 'gpt-4o-mini-tts',
+ voiceId: 'nova',
+ format: 'mp3' as const
+ }));
+ server = await buildServer({
+ token: 'secret',
+ dataDir: tempDir,
+ codexHome: join(tempDir, 'codex-home'),
+ creatorExecutors: [createSmartDubbingExecutor({ ttsService: { synthesize } })],
+ creatorServicesConfigStore: {
+ async read() { return structuredClone(config); },
+ async write(next) { return structuredClone(next); },
+ async reset() { return structuredClone(config); }
+ },
+ codexProviderCredentialStore: {
+ async readApiKey() { return undefined; },
+ async writeApiKey() {}
+ }
+ });
+
+ const templates = await request('GET', '/creator/templates');
+ expect(templates.json().templates).toContainEqual(expect.objectContaining({
+ id: 'smart-dubbing',
+ outputs: [{ kind: 'dubbed_audio', required: true }]
+ }));
+
+ const created = await request('POST', '/creator/jobs', {
+ projectId: 'project_dubbing',
+ templateId: 'smart-dubbing'
+ });
+ const initial = created.json().job;
+ const updated = await request('POST', `/creator/jobs/${initial.id}/actions`, {
+ action: 'update-settings',
+ expectedRevision: initial.revision,
+ input: {
+ patch: {
+ text: '这是一段独立的智能配音文案。',
+ ttsProvider: 'openai',
+ ttsModel: 'gpt-4o-mini-tts',
+ voiceCode: 'nova',
+ voiceName: 'Nova',
+ style: 'warm',
+ speed: 1.05,
+ format: 'mp3'
+ }
+ }
+ });
+ const started = await request('POST', `/creator/jobs/${initial.id}/actions`, {
+ action: 'run-stage',
+ expectedRevision: updated.json().job.revision,
+ input: { stageId: 'tts' }
+ });
+ expect(started.statusCode).toBe(200);
+
+ const completed = await waitForCompletedJob(initial.id);
+ expect(completed).toMatchObject({
+ status: 'completed',
+ state: {
+ latestResultVersion: 1,
+ resultSnapshots: [{
+ version: 1,
+ stageId: 'tts',
+ artifactRefs: { dubbed_audio: [expect.any(String)] }
+ }]
+ },
+ stages: [{
+ stageId: 'tts',
+ executor: 'smart-dubbing',
+ status: 'succeeded',
+ progress: {
+ phase: 'completed',
+ percent: 100,
+ completed: 1,
+ failed: 0,
+ total: 1
+ }
+ }]
+ });
+ expect(synthesize).toHaveBeenCalledWith(expect.objectContaining({
+ text: '这是一段独立的智能配音文案。',
+ provider: 'openai',
+ model: 'gpt-4o-mini-tts',
+ voiceId: 'nova',
+ format: 'mp3',
+ speed: 1.05,
+ instructions: expect.stringContaining('warm'),
+ signal: expect.any(AbortSignal)
+ }));
+
+ const artifact = completed.artifacts.find((item: { kind: string }) => (
+ item.kind === 'dubbed_audio'
+ ));
+ expect(artifact).toMatchObject({
+ status: 'completed',
+ metadata: {
+ fileName: 'OpenCreator-dubbing.mp3',
+ provider: 'openai',
+ model: 'gpt-4o-mini-tts',
+ voiceCode: 'nova',
+ voiceName: 'Nova',
+ style: 'warm',
+ speed: 1.05,
+ format: 'mp3',
+ resultVersion: 1
+ }
+ });
+
+ const content = await request(
+ 'GET',
+ `/creator/jobs/${initial.id}/artifacts/${artifact.id}/content`
+ );
+ expect(content.statusCode).toBe(200);
+ expect(content.rawPayload).toEqual(audio);
+ });
+});
+
+async function waitForCompletedJob(jobId: string) {
+ const deadline = Date.now() + 10_000;
+ let lastJob: unknown;
+ while (Date.now() < deadline) {
+ const response = await request('GET', `/creator/jobs/${jobId}`);
+ const job = response.json().job;
+ lastJob = job;
+ if (job.status === 'completed') return job;
+ if (job.status === 'failed' || job.status === 'needs_input') {
+ throw new Error(`Smart dubbing failed: ${JSON.stringify(job)}`);
+ }
+ await new Promise(resolve => setTimeout(resolve, 20));
+ }
+ throw new Error(`Timed out waiting for smart dubbing: ${JSON.stringify(lastJob)}`);
+}
+
+async function request(
+ method: 'GET' | 'POST',
+ url: string,
+ payload?: object
+): Promise<{ statusCode: number; json(): any; rawPayload: Buffer }> {
+ return await server!.inject({
+ method,
+ url,
+ headers: { authorization: 'Bearer secret' },
+ ...(payload === undefined ? {} : { payload })
+ }) as never;
+}
diff --git a/apps/daemon/test/unit/creator-template-registry.test.ts b/apps/daemon/test/unit/creator-template-registry.test.ts
index b2c5e873..d7349be3 100644
--- a/apps/daemon/test/unit/creator-template-registry.test.ts
+++ b/apps/daemon/test/unit/creator-template-registry.test.ts
@@ -3,6 +3,7 @@ import {
createCoverTemplate,
createImageGenerationTemplate,
createCreatorTemplateRegistry,
+ createSmartDubbingTemplate,
createVideoDownloadTemplate,
createVideoTranslationTemplate
} from '../../src/creator/templates/registry.js';
@@ -69,6 +70,31 @@ describe('creator template registry', () => {
});
});
+ it('registers smart dubbing as a persisted TTS workflow', () => {
+ const template = createSmartDubbingTemplate();
+
+ expect(template).toMatchObject({
+ id: 'smart-dubbing',
+ version: 1,
+ renderer: 'smart-dubbing',
+ stages: [{
+ id: 'tts',
+ executor: 'smart-dubbing',
+ outputArtifacts: [{ kind: 'dubbed_audio', status: 'completed' }]
+ }],
+ outputs: [{ kind: 'dubbed_audio', required: true }]
+ });
+ expect(template.inputSchema.parse({})).toMatchObject({
+ text: '',
+ style: 'natural',
+ speed: 1,
+ format: 'mp3',
+ currentStep: 0,
+ furthestStep: 0
+ });
+ expect(template.inputSchema.parse({})).not.toHaveProperty('ttsProvider');
+ });
+
it('registers video download v2 with a non-final probe and controlled choices', () => {
const template = createVideoDownloadTemplate();
diff --git a/apps/web/src/app/AppController.tsx b/apps/web/src/app/AppController.tsx
index a0dd07d2..5534138f 100644
--- a/apps/web/src/app/AppController.tsx
+++ b/apps/web/src/app/AppController.tsx
@@ -144,7 +144,6 @@ import { createRunService } from '../services/run-service.js';
import { createRuntimeDependencyService } from '../services/runtime-dependency-service.js';
import { createScheduleService } from '../services/schedule-service.js';
import { createSearchService } from '../services/search-service.js';
-import { createSmartDubbingService } from '../services/smart-dubbing-service.js';
import { createVideoGenerationService } from '../services/video-generation-service.js';
import { createSkillMarketService } from '../services/skill-market-service.js';
import { createTaskService } from '../services/task-service.js';
@@ -510,10 +509,6 @@ export function AppController(props: AppControllerProps) {
() => runtimeClient === null ? undefined : createVideoMetadataService(runtimeClient),
[runtimeClient]
);
- const smartDubbingService = useMemo(
- () => runtimeClient === null ? undefined : createSmartDubbingService(runtimeClient),
- [runtimeClient]
- );
const videoGenerationService = useMemo(
() => runtimeClient === null ? undefined : createVideoGenerationService(runtimeClient),
[runtimeClient]
@@ -4314,7 +4309,6 @@ export function AppController(props: AppControllerProps) {
creatorService={creatorService}
runtimeDependencies={runtimeDependencies}
creatorServicesService={creatorServicesService}
- smartDubbingService={smartDubbingService}
workspace={props.route.view === 'workbench' ? props.route.tool : undefined}
jobId={props.route.view === 'workbench' ? props.route.jobId : undefined}
onJobCreated={rememberCreatorJob}
diff --git a/apps/web/src/features/dashboard/CreatorCollaborationPanel.test.tsx b/apps/web/src/features/dashboard/CreatorCollaborationPanel.test.tsx
index 6ce0bf4e..57e190a6 100644
--- a/apps/web/src/features/dashboard/CreatorCollaborationPanel.test.tsx
+++ b/apps/web/src/features/dashboard/CreatorCollaborationPanel.test.tsx
@@ -5,6 +5,7 @@ import { LanguageProvider } from '../../i18n/LanguageProvider.js';
import CreatorCollaborationPanel from './CreatorCollaborationPanel.js';
import {
coverPanelAdapter,
+ smartDubbingPanelAdapter,
videoDownloadPanelAdapter
} from './creator-panel-adapters.js';
import { CreatorSessionProvider } from './creator-session-store.js';
@@ -388,8 +389,135 @@ describe('CreatorCollaborationPanel', () => {
expect(screen.getByText('无法连接视频平台,请检查网络或代理设置后重试'))
.toBeInTheDocument();
});
+
+ it('语义化智能配音动态并显示真实 TTS 阶段进度', () => {
+ const onCancelTask = vi.fn();
+ const { container } = render(
+ <LanguageProvider initialPreference="zh-CN">
+ <CreatorSessionProvider
+ initialJob={smartDubbingJob()}
+ service={{
+ applyAction: vi.fn(),
+ runAgentTurn: vi.fn()
+ } as never}
+ >
+ <CreatorCollaborationPanel
+ adapter={smartDubbingPanelAdapter}
+ stepLabel="正在生成配音"
+ contextSummary="Nova · 温暖 · 1.05x"
+ onCancelTask={onCancelTask}
+ />
+ </CreatorSessionProvider>
+ </LanguageProvider>
+ );
+
+ expect(screen.getAllByText('更新了创作设置')).toHaveLength(1);
+ expect(screen.getByText('配音文案、音色、表达风格')).toBeInTheDocument();
+ expect(screen.getByText('2 次修改')).toBeInTheDocument();
+ expect(screen.queryByText(/currentStep|furthestStep/)).not.toBeInTheDocument();
+ expect(screen.queryByText('启动阶段 tts')).not.toBeInTheDocument();
+ expect(screen.getByText(/系统 · 生成配音/)).toBeInTheDocument();
+ expect(screen.getByText('生成配音音频')).toBeInTheDocument();
+ expect(screen.getByText('20%')).toBeInTheDocument();
+ expect(screen.getByRole('progressbar', { name: '生成配音进度' }))
+ .toHaveAttribute('aria-valuenow', '20');
+ expect(screen.getByRole('button', { name: '终止生成配音' })).toBeInTheDocument();
+ expect(container.querySelectorAll('.creator-collaboration-stage')).toHaveLength(1);
+ });
});
+function smartDubbingJob(): CreatorJob {
+ const createdAt = '2026-09-07T08:00:00.000Z';
+ return {
+ id: 'smart_dubbing_job',
+ projectId: 'project_1',
+ templateId: 'smart-dubbing',
+ templateVersion: 1,
+ status: 'running',
+ revision: 4,
+ state: {
+ text: '这是一段智能配音文案。',
+ ttsProvider: 'openai',
+ ttsModel: 'gpt-4o-mini-tts',
+ voiceCode: 'nova',
+ voiceName: 'Nova',
+ style: 'warm',
+ speed: 1.05,
+ format: 'mp3',
+ currentStage: 'tts'
+ },
+ agentThreadId: null,
+ stages: [{
+ id: 'smart_dubbing_stage',
+ jobId: 'smart_dubbing_job',
+ stageId: 'tts',
+ executor: 'smart-dubbing',
+ status: 'running',
+ dispatchStatus: 'claimed',
+ claimOwner: 'scheduler_1',
+ claimExpiresAt: null,
+ attempt: 1,
+ idempotencyKey: 'smart-dubbing-1',
+ progress: {
+ phase: 'generating_voice',
+ percent: 20,
+ completed: 0,
+ failed: 0,
+ total: 1
+ },
+ errorCode: null,
+ errorMessage: null,
+ startedAt: '2026-09-07T08:00:03.000Z',
+ finishedAt: null
+ }],
+ artifacts: [],
+ activities: [
+ {
+ id: 'activity_ui',
+ jobId: 'smart_dubbing_job',
+ revision: 1,
+ actor: 'user',
+ action: 'update-settings:draft',
+ summary: '更新创作设置',
+ details: { objectId: 'currentStep,furthestStep' },
+ createdAt: '2026-09-07T08:00:01.000Z'
+ },
+ {
+ id: 'activity_text',
+ jobId: 'smart_dubbing_job',
+ revision: 2,
+ actor: 'user',
+ action: 'update-settings:draft',
+ summary: '更新创作设置',
+ details: { objectId: 'text' },
+ createdAt: '2026-09-07T08:00:02.000Z'
+ },
+ {
+ id: 'activity_voice',
+ jobId: 'smart_dubbing_job',
+ revision: 3,
+ actor: 'user',
+ action: 'update-settings:draft',
+ summary: '更新创作设置',
+ details: { objectId: 'voiceCode,style' },
+ createdAt: '2026-09-07T08:00:03.000Z'
+ },
+ {
+ id: 'activity_run',
+ jobId: 'smart_dubbing_job',
+ revision: 4,
+ actor: 'user',
+ action: 'run-stage',
+ summary: '启动阶段 tts',
+ details: { stageId: 'tts' },
+ createdAt: '2026-09-07T08:00:04.000Z'
+ }
+ ],
+ createdAt,
+ updatedAt: '2026-09-07T08:00:04.000Z'
+ };
+}
+
function coverJob(): CreatorJob {
const createdAt = '2026-08-30T08:00:00.000Z';
return {
diff --git a/apps/web/src/features/dashboard/DashboardPage.test.tsx b/apps/web/src/features/dashboard/DashboardPage.test.tsx
index 1c88ecc2..cf8718b3 100644
--- a/apps/web/src/features/dashboard/DashboardPage.test.tsx
+++ b/apps/web/src/features/dashboard/DashboardPage.test.tsx
@@ -80,6 +80,12 @@ function createInMemoryCreatorService(): CreatorWebService {
&& typeof request.input.stageId === 'string'
) {
job = completeTranslationStage(current, request.input.stageId, request.input);
+ } else if (
+ current.templateId === 'smart-dubbing'
+ && request.action === 'run-stage'
+ && request.input.stageId === 'tts'
+ ) {
+ job = completeSmartDubbingStage(current);
} else {
job = current;
}
@@ -111,6 +117,79 @@ function createInMemoryCreatorService(): CreatorWebService {
} as unknown as CreatorWebService;
}
+function completeSmartDubbingStage(current: CreatorJob): CreatorJob {
+ const now = new Date().toISOString();
+ const version = current.artifacts.filter(artifact => artifact.kind === 'dubbed_audio').length + 1;
+ const fileName = `OpenCreator-dubbing-V${version}.mp3`;
+ const artifact: CreatorArtifact = {
+ id: `smart_dubbing_audio_v${version}`,
+ jobId: current.id,
+ kind: 'dubbed_audio',
+ version,
+ status: 'completed',
+ path: `/tmp/${fileName}`,
+ sourceArtifactIds: [],
+ metadata: {
+ resultVersion: version,
+ fileName,
+ mime: 'audio/mpeg',
+ bytes: 2048,
+ provider: 'openai',
+ model: 'gpt-4o-mini-tts',
+ voiceCode: current.state.voiceCode ?? 'nova',
+ voiceName: current.state.voiceName ?? '星语',
+ style: current.state.style ?? 'natural',
+ speed: current.state.speed ?? 1,
+ format: current.state.format ?? 'mp3',
+ characterCount: typeof current.state.text === 'string' ? [...current.state.text].length : 0,
+ settingsSnapshot: current.state
+ },
+ createdAt: now
+ };
+ return {
+ ...current,
+ status: 'completed',
+ revision: current.revision + 2,
+ state: {
+ ...current.state,
+ currentStage: 'tts',
+ resultVersion: version,
+ latestResultVersion: version
+ },
+ stages: [...current.stages, {
+ id: `smart_dubbing_stage_v${version}`,
+ jobId: current.id,
+ stageId: 'tts',
+ executor: 'smart-dubbing',
+ status: 'succeeded',
+ dispatchStatus: 'finished',
+ claimOwner: null,
+ claimExpiresAt: null,
+ attempt: 1,
+ idempotencyKey: null,
+ progress: {
+ phase: 'completed',
+ percent: 100,
+ completed: 1,
+ failed: 0,
+ total: 1,
+ resultVersion: version
+ },
+ errorCode: null,
+ errorMessage: null,
+ startedAt: now,
+ finishedAt: now
+ }],
+ artifacts: [
+ ...current.artifacts.map(existing => existing.kind === 'dubbed_audio'
+ ? { ...existing, status: 'stale' as const }
+ : existing),
+ artifact
+ ],
+ updatedAt: now
+ };
+}
+
function createTtsServices(options?: {
voiceId?: string;
voiceName?: string;
@@ -648,16 +727,17 @@ describe('DashboardPage', () => {
expect(within(videoTranslationCard).getByText('HOT')).toBeInTheDocument();
expect(within(videoTranslationCard).queryByText('NEW')).not.toBeInTheDocument();
const appCards = Array.from(container.querySelectorAll('.dashboard-app-card'));
- expect(appCards).toHaveLength(4);
+ expect(appCards).toHaveLength(5);
expect(appCards.map(card => card.querySelector('strong')?.textContent)).toEqual([
'视频翻译',
'视频下载',
'封面生成',
+ '智能配音',
'图像生成'
]);
expect(screen.queryByRole('button', { name: /^火柴人动画/ })).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: /^自动剪辑/ })).not.toBeInTheDocument();
- expect(screen.queryByRole('button', { name: /^智能配音/ })).not.toBeInTheDocument();
+ expect(screen.getByRole('button', { name: /^智能配音/ })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: /^视频生成/ })).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: /^数字人口播/ })).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: /^视频转格式/ })).not.toBeInTheDocument();
@@ -1758,6 +1838,10 @@ describe('DashboardPage', () => {
expect(screen.getByText('没有找到相关应用')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '查看全部应用' }));
expect(screen.getByRole('tab', { name: '全部' })).toHaveAttribute('aria-selected', 'true');
+
+ fireEvent.click(screen.getByRole('tab', { name: '音频处理' }));
+ expect(within(directory).getByRole('button', { name: /^智能配音/ })).toBeInTheDocument();
+ expect(directory.querySelectorAll('.dashboard-app-card')).toHaveLength(1);
});
it('creates downloadable audio in the smart dubbing workspace', async () => {
@@ -1771,29 +1855,15 @@ describe('DashboardPage', () => {
});
const play = vi.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue();
const pause = vi.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation(() => undefined);
- const result = {
- id: 'result_123456',
- fileName: 'OpenCreator-dubbing-result_123456.mp3',
- mime: 'audio/mpeg' as const,
- size: 2048,
- provider: 'openai' as const,
- model: 'gpt-4o-mini-tts',
- voice: 'nova' as const,
- style: 'warm' as const,
- speed: 1,
- format: 'mp3' as const,
- characterCount: 10,
- createdAt: '2026-08-20T00:00:00.000Z'
- };
- const generate = vi.fn(async () => ({ result }));
- const preview = vi.fn();
- const openContent = vi.fn(async () => new Response(new Blob(['audio'], { type: 'audio/mpeg' })));
const tts = createTtsServices({ voiceId: 'nova', voiceName: '星语' });
+ const creatorService = createInMemoryCreatorService();
+ const applyAction = vi.spyOn(creatorService, 'applyAction');
+ const openArtifact = vi.spyOn(creatorService, 'openArtifact');
render(
<DashboardPage
onSelectPrompt={vi.fn()}
workspace="smart-dubbing"
- smartDubbingService={{ generate, preview, openContent }}
+ creatorService={creatorService}
creatorServicesService={tts.service}
/>
);
@@ -1811,7 +1881,6 @@ describe('DashboardPage', () => {
model: 'gpt-4o-mini-tts',
voiceId: 'nova'
});
- expect(preview).not.toHaveBeenCalled();
expect(play).toHaveBeenCalledOnce();
fireEvent.click(screen.getByRole('button', { name: '暂停音色试听' }));
expect(pause).toHaveBeenCalled();
@@ -1826,14 +1895,56 @@ describe('DashboardPage', () => {
fireEvent.click(screen.getByRole('button', { name: '开始生成' }));
expect(await screen.findByLabelText('智能配音试听')).toHaveAttribute('src', 'blob:smart-dubbing');
- expect(screen.getByText(result.fileName)).toBeInTheDocument();
- expect(generate).toHaveBeenCalledWith(expect.objectContaining({
- voice: 'nova',
- style: 'warm',
- speed: 1,
- format: 'mp3'
- }));
- expect(openContent).toHaveBeenCalledWith(result.id);
+ expect(screen.getByText('OpenCreator-dubbing-V1.mp3')).toBeInTheDocument();
+ expect(screen.queryByText('Creator Runtime 未连接,Agent 不会生成替代回复。')).not.toBeInTheDocument();
+ expect(applyAction).toHaveBeenCalledWith(
+ expect.stringMatching(/^creator_test_job_/),
+ expect.objectContaining({
+ action: 'run-stage',
+ input: { stageId: 'tts' }
+ })
+ );
+ expect(openArtifact).toHaveBeenCalledWith(
+ expect.stringMatching(/^creator_test_job_/),
+ 'smart_dubbing_audio_v1'
+ );
+ });
+
+ it('links TTS configuration errors to voice service settings', async () => {
+ const tts = createTtsServices({ voiceId: 'nova', voiceName: '星语' });
+ const creatorService = createInMemoryCreatorService();
+ const applyAction = creatorService.applyAction.bind(creatorService);
+ vi.spyOn(creatorService, 'applyAction').mockImplementation(async (jobId, request) => {
+ if (request.action === 'run-stage') {
+ throw Object.assign(new Error('TTS API key is missing'), {
+ code: 'creator_tts_config_missing'
+ });
+ }
+ return applyAction(jobId, request);
+ });
+ render(
+ <DashboardPage
+ onSelectPrompt={vi.fn()}
+ workspace="smart-dubbing"
+ creatorService={creatorService}
+ creatorServicesService={tts.service}
+ />
+ );
+
+ fireEvent.change(screen.getByRole('textbox', { name: '配音文案内容' }), {
+ target: { value: '这是一段需要配置服务后生成的配音文案。' }
+ });
+ fireEvent.click(screen.getByRole('button', { name: '继续' }));
+ expect(await screen.findByRole('combobox', { name: '配音音色' })).toHaveValue('nova');
+ fireEvent.click(screen.getByRole('button', { name: '继续' }));
+ fireEvent.click(screen.getByRole('button', { name: '开始生成' }));
+
+ expect(await screen.findAllByText('请先在设置的配音服务中配置当前服务商的 API Key'))
+ .toHaveLength(2);
+ expect(screen.getByRole('link', { name: '打开配音服务设置' })).toHaveAttribute(
+ 'href',
+ '#/settings?tab=ai-services&section=tts'
+ );
});
it('generates image assets through the Creator Runtime', async () => {
diff --git a/apps/web/src/features/dashboard/DashboardPage.tsx b/apps/web/src/features/dashboard/DashboardPage.tsx
index ba7a4917..ec45ed4c 100644
--- a/apps/web/src/features/dashboard/DashboardPage.tsx
+++ b/apps/web/src/features/dashboard/DashboardPage.tsx
@@ -40,7 +40,6 @@ import {
isVisibleCreatorWorkspace
} from './creator-workspace.js';
import type { VideoMetadataService } from '../../services/video-metadata-service.js';
-import type { SmartDubbingService } from '../../services/smart-dubbing-service.js';
import type { CreatorServicesSettingsService } from '../../services/creator-services-service.js';
import type { VideoGenerationService } from '../../services/video-generation-service.js';
@@ -162,7 +161,7 @@ const creatorTools: DashboardEntry[] = [
},
];
-const categories = ['全部', '视频编辑', '图像创作'] as const;
+const categories = ['全部', '视频编辑', '图像创作', '音频处理'] as const;
type CategoryFilter = typeof categories[number];
const CREATOR_JOB_LOAD_TIMEOUT_MS = 15_000;
@@ -176,7 +175,6 @@ export default function DashboardPage(props: {
onBackToHome?(): void;
onWorkspaceModeChange?(active: boolean): void;
skillLaunch?: CreatorSkillLaunch;
- smartDubbingService?: SmartDubbingService;
creatorServicesService?: CreatorServicesSettingsService | null;
videoGenerationService?: VideoGenerationService;
videoMetadataService?: VideoMetadataService;
@@ -311,14 +309,13 @@ export default function DashboardPage(props: {
}
if (activeWorkspace === 'smart-dubbing') {
- return (
+ return renderCreatorWorkspace('smart-dubbing', (
<SmartDubbingWorkspace
promptHint={activePromptHint}
- service={props.smartDubbingService}
creatorServicesService={props.creatorServicesService}
onBack={closeWorkspace}
/>
- );
+ ));
}
if (activeWorkspace === 'image-generation') {
diff --git a/apps/web/src/features/dashboard/SmartDubbingWorkspace.tsx b/apps/web/src/features/dashboard/SmartDubbingWorkspace.tsx
index 6cee3e20..b1b8f2fb 100644
--- a/apps/web/src/features/dashboard/SmartDubbingWorkspace.tsx
+++ b/apps/web/src/features/dashboard/SmartDubbingWorkspace.tsx
@@ -1,10 +1,11 @@
-import { useEffect, useMemo, useState } from 'react';
-import type {
- CreatorTtsProvider,
- SmartDubbingFormat,
- SmartDubbingResult,
- SmartDubbingStyle,
- SmartDubbingVoice
+import {
+ smartDubbingStyles,
+ type CreatorArtifact,
+ type CreatorJson,
+ type CreatorTtsProvider,
+ type SmartDubbingFormat,
+ type SmartDubbingStyle,
+ type SmartDubbingVoice
} from '@opencreator/protocol';
import {
Check,
@@ -17,15 +18,30 @@ import {
Sparkles,
WandSparkles
} from 'lucide-react';
-import { useLocalizedCopy } from '../../i18n/useLocalizedCopy.js';
+import { useEffect, useMemo, useState } from 'react';
import { TtsVoicePicker } from '../../components/tts/TtsVoicePicker.js';
+import { useLocalizedCopy } from '../../i18n/useLocalizedCopy.js';
import type { CreatorServicesSettingsService } from '../../services/creator-services-service.js';
-import type { SmartDubbingService } from '../../services/smart-dubbing-service.js';
import CreatorTaskSummary from './CreatorTaskSummary.js';
import CreatorToolShell from './CreatorToolShell.js';
+import { useOptionalCreatorSession } from './creator-session-store.js';
type DubbingStep = 0 | 1 | 2;
+type DubbingResult = {
+ artifact: CreatorArtifact;
+ fileName: string;
+ size: number;
+ provider: Exclude<CreatorTtsProvider, 'edge-tts'>;
+ model: string;
+ voice: string;
+ voiceName: string;
+ style: SmartDubbingStyle;
+ speed: number;
+ format: SmartDubbingFormat;
+ characterCount: number;
+};
+
const styles: Array<{ value: SmartDubbingStyle; zh: string; en: string }> = [
{ value: 'natural', zh: '自然', en: 'Natural' },
{ value: 'professional', zh: '专业', en: 'Professional' },
@@ -37,46 +53,66 @@ const styles: Array<{ value: SmartDubbingStyle; zh: string; en: string }> = [
const sampleTextZh = '每一个好故事,都从一个清晰的想法开始。让声音带着恰当的节奏和情绪,把内容自然地传递给听众。';
const sampleTextEn = 'Every strong story begins with a clear idea. Give it the right pace and emotion, then let the voice carry it naturally to the audience.';
+
export default function SmartDubbingWorkspace(props: {
onBack(): void;
promptHint?: string;
- service?: SmartDubbingService;
creatorServicesService?: CreatorServicesSettingsService | null;
}) {
const l = useLocalizedCopy();
- const [currentStep, setCurrentStep] = useState<DubbingStep>(0);
- const [furthestStep, setFurthestStep] = useState<DubbingStep>(0);
- const [text, setText] = useState('');
- const [provider, setProvider] = useState<CreatorTtsProvider>('openai');
- const [model, setModel] = useState('gpt-4o-mini-tts');
- const [voice, setVoice] = useState<SmartDubbingVoice>('');
- const [voiceName, setVoiceName] = useState('');
- const [style, setStyle] = useState<SmartDubbingStyle>('natural');
- const [speed, setSpeed] = useState(1);
- const [format, setFormat] = useState<SmartDubbingFormat>('mp3');
- const [generating, setGenerating] = useState(false);
- const [result, setResult] = useState<SmartDubbingResult>();
+ const session = useOptionalCreatorSession();
+ const restoredResult = session?.job.artifacts.some(artifact => (
+ artifact.kind === 'dubbed_audio' && artifact.status === 'completed'
+ )) === true;
+ const restoredStep = restoredResult ? 2 : readStep(session?.state.currentStep, 0);
+ const [currentStep, setCurrentStep] = useState<DubbingStep>(restoredStep);
+ const [furthestStep, setFurthestStep] = useState<DubbingStep>(() => (
+ Math.max(restoredStep, readStep(session?.state.furthestStep, restoredStep)) as DubbingStep
+ ));
+ const [text, setText] = useState(() => readString(session?.state.text));
+ const [provider, setProvider] = useState<CreatorTtsProvider>(() => (
+ readProvider(session?.state.ttsProvider) ?? 'openai'
+ ));
+ const [model, setModel] = useState(() => readString(session?.state.ttsModel) || 'gpt-4o-mini-tts');
+ const [voice, setVoice] = useState<SmartDubbingVoice>(() => readString(session?.state.voiceCode));
+ const [voiceName, setVoiceName] = useState(() => readString(session?.state.voiceName));
+ const [style, setStyle] = useState<SmartDubbingStyle>(() => readStyle(session?.state.style));
+ const [speed, setSpeed] = useState(() => readSpeed(session?.state.speed));
+ const [format, setFormat] = useState<SmartDubbingFormat>(() => readFormat(session?.state.format));
const [audioUrl, setAudioUrl] = useState('');
const [notice, setNotice] = useState('');
const [error, setError] = useState('');
+ const [taskControlPending, setTaskControlPending] = useState<'canceling' | 'resuming'>();
const characterCount = useMemo(() => [...text.trim()].length, [text]);
const selectedStyle = styles.find(item => item.value === style) ?? styles[0]!;
-
- useEffect(() => () => {
- if (audioUrl) URL.revokeObjectURL(audioUrl);
- }, [audioUrl]);
+ const result = useMemo(
+ () => readLatestResult(session?.job.artifacts ?? []),
+ [session?.job.artifacts]
+ );
+ const latestStage = session?.job.stages.filter(stage => stage.stageId === 'tts').at(-1);
+ const generating = latestStage?.status === 'queued' || latestStage?.status === 'running';
+ const runtimeError = latestStage?.status === 'failed'
+ ? formatGenerationError({ code: latestStage.errorCode, message: latestStage.errorMessage }, l)
+ : session?.error === null || session?.error === undefined
+ ? ''
+ : formatGenerationError(session.error, l);
+ const visibleError = error || runtimeError;
+ const settingsHref = shouldOpenTtsSettings(
+ provider,
+ latestStage?.errorCode,
+ session?.error?.code
+ ) ? '#/settings?tab=ai-services&section=tts' : undefined;
useEffect(() => {
let active = true;
if (props.creatorServicesService === null || props.creatorServicesService === undefined) {
- return () => {
- active = false;
- };
+ return () => { active = false; };
}
void props.creatorServicesService.getConfig()
.then(response => {
if (!active) return;
- const selectedProvider = response.config.tts.provider;
+ const configuredProvider = response.config.tts.provider;
+ const selectedProvider = readProvider(session?.state.ttsProvider) ?? configuredProvider;
setProvider(selectedProvider);
if (selectedProvider === 'edge-tts') {
setModel('');
@@ -85,19 +121,55 @@ export default function SmartDubbingWorkspace(props: {
return;
}
const selectedConfig = response.config.tts[selectedProvider];
- setModel(selectedConfig.model);
- setVoice(selectedConfig.defaultVoiceId);
- setVoiceName(selectedConfig.defaultVoiceId);
+ setModel(readString(session?.state.ttsModel) || selectedConfig.model);
+ setVoice(readString(session?.state.voiceCode) || selectedConfig.defaultVoiceId);
+ setVoiceName(readString(session?.state.voiceName) || selectedConfig.defaultVoiceId);
})
.catch(() => setError(l('无法读取配音服务配置', 'Could not load TTS settings')));
+ return () => { active = false; };
+ }, [props.creatorServicesService, session?.job.id]);
+
+ useEffect(() => {
+ if (session === null || result === undefined) {
+ setAudioUrl(previous => {
+ if (previous) URL.revokeObjectURL(previous);
+ return '';
+ });
+ return undefined;
+ }
+ let active = true;
+ let objectUrl = '';
+ void session.openArtifact(result.artifact.id)
+ .then(async response => {
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
+ objectUrl = URL.createObjectURL(await response.blob());
+ if (active) setAudioUrl(objectUrl);
+ })
+ .catch(cause => {
+ if (active) setError(l(
+ '配音音频加载失败,可以稍后重试或重新生成',
+ `Dubbing audio failed to load: ${cause instanceof Error ? cause.message : String(cause)}`
+ ));
+ });
return () => {
active = false;
+ if (objectUrl) URL.revokeObjectURL(objectUrl);
};
- }, [props.creatorServicesService]);
+ }, [l, result?.artifact.id, session?.openArtifact]);
+
+ useEffect(() => {
+ if (result !== undefined && !generating) {
+ setCurrentStep(2);
+ setFurthestStep(2);
+ setNotice(l('配音已生成,可以试听或下载音频', 'Dubbing is ready to preview or download'));
+ }
+ }, [generating, l, result?.artifact.id]);
function openStep(step: DubbingStep) {
+ const nextFurthest = Math.max(furthestStep, step) as DubbingStep;
setCurrentStep(step);
- setFurthestStep(previous => Math.max(previous, step) as DubbingStep);
+ setFurthestStep(nextFurthest);
+ session?.updateDraft({ currentStep: step, furthestStep: nextFurthest });
}
function nextStep() {
@@ -113,29 +185,76 @@ export default function SmartDubbingWorkspace(props: {
openStep(Math.min(2, currentStep + 1) as DubbingStep);
}
+ function updateText(value: string) {
+ setText(value);
+ session?.updateDraft({ text: value });
+ setError('');
+ }
+
+ function updateStyle(value: SmartDubbingStyle) {
+ setStyle(value);
+ session?.updateDraft({ style: value });
+ setError('');
+ }
+
+ function updateSpeed(value: number) {
+ setSpeed(value);
+ session?.updateDraft({ speed: value });
+ setError('');
+ }
+
+ function updateFormat(value: SmartDubbingFormat) {
+ setFormat(value);
+ session?.updateDraft({ format: value });
+ setError('');
+ }
+
async function generate() {
if (generating) return;
- if (!props.service) {
+ if (session === null) {
setError(l('智能配音服务暂不可用,请检查 Runtime 连接', 'Smart dubbing is unavailable. Check the Runtime connection.'));
return;
}
- setGenerating(true);
+ if (!text.trim()) {
+ setError(l('请先填写需要配音的文案', 'Enter the script to be voiced'));
+ openStep(0);
+ return;
+ }
+ if (!voice.trim()) {
+ setError(l('请选择一个可用音色', 'Select an available voice'));
+ openStep(1);
+ return;
+ }
+ if (provider === 'edge-tts') {
+ setError(l(
+ '智能配音暂不支持 Edge TTS,请先在设置中选择阿里云百炼、OpenAI 或 MiniMax',
+ 'AI dubbing does not support Edge TTS. Select Alibaba Cloud, OpenAI, or MiniMax in Settings.'
+ ));
+ openStep(1);
+ return;
+ }
setError('');
setNotice('');
+ session.updateDraft({
+ text: text.trim(),
+ ttsProvider: provider,
+ ttsModel: model,
+ voiceCode: voice,
+ voiceName: voiceName || voice,
+ style,
+ speed,
+ format
+ }, { semantic: true });
try {
- const response = await props.service.generate({ text, voice, style, speed, format });
- const audioResponse = await props.service.openContent(response.result.id);
- const objectUrl = URL.createObjectURL(await audioResponse.blob());
- setAudioUrl(previous => {
- if (previous) URL.revokeObjectURL(previous);
- return objectUrl;
+ await session.flush();
+ await session.applyAction({
+ actor: 'user',
+ action: 'run-stage',
+ input: { stageId: 'tts' }
});
- setResult(response.result);
- setNotice(l('配音已生成,可以试听或下载音频', 'Dubbing is ready to preview or download'));
+ setNotice(l('配音任务已提交,完成后会自动显示音频', 'Dubbing started. The audio will appear automatically.'));
} catch (caught) {
setError(formatGenerationError(caught, l));
- } finally {
- setGenerating(false);
}
}
@@ -148,48 +267,84 @@ export default function SmartDubbingWorkspace(props: {
setNotice(l('配音音频已开始下载', 'The dubbing audio download has started'));
}
+ async function cancelTask() {
+ if (session === null || taskControlPending !== undefined) return;
+ setTaskControlPending('canceling');
+ try {
+ await session.cancelJob();
+ } catch (caught) {
+ setError(formatGenerationError(caught, l));
+ } finally {
+ setTaskControlPending(undefined);
+ }
+ }
+
+ async function resumeTask() {
+ if (session === null || taskControlPending !== undefined) return;
+ setTaskControlPending('resuming');
+ try {
+ await session.resumeJob();
+ } catch (caught) {
+ setError(formatGenerationError(caught, l));
+ } finally {
+ setTaskControlPending(undefined);
+ }
+ }
+
function handleCommand(command: string) {
if (/示例|sample/i.test(command)) {
- setText(l(sampleTextZh, sampleTextEn));
+ updateText(l(sampleTextZh, sampleTextEn));
openStep(0);
return l('示例文案已填入,可以继续选择音色。', 'The sample script is ready. Continue to voice selection.');
}
- const styleMatch = styles.find(item => command.includes(item.zh) || command.toLowerCase().includes(item.en.toLowerCase()));
+ const styleMatch = styles.find(item => (
+ command.includes(item.zh) || command.toLowerCase().includes(item.en.toLowerCase())
+ ));
if (styleMatch) {
- setStyle(styleMatch.value);
+ updateStyle(styleMatch.value);
openStep(1);
return l(`表达风格已改为${styleMatch.zh}。`, `Delivery style changed to ${styleMatch.en}.`);
}
if (/快一点|加快|faster/i.test(command)) {
- setSpeed(current => Math.min(1.25, Math.round((current + 0.1) * 100) / 100));
+ updateSpeed(Math.min(1.25, Math.round((speed + 0.1) * 100) / 100));
openStep(1);
return l('语速已加快。', 'The speaking rate is faster.');
}
if (/慢一点|减慢|slower/i.test(command)) {
- setSpeed(current => Math.max(0.75, Math.round((current - 0.1) * 100) / 100));
+ updateSpeed(Math.max(0.75, Math.round((speed - 0.1) * 100) / 100));
openStep(1);
return l('语速已放慢。', 'The speaking rate is slower.');
}
if (command.trim().length > 12) {
- setText(command.trim());
+ updateText(command.trim());
openStep(0);
return l('文案已同步到左侧,可以继续设置音色和表达。', 'The script is synchronized on the left. Continue with voice and delivery settings.');
}
return l('可以发送配音文案,或告诉我需要自然、专业、温暖、活力、沉静或叙事风格。', 'Send a script, or ask for a natural, professional, warm, energetic, calm, or storytelling delivery.');
}
+ const settingsSnapshot = result?.artifact.metadata.settingsSnapshot;
+ const resultSettings = settingsSnapshot !== null
+ && typeof settingsSnapshot === 'object'
+ && !Array.isArray(settingsSnapshot)
+ ? settingsSnapshot as Record<string, CreatorJson>
+ : undefined;
+ const summaryText = result ? readString(resultSettings?.text) || text.trim() : text.trim();
+ const summaryStyle = result
+ ? styles.find(item => item.value === result.style) ?? selectedStyle
+ : selectedStyle;
const summary = (
<CreatorTaskSummary
sourceIcon={FileAudio}
sourceLabel={l('配音文案', 'Script')}
- sourceValue={text.trim()}
+ sourceValue={summaryText}
items={[
- { label: l('服务商', 'Provider'), value: providerLabel(provider, l) },
- { label: l('音色', 'Voice'), value: voiceName || voice },
- { label: l('表达风格', 'Delivery'), value: l(selectedStyle.zh, selectedStyle.en) },
- { label: l('语速', 'Speed'), value: `${speed.toFixed(2)}x` },
- { label: l('音频格式', 'Format'), value: format.toUpperCase() },
- { label: l('文案长度', 'Length'), value: l(`${characterCount} 字`, `${characterCount} characters`) }
+ { label: l('服务商', 'Provider'), value: providerLabel(result?.provider ?? provider, l) },
+ { label: l('音色', 'Voice'), value: result?.voiceName || voiceName || voice },
+ { label: l('表达风格', 'Delivery'), value: l(summaryStyle.zh, summaryStyle.en) },
+ { label: l('语速', 'Speed'), value: `${(result?.speed ?? speed).toFixed(2)}x` },
+ { label: l('音频格式', 'Format'), value: (result?.format ?? format).toUpperCase() },
+ { label: l('文案长度', 'Length'), value: l(`${result?.characterCount ?? characterCount} 字`, `${result?.characterCount ?? characterCount} characters`) }
]}
/>
);
@@ -198,12 +353,26 @@ export default function SmartDubbingWorkspace(props: {
<CreatorToolShell
title={l('智能配音', 'AI Dubbing')}
subtitle={l('自然音色、表达风格与可下载音频', 'Natural voices, expressive delivery, and downloadable audio')}
- context={result ? l(`${result.format.toUpperCase()} 配音已完成`, `${result.format.toUpperCase()} dubbing ready`) : currentStep === 0 ? l('正在编辑文案', 'Editing script') : currentStep === 1 ? `${voiceName || voice || providerLabel(provider, l)} · ${speed.toFixed(2)}x` : l('等待生成', 'Ready to generate')}
- initialMessage={l('把需要配音的文案发给我,再选择音色和表达风格。', 'Send me the script, then choose a voice and delivery style.')}
- suggestions={result ? [l('换成温暖风格', 'Use a warm style'), l('语速慢一点', 'Make it slower')] : [l('填入示例文案', 'Use a sample script'), l('使用专业风格', 'Use a professional style')]}
+ context={result
+ ? l(`${result.format.toUpperCase()} 配音已完成`, `${result.format.toUpperCase()} dubbing ready`)
+ : currentStep === 0
+ ? l('正在编辑文案', 'Editing script')
+ : currentStep === 1
+ ? `${voiceName || voice || providerLabel(provider, l)} · ${speed.toFixed(2)}x`
+ : generating
+ ? l('正在生成配音', 'Generating dubbing')
+ : l('等待生成', 'Ready to generate')}
+ stepLabel={generating ? l('正在生成配音', 'Generating dubbing') : l('智能配音', 'AI dubbing')}
+ currentIssue={visibleError || undefined}
+ suggestions={result
+ ? [l('换成温暖风格', 'Use a warm style'), l('语速慢一点', 'Make it slower')]
+ : [l('填入示例文案', 'Use a sample script'), l('使用专业风格', 'Use a professional style')]}
placeholder={props.promptHint ?? l('输入配音文案或调整要求', 'Enter a script or delivery request')}
onBack={props.onBack}
onCommand={handleCommand}
+ onCancelTask={() => void cancelTask()}
+ onResumeTask={() => void resumeTask()}
+ taskControlPending={taskControlPending}
contentClassName="smart-dubbing-workspace-content"
>
<div className="creator-tool-stack smart-dubbing-stack">
@@ -237,12 +406,12 @@ export default function SmartDubbingWorkspace(props: {
rows={12}
maxLength={5000}
value={text}
- onChange={event => { setText(event.target.value); setResult(undefined); setError(''); }}
+ onChange={event => updateText(event.target.value)}
placeholder={l('输入需要转换为语音的文案', 'Enter the script to convert into speech')}
aria-label={l('配音文案内容', 'Dubbing script content')}
/>
</label>
- <button className="smart-dubbing-sample" type="button" onClick={() => setText(l(sampleTextZh, sampleTextEn))}>
+ <button className="smart-dubbing-sample" type="button" onClick={() => updateText(l(sampleTextZh, sampleTextEn))}>
<WandSparkles size={14} strokeWidth={1.8} aria-hidden="true" />
{l('填入示例文案', 'Use sample script')}
</button>
@@ -268,7 +437,11 @@ export default function SmartDubbingWorkspace(props: {
onChange={(voiceId, selectedVoice) => {
setVoice(voiceId);
setVoiceName(selectedVoice?.name ?? voiceId);
- setResult(undefined);
+ session?.updateDraft({
+ voiceCode: voiceId,
+ voiceName: selectedVoice?.name ?? voiceId
+ });
+ setError('');
}}
onVoiceResolved={selectedVoice => setVoiceName(selectedVoice.name)}
/>
@@ -276,18 +449,18 @@ export default function SmartDubbingWorkspace(props: {
<div className="smart-dubbing-control-group">
<span>{l('表达风格', 'Delivery style')}</span>
<div className="creator-tool-segmented smart-dubbing-style-options" role="radiogroup" aria-label={l('表达风格', 'Delivery style')}>
- {styles.map(item => <button type="button" role="radio" aria-checked={style === item.value} aria-selected={style === item.value} key={item.value} onClick={() => { setStyle(item.value); setResult(undefined); }}>{l(item.zh, item.en)}</button>)}
+ {styles.map(item => <button type="button" role="radio" aria-checked={style === item.value} aria-selected={style === item.value} key={item.value} onClick={() => updateStyle(item.value)}>{l(item.zh, item.en)}</button>)}
</div>
</div>
<label className="smart-dubbing-speed">
<span><span><Gauge size={15} strokeWidth={1.8} aria-hidden="true" />{l('语速', 'Speaking rate')}</span><output>{speed.toFixed(2)}x</output></span>
- <input type="range" min="0.75" max="1.25" step="0.05" value={speed} onChange={event => { setSpeed(Number(event.target.value)); setResult(undefined); }} />
+ <input type="range" min="0.75" max="1.25" step="0.05" value={speed} onChange={event => updateSpeed(Number(event.target.value))} />
<small><span>0.75x</span><span>1.00x</span><span>1.25x</span></small>
</label>
<div className="smart-dubbing-control-group">
<span>{l('音频格式', 'Audio format')}</span>
<div className="creator-tool-segmented smart-dubbing-format-options" role="radiogroup" aria-label={l('音频格式', 'Audio format')}>
- {(['mp3', 'wav'] as const).map(value => <button type="button" role="radio" aria-checked={format === value} aria-selected={format === value} key={value} onClick={() => { setFormat(value); setResult(undefined); }}>{value.toUpperCase()}</button>)}
+ {(['mp3', 'wav'] as const).map(value => <button type="button" role="radio" aria-checked={format === value} aria-selected={format === value} key={value} onClick={() => updateFormat(value)}>{value.toUpperCase()}</button>)}
</div>
</div>
</section>
@@ -305,16 +478,16 @@ export default function SmartDubbingWorkspace(props: {
<div><strong>{result.fileName}</strong><small>{formatBytes(result.size)} · {result.model}</small></div>
<audio controls src={audioUrl} aria-label={l('智能配音试听', 'AI dubbing preview')} />
<div className="smart-dubbing-result-actions">
- <button type="button" onClick={generate} disabled={generating}><RotateCcw size={15} strokeWidth={1.8} aria-hidden="true" />{l('重新生成', 'Regenerate')}</button>
+ <button type="button" onClick={() => void generate()} disabled={generating}><RotateCcw size={15} strokeWidth={1.8} aria-hidden="true" />{l('重新生成', 'Regenerate')}</button>
<button className="creator-tool-primary" type="button" onClick={download}><Download size={15} strokeWidth={1.8} aria-hidden="true" />{l('下载音频', 'Download audio')}</button>
</div>
</div>
) : (
<div className="smart-dubbing-ready">
<span><Sparkles size={24} strokeWidth={1.6} aria-hidden="true" /></span>
- <strong>{l('准备生成配音', 'Ready to generate dubbing')}</strong>
+ <strong>{generating ? l('正在生成配音', 'Generating dubbing') : l('准备生成配音', 'Ready to generate dubbing')}</strong>
<p>{l('文案、音色和输出格式已经就绪', 'The script, voice, and output format are ready')}</p>
- <button className="creator-tool-primary" type="button" onClick={generate} disabled={generating}>
+ <button className="creator-tool-primary" type="button" onClick={() => void generate()} disabled={generating}>
{generating ? <LoaderCircle className="smart-dubbing-spinner" size={16} strokeWidth={1.8} aria-hidden="true" /> : <Mic2 size={16} strokeWidth={1.8} aria-hidden="true" />}
{generating ? l('正在生成', 'Generating') : l('开始生成', 'Generate')}
</button>
@@ -324,7 +497,14 @@ export default function SmartDubbingWorkspace(props: {
{summary}
</div>
) : null}
- {error ? <p className="creator-tool-error smart-dubbing-error" role="alert">{error}</p> : null}
+ {visibleError ? (
+ <div className="creator-tool-error smart-dubbing-error" role="alert">
+ <span>{visibleError}</span>
+ {settingsHref ? (
+ <a href={settingsHref}>{l('打开配音服务设置', 'Open voice service settings')}</a>
+ ) : null}
+ </div>
+ ) : null}
{notice ? <p className="creator-tool-notice" role="status">{notice}</p> : null}
</div>
@@ -339,6 +519,30 @@ export default function SmartDubbingWorkspace(props: {
);
}
+function readLatestResult(artifacts: CreatorArtifact[]): DubbingResult | undefined {
+ const artifact = [...artifacts].reverse().find(candidate => (
+ candidate.kind === 'dubbed_audio'
+ && candidate.path !== null
+ && candidate.status === 'completed'
+ ));
+ if (artifact === undefined) return undefined;
+ const metadata = artifact.metadata;
+ const provider = readProvider(metadata.provider);
+ return {
+ artifact,
+ fileName: readString(metadata.fileName) || `OpenCreator-dubbing.${readFormat(metadata.format)}`,
+ size: readNonNegativeNumber(metadata.bytes),
+ provider: provider === 'aliyun' || provider === 'minimax' ? provider : 'openai',
+ model: readString(metadata.model),
+ voice: readString(metadata.voiceCode),
+ voiceName: readString(metadata.voiceName) || readString(metadata.voiceCode),
+ style: readStyle(metadata.style),
+ speed: readSpeed(metadata.speed),
+ format: readFormat(metadata.format),
+ characterCount: readNonNegativeNumber(metadata.characterCount)
+ };
+}
+
function providerLabel(
provider: CreatorTtsProvider,
l: (zh: string, en: string) => string
@@ -358,14 +562,69 @@ function formatGenerationError(error: unknown, l: (zh: string, en: string) => st
const code = typeof error === 'object' && error !== null && 'code' in error
? String((error as { code?: unknown }).code)
: '';
- if (code === 'SMART_DUBBING_CONFIG_REQUIRED') {
+ if (code === 'SMART_DUBBING_CONFIG_REQUIRED' || code === 'creator_tts_config_missing') {
return l('请先在设置的配音服务中配置当前服务商的 API Key', 'Configure the selected TTS provider API key in Settings first');
}
- if (code === 'SMART_DUBBING_PROVIDER_UNSUPPORTED') {
+ if (code === 'SMART_DUBBING_PROVIDER_UNSUPPORTED' || code === 'unsupported_capability') {
return l('当前配音服务商不支持智能配音,请在设置中选择阿里云百炼、OpenAI 或 MiniMax', 'Select Alibaba Cloud, OpenAI, or MiniMax for AI dubbing.');
}
- if (code === 'SMART_DUBBING_UPSTREAM_ERROR') {
+ if (
+ code === 'SMART_DUBBING_UPSTREAM_ERROR'
+ || code === 'creator_tts_upstream_error'
+ || code === 'creator_tts_runtime_unavailable'
+ ) {
return l('配音服务请求失败,请检查服务配置和网络后重试', 'The dubbing request failed. Check the service configuration and network, then retry.');
}
- return error instanceof Error ? error.message : l('配音生成失败,请稍后重试', 'Dubbing generation failed. Try again later.');
+ const message = typeof error === 'object' && error !== null && 'message' in error
+ ? String((error as { message?: unknown }).message ?? '')
+ : error instanceof Error
+ ? error.message
+ : '';
+ return message || l('配音生成失败,请稍后重试', 'Dubbing generation failed. Try again later.');
+}
+
+function readStep(value: CreatorJson | undefined, fallback: DubbingStep): DubbingStep {
+ return value === 0 || value === 1 || value === 2 ? value : fallback;
+}
+
+function readString(value: CreatorJson | undefined): string {
+ return typeof value === 'string' ? value : '';
+}
+
+function readProvider(value: CreatorJson | undefined): CreatorTtsProvider | undefined {
+ return value === 'openai' || value === 'aliyun' || value === 'minimax' || value === 'edge-tts'
+ ? value
+ : undefined;
+}
+
+function readStyle(value: CreatorJson | undefined): SmartDubbingStyle {
+ return typeof value === 'string' && (smartDubbingStyles as readonly string[]).includes(value)
+ ? value as SmartDubbingStyle
+ : 'natural';
+}
+
+function readSpeed(value: CreatorJson | undefined): number {
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0.75 && value <= 1.25
+ ? value
+ : 1;
+}
+
+function readFormat(value: CreatorJson | undefined): SmartDubbingFormat {
+ return value === 'wav' ? 'wav' : 'mp3';
+}
+
+function readNonNegativeNumber(value: CreatorJson | undefined): number {
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : 0;
+}
+
+function shouldOpenTtsSettings(
+ provider: CreatorTtsProvider,
+ ...codes: Array<string | null | undefined>
+): boolean {
+ return provider === 'edge-tts' || codes.some(code => (
+ code === 'SMART_DUBBING_CONFIG_REQUIRED'
+ || code === 'SMART_DUBBING_PROVIDER_UNSUPPORTED'
+ || code === 'creator_tts_config_missing'
+ || code === 'unsupported_capability'
+ ));
}
diff --git a/apps/web/src/features/dashboard/creator-panel-adapters.ts b/apps/web/src/features/dashboard/creator-panel-adapters.ts
index 5925e0e0..ca4796f0 100644
--- a/apps/web/src/features/dashboard/creator-panel-adapters.ts
+++ b/apps/web/src/features/dashboard/creator-panel-adapters.ts
@@ -310,9 +310,53 @@ export const videoDownloadPanelAdapter: CreatorPanelAdapter = {
}
};
+export const smartDubbingPanelAdapter: CreatorPanelAdapter = {
+ id: 'smart-dubbing',
+ composerPlaceholder: l => l(
+ '询问生成状态,或调整文案、音色、风格和语速',
+ 'Ask about progress or adjust the script, voice, delivery, and speed'
+ ),
+ stageLabel(stageId, l) {
+ if (stageId === 'tts') return l('生成配音', 'Generate dubbing');
+ return l('智能配音任务', 'AI dubbing task');
+ },
+ phaseLabel(phase, l) {
+ const labels: Record<string, string> = {
+ validating: l('检查配音设置', 'Checking dubbing settings'),
+ generating_voice: l('生成配音音频', 'Generating dubbing audio'),
+ finalizing_output: l('整理配音文件', 'Finalizing the dubbing file'),
+ completed: l('配音音频已生成', 'Dubbing audio generated')
+ };
+ return labels[phase] ?? genericPhaseLabel(phase, l);
+ },
+ activityStageId: readActivityStageId,
+ normalizeActivity(activity, l) {
+ if (activity.action === 'run-stage') {
+ return { label: l('开始生成配音', 'Started generating dubbing'), fields: [] };
+ }
+ return normalizeCommonActivity(
+ activity,
+ l,
+ smartDubbingPanelAdapter,
+ {},
+ smartDubbingFieldLabel
+ );
+ },
+ readStageProgress: readStandardProgress,
+ runningProgressText(_stage, progress, l) {
+ return progress.phase === null
+ ? null
+ : smartDubbingPanelAdapter.phaseLabel(progress.phase, l);
+ },
+ succeededProgressText(_stage, l) {
+ return l('配音音频已生成', 'Dubbing audio generated');
+ }
+};
+
export function creatorPanelAdapterFor(templateId: string): CreatorPanelAdapter {
if (templateId === 'video-translation') return videoTranslationPanelAdapter;
if (templateId === 'video-download') return videoDownloadPanelAdapter;
+ if (templateId === 'smart-dubbing') return smartDubbingPanelAdapter;
if (templateId === 'cover') return coverPanelAdapter;
return genericAdapter;
}
@@ -426,6 +470,23 @@ function videoDownloadFieldLabel(
return labels[field] ?? null;
}
+function smartDubbingFieldLabel(
+ field: string,
+ l: CreatorPanelLocalize
+): string | null {
+ const labels: Record<string, string> = {
+ text: l('配音文案', 'Dubbing script'),
+ ttsProvider: l('配音服务', 'TTS provider'),
+ ttsModel: l('配音模型', 'TTS model'),
+ voiceCode: l('音色', 'Voice'),
+ voiceName: l('音色名称', 'Voice name'),
+ style: l('表达风格', 'Delivery style'),
+ speed: l('语速', 'Speaking rate'),
+ format: l('音频格式', 'Audio format')
+ };
+ return labels[field] ?? null;
+}
+
function readActivityStageId(activity: CreatorActivity): string | null {
const structured = readString(activity.details.stageId);
if (structured !== null) return structured;
diff --git a/apps/web/src/features/dashboard/creator-workspace.ts b/apps/web/src/features/dashboard/creator-workspace.ts
index 2a623797..11340012 100644
--- a/apps/web/src/features/dashboard/creator-workspace.ts
+++ b/apps/web/src/features/dashboard/creator-workspace.ts
@@ -24,6 +24,7 @@ export const creatorWorkspaces = [
export const visibleCreatorWorkspaces = [
'video-translation',
'video-download',
+ 'smart-dubbing',
'cover-generator',
'image-generation'
] as const satisfies readonly CreatorWorkspace[];
@@ -33,6 +34,7 @@ export const creatorRuntimeWorkspaces = [
'video-download',
'stickman-video',
'auto-clips',
+ 'smart-dubbing',
'cover-generator',
'image-generation'
] as const satisfies readonly CreatorWorkspace[];
@@ -44,6 +46,7 @@ const templateByWorkspace: Record<CreatorRuntimeWorkspace, string> = {
'video-download': 'video-download',
'stickman-video': 'stickman-video',
'auto-clips': 'auto-clip',
+ 'smart-dubbing': 'smart-dubbing',
'cover-generator': 'cover',
'image-generation': 'image-generation'
};
diff --git a/apps/web/src/features/dashboard/dashboard.css b/apps/web/src/features/dashboard/dashboard.css
index cc44e5dc..89dbbe9c 100644
--- a/apps/web/src/features/dashboard/dashboard.css
+++ b/apps/web/src/features/dashboard/dashboard.css
@@ -2851,6 +2851,10 @@
.smart-dubbing-error {
min-height: 34px;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 12px;
margin: 10px 0 0;
padding: 8px 11px;
border-left: 2px solid #c94b4b;
@@ -2859,6 +2863,17 @@
font-size: 12px;
}
+.smart-dubbing-error a {
+ flex: 0 0 auto;
+ color: var(--accent);
+ font-weight: 620;
+ text-decoration: none;
+}
+
+.smart-dubbing-error a:hover {
+ text-decoration: underline;
+}
+
.smart-dubbing-actions {
margin-top: 0;
padding-top: 14px;