Play audio with Node.JS

前端 未结 7 2095
故里飘歌
故里飘歌 2021-02-01 15:52

I\'m currently using child_process and command-line mplayer to play audio on the local machine, with my Node.JS application. This works, but it\'s not really an exc

相关标签:
7条回答
  • 2021-02-01 16:29

    I think what you asking is there any good modules that work with audio in the nodejs ecosystem?

    Whenever you have this type of question you should first go the npmjs and just type a appropiate keyword.

    Here is list of modules that related to audio I found on the npmjs site.

    substacks's baudio looks good to me.

    0 讨论(0)
  • 2021-02-01 16:33

    Check out node-groove - Node.js binding to libgroove:

    This library provides decoding and encoding of audio on a playlist. It is intended to be used as a backend for music player applications, however it is generic enough to be used as a backend for any audio processing utility.

    Disclaimer: I wrote the library, which is free, open source, and not affiliated with any product, service, or company.

    0 讨论(0)
  • 2021-02-01 16:39

    Check out sound-play, it's a simple solution that works on Windows and MacOS without using external players:

    const sound = require('sound-play')
    sound.play('music.mp3')
    

    Disclaimer: I'm the author of this package.

    0 讨论(0)
  • 2021-02-01 16:41

    I would suggest using node-speaker, which outputs raw PCM data to your speakers (so basically, it plays audio).

    If you're playing something like mp3 files you might need to decode it first to PCM data, which is exactly what node-lame does.

    Hope that helps.

    0 讨论(0)
  • 2021-02-01 16:41

    Introducing, audic. It doesn't use any native dependencies and it's isomorphic so it can't break like in the answers higher up.

    Observe:

    const Audic = require("audic")
    
    const audio = new Audic("audio.mp3")
    
    // Play Audio
    audio.play()
    
    // Pause Audio
    audio.pause()
    
    0 讨论(0)
  • 2021-02-01 16:48

    You can use play-sound module also:

    Install using npm, Run command:

    npm install play-sound --save
    

    Now use in your code:

    var player = require('play-sound')(opts = {})
    
     player.play('./music/somebody20.flac', function (err) {
       if (err) throw err;
       console.log("Audio finished");
     });
    
    0 讨论(0)
提交回复
热议问题