Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Node.Js中播放wav文件?_Node.js_Audio_Wav - Fatal编程技术网

如何在Node.Js中播放wav文件?

如何在Node.Js中播放wav文件?,node.js,audio,wav,Node.js,Audio,Wav,我需要一些简单的东西:播放node.js文件中的音频文件。我试过各种各样的方法,但都找不到有效的方法。我目前正在尝试通过以下链接播放声音: 我确保安装了play sound,然后我的代码只有以下内容: var player = require('play-sound')(opts = {}) player.play('chime.wav', function(err){ if (err) throw err }); 我什么也得不到。我可以通过以下命令行播放声音: aplay chime.wav

我需要一些简单的东西:播放node.js文件中的音频文件。我试过各种各样的方法,但都找不到有效的方法。我目前正在尝试通过以下链接播放声音:

我确保安装了play sound,然后我的代码只有以下内容:

var player = require('play-sound')(opts = {})
player.play('chime.wav', function(err){
if (err) throw err
});
我什么也得不到。我可以通过以下命令行播放声音:

aplay chime.wav
任何想法都将不胜感激


更新:我找到了答案。“node aplay”为我工作:

我不需要USB音频配置部分。我只是按照说明安装了node aplay和alsa。我的代码只是示例中的前两行:

var Sound = require('node-aplay');

// fire and forget: 
new Sound('/path/to/the/file/filename.wav').play();
var Sound = require('node-aplay');

// fire and forget: 
new Sound('/path/to/the/file/filename.wav').play();

通过检查
stdout
stderr
可以看到发生了什么:

var player = require('play-sound')(opts = {})
var player.play('chime.wav', function(err, stdout, stderr) {
   if (err) throw err
   console.log(stdout)                                                                                               
   console.log(stderr)
});

更新:我找到了答案。“node aplay”为我工作:

我不需要USB音频配置部分。我只是按照说明安装了node aplay和alsa。我的代码只是示例中的前两行:

var Sound = require('node-aplay');

// fire and forget: 
new Sound('/path/to/the/file/filename.wav').play();
var Sound = require('node-aplay');

// fire and forget: 
new Sound('/path/to/the/file/filename.wav').play();

尝试
声音播放
,它同时支持
.wav
.mp3

const sound = require('sound-play')
sound.play('/path/music.wav')

node-wav播放器在Mac上使用的非常好。谢谢,唯一对我有用的东西!