// e2e-en.js — 创建英文书,等生成,触发音频,验证英文 const { PrismaClient } = require('@prisma/client'); const { bookStore } = require('./dist/modules/book-generator/book-generator.store.js'); const p = new PrismaClient(); (async () => { const LANG = 'en-US'; console.log(`=== 1. 创建英文书 (${LANG}) ===`); const book = await bookStore.create({ userId: 1, title: 'EN E2E Audit Test', description: 'Test English content generation and English audio', bookScale: '500', targetLanguage: LANG, autoGenerateContent: true, autoGenerateAudio: false, }); console.log(` bookId=${book.id} targetLanguage=${book.targetLanguage}`); const bookId = parseInt(book.id); console.log('=== 2. 等 60s AI 生成内容 ==='); await new Promise(r => setTimeout(r, 60000)); const chs = await p.bookChapter.findMany({ where: { bookId }, select: { id: true, title: true, content: true, genStage: true } }); console.log(` 共 ${chs.length} 章`); for (const ch of chs) { const sample = (ch.content || '').substring(0, 200).replace(/\n/g, ' / '); console.log(` ch#${ch.id} [${ch.genStage}] ${ch.title}`); console.log(` ${sample}`); // 检测是否有中文(检测 unicode 范围) const hasChinese = /[一-鿿]/.test(ch.content || ''); console.log(` has Chinese: ${hasChinese ? '❌ 有中文!' : '✅ 纯英文'}`); } console.log('=== 3. 触发音频生成 ==='); for (const ch of chs) { try { await bookStore.generateChapterAudioById(ch.id, 1, undefined, {}); console.log(` queued ch#${ch.id}`); } catch (e) { console.log(` err: ${e.message.slice(0, 100)}`); } } console.log('=== 4. 等 90s 让 TTS 跑完 ==='); await new Promise(r => setTimeout(r, 90000)); console.log('=== 5. 查 BookChapter.audioUrl + TtsTask 状态 ==='); for (const ch of chs) { const full = await p.bookChapter.findUnique({ where: { id: ch.id }, select: { audioUrl: true, audioDuration: true } }); const tasks = await p.ttsTask.findMany({ where: { chapterId: ch.id }, select: { voiceId: true, targetLanguage: true, preferredVendor: true, status: true } }); console.log(` ch#${ch.id} audioUrl=${full.audioUrl ? '✅ ' + full.audioUrl.slice(-50) : '❌ 无'} dur=${full.audioDuration}s`); for (const t of tasks) { console.log(` ttsTask status=${t.status} voice=${t.voiceId} lang=${t.targetLanguage} vendor=${t.preferredVendor}`); } } await p.$disconnect(); })();