@ww_nero/media 1.0.10 → 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/README.md +1 -4
- package/index.js +6 -15
- package/package.json +1 -1
- package/utils/tts.js +12 -1
package/README.md
CHANGED
|
@@ -27,12 +27,9 @@
|
|
|
27
27
|
**参数:**
|
|
28
28
|
- `working_directory`: 工作目录的绝对路径,合成的音频文件将保存到此目录
|
|
29
29
|
- `text`: 需要合成语音的文本内容
|
|
30
|
-
- `voice`: (可选)音色模型,默认 `sambert-zhimiao-emo-v1`
|
|
31
|
-
- `format`: (可选)输出音频格式,可选 mp3(默认)、wav、pcm
|
|
32
|
-
- `sample_rate`: (可选)采样率,默认 16000
|
|
33
30
|
|
|
34
31
|
**输出:**
|
|
35
|
-
- 合成结果保存到工作目录下的 `tts_<timestamp
|
|
32
|
+
- 合成结果保存到工作目录下的 `tts_<timestamp>.mp3` 文件
|
|
36
33
|
|
|
37
34
|
## 环境变量
|
|
38
35
|
|
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.0
|
|
117
|
+
version: '1.2.0',
|
|
118
118
|
},
|
|
119
119
|
{
|
|
120
120
|
capabilities: {
|
|
@@ -157,17 +157,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
157
157
|
type: 'string',
|
|
158
158
|
description: '需要合成语音的文本内容',
|
|
159
159
|
},
|
|
160
|
-
|
|
160
|
+
gender: {
|
|
161
161
|
type: 'string',
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
format: {
|
|
165
|
-
type: 'string',
|
|
166
|
-
description: '输出音频格式,可选 mp3(默认)、wav、pcm',
|
|
167
|
-
},
|
|
168
|
-
sample_rate: {
|
|
169
|
-
type: 'number',
|
|
170
|
-
description: '采样率,默认 16000',
|
|
162
|
+
enum: ['female', 'male'],
|
|
163
|
+
description: '语音性别,female 为女声,male 为男声,默认为 female',
|
|
171
164
|
},
|
|
172
165
|
},
|
|
173
166
|
required: ['working_directory', 'text'],
|
|
@@ -192,7 +185,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
192
185
|
}
|
|
193
186
|
|
|
194
187
|
if (name === 'tts') {
|
|
195
|
-
const { working_directory, text,
|
|
188
|
+
const { working_directory, text, gender } = args;
|
|
196
189
|
if (!working_directory || !text) {
|
|
197
190
|
throw new Error('必须同时提供 working_directory 和 text 参数');
|
|
198
191
|
}
|
|
@@ -200,10 +193,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
200
193
|
const filename = await tts({
|
|
201
194
|
workingDir,
|
|
202
195
|
text,
|
|
196
|
+
gender,
|
|
203
197
|
apiKey: DASHSCOPE_API_KEY,
|
|
204
|
-
voice: voice || 'sambert-zhimiao-emo-v1',
|
|
205
|
-
format: format || 'mp3',
|
|
206
|
-
sampleRate: sample_rate || 16000,
|
|
207
198
|
});
|
|
208
199
|
return { content: [{ type: 'text', text: `语音合成完成,音频文件已保存到工作目录下:${filename}` }] };
|
|
209
200
|
}
|
package/package.json
CHANGED
package/utils/tts.js
CHANGED
|
@@ -5,10 +5,21 @@ 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,
|
|
17
|
+
const tts = async ({ workingDir, text, gender = 'female', apiKey }) => {
|
|
18
|
+
// 根据性别选择音色
|
|
19
|
+
const voice = VOICE_MAP[gender] || VOICE_MAP.female;
|
|
20
|
+
const format = 'mp3';
|
|
21
|
+
const sampleRate = 16000;
|
|
22
|
+
|
|
12
23
|
// 验证 API Key
|
|
13
24
|
if (!apiKey) {
|
|
14
25
|
throw new Error('请配置 DASHSCOPE_API_KEY 环境变量');
|