sound-play

Dead simple sound player for Node – because it should be simple.

const sound = require("sound-play");
sound.play("file.mp3");
  • Support .wav, .mp3 and other extensions.

  • Work on Windows and MacOS

安装

npm install sound-play
yarn add sound-play

例子

相对路径

sound.play("file.mp3");

or

const path = require("path");
const filePath = path.join(__dirname, "file.mp3");
sound.play(filePath);

音量 Volume

/**
 * 0   = silent
 * 0.5 = default (默认音量)
 * 1   = max volume
 */
volume = 0.1;
sound.play("file.mp3", volume);

绝对路径

sound.play("C:\\file.mp3");

Promise

sound.play("file.mp3").then((response) => console.log("done"));

Async/await

try {
  await sound.play("file.mp3");
  console.log("done");
} catch (error) {
  console.error(error);
}
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐