verify-new-audio.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const { PrismaClient } = require('@prisma/client');
  2. const prisma = new PrismaClient();
  3. async function verifyNewAudio() {
  4. console.log('\n✅ 验证新生成的音频\n');
  5. console.log('=' .repeat(60));
  6. const bookId = 5;
  7. const chapterId = 1214;
  8. const chapter = await prisma.bookChapter.findUnique({
  9. where: { id: chapterId },
  10. select: {
  11. id: true,
  12. title: true,
  13. audioUrl: true,
  14. audioDuration: true,
  15. }
  16. });
  17. console.log(`章节: ${chapter.title}`);
  18. console.log(`ID: ${chapter.id}`);
  19. console.log(`audioUrl: ${chapter.audioUrl || '无'}`);
  20. console.log(`audioDuration: ${chapter.audioDuration || 0}秒\n`);
  21. // 检查文件
  22. const fs = require('fs');
  23. const path = require('path');
  24. const uuid = chapter.audioUrl.match(/\/uploads\/([^\/]+)\//)?.[1];
  25. if (uuid) {
  26. const outputPath = path.join(__dirname, 'uploads', uuid, 'output.mp3');
  27. const segmentPath = path.join(__dirname, 'uploads', uuid, 'segment_0.mp3');
  28. console.log('📁 文件检查:\n');
  29. console.log(`output.mp3: ${fs.existsSync(outputPath) ? '✅ 存在' : '❌ 不存在'}`);
  30. console.log(`segment_0.mp3: ${fs.existsSync(segmentPath) ? '✅ 存在' : '❌ 不存在'}\n`);
  31. if (fs.existsSync(outputPath)) {
  32. const stats = fs.statSync(outputPath);
  33. console.log(`output.mp3 大小: ${(stats.size / 1024).toFixed(2)} KB\n`);
  34. }
  35. console.log('=' .repeat(60));
  36. console.log('\n📋 验证结论:\n');
  37. if (chapter.audioUrl?.includes('output.mp3') && fs.existsSync(outputPath)) {
  38. console.log('✅✅✅ 完美!\n');
  39. console.log(' 1. 音频URL使用output.mp3 ✅');
  40. console.log(' 2. 文件output.mp3存在 ✅');
  41. console.log(' 3. 代码修复已生效 ✅\n');
  42. console.log('前端访问:');
  43. console.log(` http://localhost:5173/#/pages/player/index?id=${chapterId}\n`);
  44. } else {
  45. console.log('❌ 验证失败\n');
  46. }
  47. }
  48. await prisma.$disconnect();
  49. }
  50. verifyNewAudio().catch(console.error);