@ww_nero/media 1.1.0 → 1.2.0
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/index.js +8 -2
- package/package.json +1 -1
- package/utils/tts.js +9 -3
package/index.js
CHANGED
|
@@ -114,7 +114,7 @@ const resolveAudioFile = (workingDir, rawPath) => {
|
|
|
114
114
|
const server = new Server(
|
|
115
115
|
{
|
|
116
116
|
name: 'media',
|
|
117
|
-
version: '1.
|
|
117
|
+
version: '1.2.0',
|
|
118
118
|
},
|
|
119
119
|
{
|
|
120
120
|
capabilities: {
|
|
@@ -157,6 +157,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
157
157
|
type: 'string',
|
|
158
158
|
description: '需要合成语音的文本内容',
|
|
159
159
|
},
|
|
160
|
+
gender: {
|
|
161
|
+
type: 'string',
|
|
162
|
+
enum: ['female', 'male'],
|
|
163
|
+
description: '语音性别,female 为女声,male 为男声,默认为 female',
|
|
164
|
+
},
|
|
160
165
|
},
|
|
161
166
|
required: ['working_directory', 'text'],
|
|
162
167
|
},
|
|
@@ -180,7 +185,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
180
185
|
}
|
|
181
186
|
|
|
182
187
|
if (name === 'tts') {
|
|
183
|
-
const { working_directory, text } = args;
|
|
188
|
+
const { working_directory, text, gender } = args;
|
|
184
189
|
if (!working_directory || !text) {
|
|
185
190
|
throw new Error('必须同时提供 working_directory 和 text 参数');
|
|
186
191
|
}
|
|
@@ -188,6 +193,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
188
193
|
const filename = await tts({
|
|
189
194
|
workingDir,
|
|
190
195
|
text,
|
|
196
|
+
gender,
|
|
191
197
|
apiKey: DASHSCOPE_API_KEY,
|
|
192
198
|
});
|
|
193
199
|
return { content: [{ type: 'text', text: `语音合成完成,音频文件已保存到工作目录下:${filename}` }] };
|
package/package.json
CHANGED
package/utils/tts.js
CHANGED
|
@@ -5,12 +5,18 @@ const { v4: uuidv4 } = require('uuid');
|
|
|
5
5
|
|
|
6
6
|
const TTS_WS_URL = 'wss://dashscope.aliyuncs.com/api-ws/v1/inference/';
|
|
7
7
|
|
|
8
|
+
// 音色配置
|
|
9
|
+
const VOICE_MAP = {
|
|
10
|
+
female: 'sambert-zhimiao-emo-v1',
|
|
11
|
+
male: 'sambert-zhihao-v1',
|
|
12
|
+
};
|
|
13
|
+
|
|
8
14
|
/**
|
|
9
15
|
* TTS 语音合成
|
|
10
16
|
*/
|
|
11
|
-
const tts = async ({ workingDir, text, apiKey }) => {
|
|
12
|
-
//
|
|
13
|
-
const voice =
|
|
17
|
+
const tts = async ({ workingDir, text, gender = 'female', apiKey }) => {
|
|
18
|
+
// 根据性别选择音色
|
|
19
|
+
const voice = VOICE_MAP[gender] || VOICE_MAP.female;
|
|
14
20
|
const format = 'mp3';
|
|
15
21
|
const sampleRate = 16000;
|
|
16
22
|
|