@ww_nero/media 1.0.0 → 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/index.js +17 -22
- package/package.json +1 -1
- package/scripts/asr_srt.py +4 -10
package/index.js
CHANGED
|
@@ -11,7 +11,7 @@ const {
|
|
|
11
11
|
} = require('@modelcontextprotocol/sdk/types.js');
|
|
12
12
|
|
|
13
13
|
const ASR_API_KEY = process.env.ASR_API_KEY || '';
|
|
14
|
-
const ASR_UPLOAD_URL =
|
|
14
|
+
const ASR_UPLOAD_URL = 'http://fsheep.com:10808/upload';
|
|
15
15
|
|
|
16
16
|
const SUPPORTED_AUDIO_TYPES = ['.mp3', '.wav'];
|
|
17
17
|
const MAX_AUDIO_DURATION_SECONDS = 60;
|
|
@@ -217,29 +217,27 @@ const runAsrScript = (audioPath, outputPath, uploadUrl, apiKey) => {
|
|
|
217
217
|
const wslAudioPath = toWslPath(audioPath);
|
|
218
218
|
const wslOutputPath = toWslPath(outputPath);
|
|
219
219
|
|
|
220
|
+
// 构建 python 命令字符串
|
|
221
|
+
const pythonCommand = [
|
|
222
|
+
'python',
|
|
223
|
+
`"${wslScriptPath}"`,
|
|
224
|
+
'--audio', `"${wslAudioPath}"`,
|
|
225
|
+
'--output', `"${wslOutputPath}"`,
|
|
226
|
+
'--upload-url', `"${uploadUrl}"`,
|
|
227
|
+
'--api-key', `"${apiKey}"`
|
|
228
|
+
].join(' ');
|
|
229
|
+
|
|
220
230
|
const isWsl = isWslEnvironment();
|
|
221
231
|
|
|
232
|
+
// 参考 bash.js 的调用方式,通过 bash -ic 执行命令
|
|
222
233
|
let cmd, args;
|
|
223
234
|
if (isWsl || process.platform === 'linux') {
|
|
224
|
-
cmd = '
|
|
225
|
-
args = [
|
|
226
|
-
wslScriptPath,
|
|
227
|
-
'--audio', wslAudioPath,
|
|
228
|
-
'--output', wslOutputPath,
|
|
229
|
-
'--upload-url', uploadUrl,
|
|
230
|
-
'--api-key', apiKey
|
|
231
|
-
];
|
|
235
|
+
cmd = 'bash';
|
|
236
|
+
args = ['-ic', pythonCommand];
|
|
232
237
|
} else {
|
|
233
|
-
// Windows 环境,通过 wsl 调用
|
|
238
|
+
// Windows 环境,通过 wsl 调用 bash
|
|
234
239
|
cmd = 'wsl';
|
|
235
|
-
args = [
|
|
236
|
-
'-e', 'python3',
|
|
237
|
-
wslScriptPath,
|
|
238
|
-
'--audio', wslAudioPath,
|
|
239
|
-
'--output', wslOutputPath,
|
|
240
|
-
'--upload-url', uploadUrl,
|
|
241
|
-
'--api-key', apiKey
|
|
242
|
-
];
|
|
240
|
+
args = ['-e', 'bash', '-ic', pythonCommand];
|
|
243
241
|
}
|
|
244
242
|
|
|
245
243
|
const child = spawn(cmd, args, {
|
|
@@ -301,9 +299,6 @@ const asr = async ({ working_directory, audio_file }) => {
|
|
|
301
299
|
if (!ASR_API_KEY) {
|
|
302
300
|
throw new Error('请配置 ASR_API_KEY 环境变量');
|
|
303
301
|
}
|
|
304
|
-
if (!ASR_UPLOAD_URL) {
|
|
305
|
-
throw new Error('请配置 ASR_UPLOAD_URL 环境变量(完整的上传接口 URL,如 http://server.domain.com/upload)');
|
|
306
|
-
}
|
|
307
302
|
|
|
308
303
|
const workingDir = resolveWorkingDirectory(working_directory);
|
|
309
304
|
const audioPath = resolveAudioFile(workingDir, audio_file);
|
|
@@ -329,7 +324,7 @@ const asr = async ({ working_directory, audio_file }) => {
|
|
|
329
324
|
const server = new Server(
|
|
330
325
|
{
|
|
331
326
|
name: 'media',
|
|
332
|
-
version: '1.0.
|
|
327
|
+
version: '1.0.2',
|
|
333
328
|
},
|
|
334
329
|
{
|
|
335
330
|
capabilities: {
|
package/package.json
CHANGED
package/scripts/asr_srt.py
CHANGED
|
@@ -88,22 +88,16 @@ def upload_audio(upload_url: str, audio_path: str) -> str:
|
|
|
88
88
|
files = {'file': (audio_path.name, f)}
|
|
89
89
|
response = requests.post(upload_url, files=files, timeout=60)
|
|
90
90
|
|
|
91
|
-
if response.status_code == 409:
|
|
92
|
-
# 文件已存在,从响应中获取文件名或根据原文件名推断
|
|
93
|
-
data = response.json()
|
|
94
|
-
if 'fileName' in data:
|
|
95
|
-
return data['fileName']
|
|
96
|
-
# 如果没有返回文件名,使用原始文件名的扩展名
|
|
97
|
-
raise Exception(f"文件已存在: {data.get('message', '未知错误')}")
|
|
98
|
-
|
|
99
91
|
if response.status_code != 200:
|
|
100
92
|
raise Exception(f"上传失败: {response.status_code} - {response.text}")
|
|
101
93
|
|
|
102
94
|
data = response.json()
|
|
103
|
-
|
|
95
|
+
|
|
96
|
+
# 响应格式: {'success': True, 'data': {'path': '/tmp/xxx.wav'}}
|
|
97
|
+
if not data.get('success') or 'data' not in data or 'path' not in data['data']:
|
|
104
98
|
raise Exception(f"上传响应格式错误: {data}")
|
|
105
99
|
|
|
106
|
-
return data['
|
|
100
|
+
return Path(data['data']['path']).name
|
|
107
101
|
|
|
108
102
|
|
|
109
103
|
def get_static_url(upload_url: str, filename: str) -> str:
|