Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

JS bindings for libopus 1.4, ported with Emscripten

License

NotificationsYou must be signed in to change notification settings

abalabahaha/opusscript

Repository files navigation

JS bindings for libopus 1.4, ported with Emscripten.


Usage

varOpusScript=require("opusscript");// 48kHz sampling rate, 20ms frame duration, stereo audio (2 channels)varsamplingRate=48000;varframeDuration=20;varchannels=2;// Optimize encoding for audio. Available applications are VOIP, AUDIO, and RESTRICTED_LOWDELAYvarencoder=newOpusScript(samplingRate,channels,OpusScript.Application.AUDIO);varframeSize=samplingRate*frameDuration/1000;// Get PCM data from somewhere and encode it into opusvarpcmData=newBuffer(pcmSource);varencodedPacket=encoder.encode(pcmData,frameSize);// Decode the opus packet back into PCMvardecodedPacket=encoder.decode(encodedPacket);// Delete the encoder when finished with it (Emscripten does not automatically call C++ object destructors)encoder.delete();

Note: WASM

If your environment doesn't support WASM, you can try the JS-only module. Do note that the JS-only version barely has optimizations due to compiler/toolchain limitations, and should only be used as a last resort.

varencoder=newOpusScript(samplingRate,channels,OpusScript.Application.AUDIO,{wasm:false});

Note: TypeScript

Since this module wasn't written for TypeScript, you need to useimport = require syntax.

// Import using:importOpusScript= require("opusscript");// and NOT:importOpusScriptfrom"opusscript";

[8]ページ先頭

©2009-2025 Movatter.jp