@ww_nero/media 1.2.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.2.0',
117
+ version: '1.3.0',
118
118
  },
119
119
  {
120
120
  capabilities: {
@@ -162,6 +162,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
162
162
  enum: ['female', 'male'],
163
163
  description: '语音性别,female 为女声,male 为男声,默认为 female',
164
164
  },
165
+ rate: {
166
+ type: 'number',
167
+ description: '语速,可调区间为 0.5-2,数字越大语速越快,默认为 1',
168
+ },
165
169
  },
166
170
  required: ['working_directory', 'text'],
167
171
  },
@@ -185,7 +189,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
185
189
  }
186
190
 
187
191
  if (name === 'tts') {
188
- const { working_directory, text, gender } = args;
192
+ const { working_directory, text, gender, rate } = args;
189
193
  if (!working_directory || !text) {
190
194
  throw new Error('必须同时提供 working_directory 和 text 参数');
191
195
  }
@@ -194,6 +198,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
194
198
  workingDir,
195
199
  text,
196
200
  gender,
201
+ rate,
197
202
  apiKey: DASHSCOPE_API_KEY,
198
203
  });
199
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.2.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
@@ -14,12 +14,15 @@ const VOICE_MAP = {
14
14
  /**
15
15
  * TTS 语音合成
16
16
  */
17
- const tts = async ({ workingDir, text, gender = 'female', apiKey }) => {
17
+ const tts = async ({ workingDir, text, gender = 'female', rate = 1, apiKey }) => {
18
18
  // 根据性别选择音色
19
19
  const voice = VOICE_MAP[gender] || VOICE_MAP.female;
20
20
  const format = 'mp3';
21
21
  const sampleRate = 16000;
22
22
 
23
+ // 验证语速参数
24
+ const validRate = Math.max(0.5, Math.min(2, Number(rate) || 1));
25
+
23
26
  // 验证 API Key
24
27
  if (!apiKey) {
25
28
  throw new Error('请配置 DASHSCOPE_API_KEY 环境变量');
@@ -81,7 +84,7 @@ const tts = async ({ workingDir, text, gender = 'female', apiKey }) => {
81
84
  format: format,
82
85
  sample_rate: sampleRate,
83
86
  volume: 50,
84
- rate: 1,
87
+ rate: validRate,
85
88
  pitch: 1,
86
89
  word_timestamp_enabled: false,
87
90
  phoneme_timestamp_enabled: false