buddy

node MVC discord bot
Log | Files | Refs | README

WebmDemuxer.js (718B)


      1 const WebmBaseDemuxer = require('../core/WebmBase');
      2 
      3 const OPUS_HEAD = Buffer.from([...'OpusHead'].map(x => x.charCodeAt(0)));
      4 
      5 /**
      6  * Demuxes a Webm stream (containing Opus audio) to output an Opus stream.
      7  * @extends core.WebmBaseDemuxer
      8  * @memberof opus
      9  * @example
     10  * const fs = require('fs');
     11  * const file = fs.createReadStream('./audio.webm');
     12  * const demuxer = new prism.opus.WebmDemuxer();
     13  * const opus = file.pipe(demuxer);
     14  * // opus is now a ReadableStream in object mode outputting Opus packets
     15  */
     16 class WebmDemuxer extends WebmBaseDemuxer {
     17   _checkHead(data) {
     18     if (!data.slice(0, 8).equals(OPUS_HEAD)) {
     19       throw Error('Audio codec is not Opus!');
     20     }
     21   }
     22 }
     23 
     24 module.exports = WebmDemuxer;