【问题标题】:Turning sox command line Duration into a node.js variable.将 sox 命令行 Duration 转换为 node.js 变量。
【发布时间】:2018-01-26 11:14:40
【问题描述】:

我想找到 audio.wav 的持续时间,并将持续时间用作 node.js 脚本中的变量。

我可以使用 sox 在命令行上获取 wav 的持续时间:

$ soxi -D audio.wav

返回:

7.870975

如何在 node.js 文件中运行 soxi -D?

【问题讨论】:

    标签: node.js sox


    【解决方案1】:

    好的,我想我使用 child_process 解决了这个问题:

    var exec = require("child_process").exec;//require child_process.exec
    
    exec("soxi -D /path/to/audio.wav", function(err, stdout){
        if (err){
             throw err;
    }
    var audioDuration = stdout * 1000; //takes audio length in seconds and converts to milliseconds
    console.log("This is the Audio Duration:" + audioDuration);//Prints
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多