UNPKG

@webgal-tools/voice

Version:
96 lines 4.84 kB
import { TranslationServiceFactory } from './factory.js'; import { NoTranslationService, StaticTranslationService, AutoEmotionTranslationService } from './implementations.js'; /** * 简单的测试函数,验证翻译服务接口的解耦 */ export async function testTranslationServices() { console.log('🧪 开始测试翻译服务接口解耦...'); // 模拟配置 const globalTranslateConfig = { check: true, model_type: 'ollama', base_url: 'http://localhost:11434/api', model_name: 'glm4:9b', context_size: 2, additional_prompt: '测试提示词' }; const characterConfig = { character_name: '测试角色', gpt: 'test_gpt.ckpt', sovits: 'test_sovits.pth', ref_audio: 'test_audio.wav', ref_text: '测试文本', translate_to: '日文', prompt: '测试角色提示词' }; const gptSovitsPath = '/path/to/gpt-sovits'; // 创建工厂 const factory = new TranslationServiceFactory(gptSovitsPath); // 测试1:空白翻译服务(translate.check = false) console.log('\n📝 测试1:空白翻译服务'); const noTranslateConfig = { ...globalTranslateConfig, check: false }; const noTranslateService = factory.createTranslationService('角色1', characterConfig, noTranslateConfig); console.log(`服务类型: ${noTranslateService.constructor.name}`); console.log(`是否为空白服务: ${noTranslateService instanceof NoTranslationService}`); // 测试2:静态翻译服务(translate.check = true, auto = false) console.log('\n📝 测试2:静态翻译服务'); const staticConfig = { ...characterConfig, auto: false }; const staticService = factory.createTranslationService('角色2', staticConfig, globalTranslateConfig); console.log(`服务类型: ${staticService.constructor.name}`); console.log(`是否为静态服务: ${staticService instanceof StaticTranslationService}`); // 测试3:自动情绪识别翻译服务(translate.check = true, auto = true) console.log('\n📝 测试3:自动情绪识别翻译服务'); const autoConfig = { ...characterConfig, auto: true }; const autoService = factory.createTranslationService('角色3', autoConfig, globalTranslateConfig); console.log(`服务类型: ${autoService.constructor.name}`); console.log(`是否为自动服务: ${autoService instanceof AutoEmotionTranslationService}`); // 测试4:无翻译目标语言(translate_to 为空) console.log('\n📝 测试4:无翻译目标语言'); const noTargetConfig = { ...characterConfig, translate_to: undefined }; const noTargetService = factory.createTranslationService('角色4', noTargetConfig, globalTranslateConfig); console.log(`服务类型: ${noTargetService.constructor.name}`); console.log(`是否为空白服务: ${noTargetService instanceof NoTranslationService}`); console.log('\n✅ 翻译服务接口解耦测试完成!'); } /** * 测试翻译服务接口的统一性 */ export async function testTranslationInterface() { console.log('🧪 开始测试翻译服务接口统一性...'); // 创建不同的翻译服务实例 const noTranslateService = new NoTranslationService(); const staticService = new StaticTranslationService(null); // 模拟TranslateService const autoService = new AutoEmotionTranslationService(null, '/path/to/gpt-sovits'); // 模拟TranslateService const testConfig = { check: true, model_type: 'ollama', base_url: 'http://localhost:11434/api', model_name: 'glm4:9b' }; const testCharacterConfig = { character_name: '测试角色', gpt: 'test.ckpt', sovits: 'test.pth', ref_audio: 'test.wav', ref_text: '测试' }; // 测试所有服务都实现了相同的接口 const services = [noTranslateService, staticService, autoService]; for (let i = 0; i < services.length; i++) { const service = services[i]; console.log(`\n📝 测试服务 ${i + 1}: ${service.constructor.name}`); try { const result = await service.translate('测试角色', '你好,世界!', '日文', testConfig, testCharacterConfig, '测试上下文'); console.log(`✅ 接口调用成功`); console.log(` 翻译结果: ${result.translatedText}`); console.log(` 是否成功: ${result.success}`); console.log(` 是否自动模式: ${result.isAutoMode}`); console.log(` 错误信息: ${result.error || '无'}`); } catch (error) { console.log(`❌ 接口调用失败: ${error}`); } } console.log('\n✅ 翻译服务接口统一性测试完成!'); } //# sourceMappingURL=test.js.map