koishi-plugin-minimax-vits 0.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export interface Config {
11
11
  ttsApiKey?: string;
12
12
  defaultVoice?: string;
13
13
  speechModel?: string;
14
+ debug?: boolean;
14
15
  }
15
16
  export declare const Config: Schema<Config>;
16
17
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -15,12 +15,107 @@ exports.Config = koishi_1.Schema.object({
15
15
  ttsApiKey: koishi_1.Schema.string().description('TTS API Key(如果与主 API Key 不同)').role('secret'),
16
16
  defaultVoice: koishi_1.Schema.string().default('Chinese_female_gentle').description('默认语音 ID'),
17
17
  speechModel: koishi_1.Schema.string().default('speech-2.6').description('TTS 模型名称'),
18
+ debug: koishi_1.Schema.boolean().default(false).description('启用调试模式(输出详细日志)'),
18
19
  }).description('MiniMax VITS 配置');
20
+ /**
21
+ * 调用 MiniMax TTS API 生成语音
22
+ */
23
+ async function generateSpeech(ctx, config, text, voice) {
24
+ const logger = ctx.logger('minimax-vits');
25
+ const apiKey = config.ttsApiKey || config.apiKey;
26
+ const apiBase = config.apiBase || 'https://api.minimaxi.com/v1';
27
+ const model = config.speechModel || 'speech-2.6';
28
+ const voiceId = voice || config.defaultVoice || 'Chinese_female_gentle';
29
+ if (config.debug) {
30
+ logger.debug(`调用 TTS API: ${apiBase}/text_to_speech`);
31
+ logger.debug(`参数: model=${model}, voice=${voiceId}, text=${text.substring(0, 50)}...`);
32
+ }
33
+ try {
34
+ const response = await ctx.http.post(`${apiBase}/text_to_speech`, {
35
+ model,
36
+ voice_id: voiceId,
37
+ text,
38
+ }, {
39
+ headers: {
40
+ 'Authorization': `Bearer ${apiKey}`,
41
+ 'Content-Type': 'application/json',
42
+ },
43
+ responseType: 'arraybuffer',
44
+ });
45
+ if (config.debug) {
46
+ logger.debug('TTS API 调用成功');
47
+ }
48
+ return Buffer.from(response);
49
+ }
50
+ catch (error) {
51
+ logger.error('TTS API 调用失败:', error);
52
+ if (config.debug) {
53
+ logger.error('错误详情:', error.response?.data || error.message);
54
+ }
55
+ return null;
56
+ }
57
+ }
19
58
  function apply(ctx, config) {
20
- ctx.logger('minimax-vits').info('MiniMax VITS 插件已加载');
21
- ctx.logger('minimax-vits').info(`API Key: ${config.apiKey ? '已配置' : '未配置'}`);
22
- ctx.logger('minimax-vits').info(`Group ID: ${config.groupId || '未配置'}`);
59
+ const logger = ctx.logger('minimax-vits');
60
+ logger.info('MiniMax VITS 插件已加载');
61
+ if (config.debug) {
62
+ logger.info('调试模式已启用');
63
+ logger.debug(`API Key: ${config.apiKey ? '已配置' : '未配置'}`);
64
+ logger.debug(`Group ID: ${config.groupId || '未配置'}`);
65
+ logger.debug(`API Base: ${config.apiBase || 'https://api.minimaxi.com/v1'}`);
66
+ logger.debug(`TTS Enabled: ${config.ttsEnabled || false}`);
67
+ }
68
+ else {
69
+ logger.info(`API Key: ${config.apiKey ? '已配置' : '未配置'}`);
70
+ logger.info(`Group ID: ${config.groupId || '未配置'}`);
71
+ }
23
72
  if (config.ttsEnabled) {
24
- ctx.logger('minimax-vits').info('TTS 功能已启用');
73
+ logger.info('TTS 功能已启用');
25
74
  }
75
+ // 注册测试指令
76
+ ctx.command('minivits.test <text:text>', '测试 MiniMax TTS 功能')
77
+ .option('voice', '-v <voice>', { fallback: config.defaultVoice || 'Chinese_female_gentle' })
78
+ .action(async ({ session, options }, text) => {
79
+ if (!session) {
80
+ return '会话不存在';
81
+ }
82
+ if (!text) {
83
+ return '请提供要测试的文本内容。\n用法: minivits.test <文本内容> [-v <语音ID>]';
84
+ }
85
+ if (!config.ttsEnabled) {
86
+ return 'TTS 功能未启用,请在配置中设置 ttsEnabled: true';
87
+ }
88
+ const logger = ctx.logger('minimax-vits');
89
+ const voiceId = options?.voice || config.defaultVoice || 'Chinese_female_gentle';
90
+ if (config.debug) {
91
+ logger.debug(`收到测试请求: text=${text}, voice=${voiceId}`);
92
+ }
93
+ await session.send('正在生成语音,请稍候...');
94
+ const audioBuffer = await generateSpeech(ctx, config, text, voiceId);
95
+ if (!audioBuffer) {
96
+ return '语音生成失败,请检查配置和网络连接';
97
+ }
98
+ if (config.debug) {
99
+ logger.debug(`语音生成成功,大小: ${audioBuffer.length} bytes`);
100
+ }
101
+ // 发送语音文件(使用 base64 编码)
102
+ return (0, koishi_1.h)('audio', { src: `base64://${audioBuffer.toString('base64')}`, type: 'audio/mpeg' });
103
+ });
104
+ // 注册调试信息查看指令
105
+ ctx.command('minivits.debug', '查看 MiniMax VITS 插件调试信息')
106
+ .action(() => {
107
+ const info = [
108
+ '=== MiniMax VITS 插件调试信息 ===',
109
+ `API Key: ${config.apiKey ? '已配置' : '未配置'}`,
110
+ `Group ID: ${config.groupId || '未配置'}`,
111
+ `API Base: ${config.apiBase || 'https://api.minimaxi.com/v1'}`,
112
+ `模型: ${config.model || 'abab6.5s-chat'}`,
113
+ `TTS 功能: ${config.ttsEnabled ? '已启用' : '已禁用'}`,
114
+ `调试模式: ${config.debug ? '已启用' : '已禁用'}`,
115
+ config.ttsEnabled ? `默认语音: ${config.defaultVoice || 'Chinese_female_gentle'}` : '',
116
+ config.ttsEnabled ? `TTS 模型: ${config.speechModel || 'speech-2.6'}` : '',
117
+ '==============================',
118
+ ].filter(Boolean).join('\n');
119
+ return info;
120
+ });
26
121
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-minimax-vits",
3
3
  "description": "使用 minimax 国际版生成语音,适配 chatluna",
4
- "version": "0.0.1",
4
+ "version": "1.0.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [