@vdegenne/play-sound
v1.0.4
Published
Play audio files by shelling out to available audio tool.
Readme
@vdegenne/play-sound
Fork of play-sound with the following modern improvements:
- ESM compliant (see usage).
- Types are directly included in the package.
- Added
ffplayplayer. - Promisified (see usage).
- Removed unnecessary dependencies.
- Code cleaned.
Installation
npm i @vdegenne/play-soundExamples
Basic
import {Player} from '@vdegenne/play-sound';
const player = new Player();
player.play('./assets/test.mp3');Promise
import {Player} from '@vdegenne/play-sound';
const player = new Player();
const {promise} = player.play('./assets/test.mp3');
promise.then(() => console.log('audio ended'));How to stop audio (Promise advanced)
import {Player} from '@vdegenne/play-sound';
const player = new Player();
const {promise, process} = player.play('./assets/test.mp3');
setTimeout(() => {
// send signal after 1s
process.kill('SIGTERM');
}, 1000);
try {
await promise;
// Audio was not stopped, continue...
} catch {
// Audio was stopped prematurely
// which is what will happen in this example
}Choose base command + options
import {Player} from '@vdegenne/play-sound';
const player = new Player({player: 'ffplay'});
player.play('./assets/test.mp3', {
ffplay: ['-nodisp', '-autoexit'],
});Options
players– List of available audio players to check. Default:player– Audio player to use (skips availability checks)
License
MIT
