mwg API
    Preparing search index...

    Function oggOpus

    • Wraps Opus packets (stereo, 20 ms each) in an Ogg stream: an OpusHead page, an OpusTags page, then audio pages whose granule positions count 48 kHz samples from the start including the pre-skip, the last one cut to totalSamples so a decoder returns exactly the length that went in.

      Parameters

      • packets: readonly Uint8Array<ArrayBufferLike>[]
      • options: OggOpusOptions

      Returns Uint8Array

      import { oggOpus } from '@datamoc/mwg/audio';

      const silence = Uint8Array.of(0xf8, 0xff, 0xfe); //a 20 ms Opus frame of silence
      const file = oggOpus([silence, silence], { inputRate: 44100, totalSamples: 1920 });
      console.log(new TextDecoder().decode(file.subarray(0, 4))); // 'OggS'