Audify.js
Audify.js - Play/Stream/Record PCM audio data & Encode/Decode Opus to PCM audio data
Features
- Encode 16-bit integer PCM or floating point PCM to Opus packet using C++ Opus library.
- Decode Opus packets to 16-bit integer PCM or floating point PCM using C++ Opus library.
- Complete API for realtime audio input/output across Linux (native ALSA, JACK, PulseAudio and OSS), Macintosh OS X (CoreAudio and JACK), and Windows (DirectSound, ASIO and WASAPI) operating systems using C++ RtAudio library.
Installation
npm install audify
Most regular installs will support prebuilds that are built with each release.
Prebuilds are available for Node/Electron versions that support N-API 5-9.
Requirements for source build
- Node or Electron versions that support N-API 5 and up (N-API Node Version Matrix)
- CMake
- A proper C/C++ compiler toolchain of the given platform
- Windows:
- Unix/Posix:
- Clang or GCC
- Ninja or Make (Ninja will be picked if both present)
Example
Opus Encode & Decode
const { OpusEncoder, OpusDecoder, OpusApplication } = require("audify");
const encoder = new OpusEncoder(48000, 2, OpusApplication.OPUS_APPLICATION_AUDIO);
const decoder = new OpusDecoder(48000, 2);
const frameSize = 1920;
const buffer = ...
var encoded = encoder.encode(buffer, frameSize);
var decoded = decoder.decode(encoded, frameSize);
Record audio and play it back realtime
const { RtAudio, RtAudioFormat } = require("audify");
const rtAudio = new RtAudio();
rtAudio.openStream(
{
deviceId: rtAudio.getDefaultOutputDevice(),
nChannels: 1,
firstChannel: 0,
},
{
deviceId: rtAudio.getDefaultInputDevice(),
nChannels: 1,
firstChannel: 0,
},
RtAudioFormat.RTAUDIO_SINT16,
48000,
1920,
"MyStream",
(pcm) => rtAudio.write(pcm)
);
rtAudio.start();
Documentation
Full documentation available here.
Legal
This project is licensed under the MIT license.