test-en-e2e.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // e2e-en.js — 创建英文书,等生成,触发音频,验证英文
  2. const { PrismaClient } = require('@prisma/client');
  3. const { bookStore } = require('./dist/modules/book-generator/book-generator.store.js');
  4. const p = new PrismaClient();
  5. (async () => {
  6. const LANG = 'en-US';
  7. console.log(`=== 1. 创建英文书 (${LANG}) ===`);
  8. const book = await bookStore.create({
  9. userId: 1,
  10. title: 'EN E2E Audit Test',
  11. description: 'Test English content generation and English audio',
  12. bookScale: '500',
  13. targetLanguage: LANG,
  14. autoGenerateContent: true,
  15. autoGenerateAudio: false,
  16. });
  17. console.log(` bookId=${book.id} targetLanguage=${book.targetLanguage}`);
  18. const bookId = parseInt(book.id);
  19. console.log('=== 2. 等 60s AI 生成内容 ===');
  20. await new Promise(r => setTimeout(r, 60000));
  21. const chs = await p.bookChapter.findMany({ where: { bookId }, select: { id: true, title: true, content: true, genStage: true } });
  22. console.log(` 共 ${chs.length} 章`);
  23. for (const ch of chs) {
  24. const sample = (ch.content || '').substring(0, 200).replace(/\n/g, ' / ');
  25. console.log(` ch#${ch.id} [${ch.genStage}] ${ch.title}`);
  26. console.log(` ${sample}`);
  27. // 检测是否有中文(检测 unicode 范围)
  28. const hasChinese = /[一-鿿]/.test(ch.content || '');
  29. console.log(` has Chinese: ${hasChinese ? '❌ 有中文!' : '✅ 纯英文'}`);
  30. }
  31. console.log('=== 3. 触发音频生成 ===');
  32. for (const ch of chs) {
  33. try {
  34. await bookStore.generateChapterAudioById(ch.id, 1, undefined, {});
  35. console.log(` queued ch#${ch.id}`);
  36. } catch (e) {
  37. console.log(` err: ${e.message.slice(0, 100)}`);
  38. }
  39. }
  40. console.log('=== 4. 等 90s 让 TTS 跑完 ===');
  41. await new Promise(r => setTimeout(r, 90000));
  42. console.log('=== 5. 查 BookChapter.audioUrl + TtsTask 状态 ===');
  43. for (const ch of chs) {
  44. const full = await p.bookChapter.findUnique({ where: { id: ch.id }, select: { audioUrl: true, audioDuration: true } });
  45. const tasks = await p.ttsTask.findMany({ where: { chapterId: ch.id }, select: { voiceId: true, targetLanguage: true, preferredVendor: true, status: true } });
  46. console.log(` ch#${ch.id} audioUrl=${full.audioUrl ? '✅ ' + full.audioUrl.slice(-50) : '❌ 无'} dur=${full.audioDuration}s`);
  47. for (const t of tasks) {
  48. console.log(` ttsTask status=${t.status} voice=${t.voiceId} lang=${t.targetLanguage} vendor=${t.preferredVendor}`);
  49. }
  50. }
  51. await p.$disconnect();
  52. })();