| 123456789101112131415161718192021222324252627282930313233343536 |
- export function createTTSMock(options: TTSMockOptions = {}) {
- const { shouldFail = false, delayMs = 0, audioUrl = 'https://mock-cdn.example.com/audio/test.mp3', duration = 120 } = options;
- return {
- name: 'mock-tts' as const,
- vendor: 'mock' as const,
- mode: 'mock' as const,
- maxTextLength: 5000,
- concurrency: 3,
- synthesize: vi.fn().mockImplementation(async (text: string, voice: string, params: any, outputPath: string) => {
- if (delayMs > 0) {
- await new Promise((resolve) => setTimeout(resolve, delayMs));
- }
- if (shouldFail) {
- throw new Error('Mock TTS failure');
- }
- return {
- audioUrl,
- duration,
- size: 2048000,
- textLength: text.length,
- };
- }),
- getVoices: vi.fn().mockReturnValue([
- { id: 'zh_female_qingxin', name: '清心女声', language: 'zh-CN' },
- { id: 'zh_male_qingxin', name: '清心男声', language: 'zh-CN' },
- ]),
- };
- }
- export interface TTSMockOptions {
- shouldFail?: boolean;
- delayMs?: number;
- audioUrl?: string;
- duration?: number;
- }
|