You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Node.js项目中调用GitHub上的Python项目whisperX?

在Node.js项目中调用whisperX的两种可行方案

不需要将whisperX打包成单个.py文件,以下是两种直接可用的实现方式:

方案1:通过child_process调用whisperX命令行工具(推荐)

whisperX本身支持命令行调用,只需先将其安装为系统/虚拟环境内的命令工具:

  1. 克隆whisperX仓库后,进入仓库根目录,执行:
    pip install -e .
    
    这会将whisperx命令注册到当前环境,后续直接通过命令调用即可。
  2. 在Node.js中使用child_process模块执行命令:
    const { execSync } = require('child_process');
    
    try {
      // 示例:处理音频文件并生成srt字幕
      const result = execSync('whisperx /path/to/target/audio.mp3 --output_format srt', { encoding: 'utf8' });
      console.log('处理结果:', result);
    } catch (err) {
      console.error('执行失败:', err.stderr);
    }
    
    命令参数可根据需求调整,参考whisperX的命令行参数说明即可。

方案2:通过python-shell直接调用项目脚本

若不想安装为命令行工具,可直接调用仓库内的核心脚本:
whisperX的入口逻辑在whisperx/cli.py文件中,直接调用该脚本即可:

const { PythonShell } = require('python-shell');

const options = {
  scriptPath: '/path/to/whisperX/repo/whisperx', // 指向仓库内的whisperx子目录
  args: ['/path/to/target/audio.mp3', '--output_format', 'vtt'] // 传入处理参数
};

PythonShell.run('cli.py', options, (err, results) => {
  if (err) throw err;
  console.log('脚本输出:', results);
});

也可通过python -m whisperx的方式调用,本质是触发whisperx/__main__.py的执行,效果与命令行一致。


内容的提问来源于stack exchange,提问作者I am L

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 19:32:46