Package Exports
- libopusenc
- libopusenc/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (libopusenc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-opusenc
Description
Entirely synchronous API to create .ogg files encoded using libopus library. It supports several sample rates (16000,48000 and more.).
Usage
import { Comments, Encoder } from "node-opusenc";
const comments = new Comments();
const enc = new Encoder();
enc.createFile(comments, path.resolve(__dirname, "test1.ogg"), 48000, 1, 0);
const pcm = child_process.spawn("arecord", [
"-f",
"FLOAT_LE",
"-c",
"1",
"-r",
"48000",
"-d",
"4",
]);
pcm.stdout.on("data", (chunk) => {
assert.strict.ok(Buffer.isBuffer(chunk));
const samples = chunk.byteLength / Float32Array.BYTES_PER_ELEMENT;
const buf = new Float32Array(samples);
buf.set(new Float32Array(chunk.buffer, chunk.byteOffset, samples));
enc.writeFloat(buf, samples);
});
return new Promise<void>((resolve) => {
pcm.stdout.on("exit", (code) => {
assert.strict.ok(code === 0);
enc.drain();
resolve();
});
});