@ww_nero/media 1.1.0 → 1.3.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 CHANGED
@@ -114,7 +114,7 @@ const resolveAudioFile = (workingDir, rawPath) => {
114
114
  const server = new Server(
115
115
  {
116
116
  name: 'media',
117
- version: '1.1.0',
117
+ version: '1.3.0',
118
118
  },
119
119
  {
120
120
  capabilities: {
@@ -157,6 +157,15 @@ 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
+ },
165
+ rate: {
166
+ type: 'number',
167
+ description: '语速,可调区间为 0.5-2,数字越大语速越快,默认为 1',
168
+ },
160
169
  },
161
170
  required: ['working_directory', 'text'],
162
171
  },
@@ -180,7 +189,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
180
189
  }
181
190
 
182
191
  if (name === 'tts') {
183
- const { working_directory, text } = args;
192
+ const { working_directory, text, gender, rate } = args;
184
193
  if (!working_directory || !text) {
185
194
  throw new Error('必须同时提供 working_directory 和 text 参数');
186
195
  }
@@ -188,6 +197,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
188
197
  const filename = await tts({
189
198
  workingDir,
190
199
  text,
200
+ gender,
201
+ rate,
191
202
  apiKey: DASHSCOPE_API_KEY,
192
203
  });
193
204
  return { content: [{ type: 'text', text: `语音合成完成,音频文件已保存到工作目录下:${filename}` }] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ww_nero/media",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "MCP server for media processing, including ASR speech recognition and TTS speech synthesis",
5
5
  "main": "index.js",
6
6
  "bin": {
package/utils/asr.js CHANGED
@@ -1,7 +1,8 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
- const ASR_UPLOAD_URL = 'http://fsheep.com:10808/upload';
4
+ const FILE_BASE_URL = 'http://fsheep.com:10801';
5
+ const ASR_UPLOAD_URL = `${FILE_BASE_URL}/file/upload`;
5
6
  const ASR_SERVICE_URL = 'https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription';
6
7
 
7
8
  const SUPPORTED_AUDIO_TYPES = ['.mp3', '.wav'];
@@ -73,7 +74,7 @@ const uploadAudio = async (uploadUrl, audioPath) => {
73
74
 
74
75
  const data = await response.json();
75
76
 
76
- if (!data.success || !data.data || !data.data.path) {
77
+ if (data.code !== 0 || !data.data || !data.data.path) {
77
78
  throw new Error(`上传响应格式错误: ${JSON.stringify(data)}`);
78
79
  }
79
80
 
@@ -81,11 +82,10 @@ const uploadAudio = async (uploadUrl, audioPath) => {
81
82
  };
82
83
 
83
84
  /**
84
- * 根据上传接口 URL 和文件路径构建静态资源 URL
85
+ * 根据 base URL 和文件路径构建静态资源 URL
85
86
  */
86
- const getStaticUrl = (uploadUrl, filePath) => {
87
- const url = new URL(uploadUrl);
88
- return `${url.protocol}//${url.host}${filePath}`;
87
+ const getStaticUrl = (baseUrl, filePath) => {
88
+ return `${baseUrl}${filePath}`;
89
89
  };
90
90
 
91
91
  /**
@@ -202,7 +202,7 @@ const asr = async ({ workingDir, audioPath, apiKey }) => {
202
202
  const filePath = await uploadAudio(ASR_UPLOAD_URL, audioPath);
203
203
 
204
204
  // 2. 构建静态资源 URL
205
- const audioUrl = getStaticUrl(ASR_UPLOAD_URL, filePath);
205
+ const audioUrl = getStaticUrl(FILE_BASE_URL, filePath);
206
206
 
207
207
  // 3. 提交 ASR 任务
208
208
  const taskId = await submitAsrTask([audioUrl], apiKey);
package/utils/tts.js CHANGED
@@ -5,15 +5,24 @@ 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 = 'sambert-zhimiao-emo-v1';
17
+ const tts = async ({ workingDir, text, gender = 'female', rate = 1, apiKey }) => {
18
+ // 根据性别选择音色
19
+ const voice = VOICE_MAP[gender] || VOICE_MAP.female;
14
20
  const format = 'mp3';
15
21
  const sampleRate = 16000;
16
22
 
23
+ // 验证语速参数
24
+ const validRate = Math.max(0.5, Math.min(2, Number(rate) || 1));
25
+
17
26
  // 验证 API Key
18
27
  if (!apiKey) {
19
28
  throw new Error('请配置 DASHSCOPE_API_KEY 环境变量');
@@ -75,7 +84,7 @@ const tts = async ({ workingDir, text, apiKey }) => {
75
84
  format: format,
76
85
  sample_rate: sampleRate,
77
86
  volume: 50,
78
- rate: 1,
87
+ rate: validRate,
79
88
  pitch: 1,
80
89
  word_timestamp_enabled: false,
81
90
  phoneme_timestamp_enabled: false