通过NodeJS以编程方式播放音频

时间:2019-03-23 03:06:48

标签: javascript node.js audio

我整天都在尝试从npm获取与播放音频有关的任何nodejs程序包,但无法正常工作。

基本上,我需要播放批处理音频。

例如:

//files containing the name of the audios
var files = require('./list-of-audios-to-play.json')

var player = require('play-sound')(opts = {})

 var counter = 0;

  //every 5 seconds, play the referenced audio

  setInterval(function(){
    counter++;
    player.play(files[counter]+'.mp3', function(err){
      if (err) throw err
    })
  },5000)

尝试了一切。

运行上面的代码时,出现此错误:

INFORMATION: wasnt possible to locate files for the specified pattern(s)
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: spawn play ENOENT
    at _errnoException (util.js:1022:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
    at onErrorNT (internal/child_process.js:372:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:695:11)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

有人可以帮忙吗?

0 个答案:

没有答案