UNPKG

microsoft-speech-browser-sdk

Version:
46 lines (42 loc) 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var OpusRecorder = /** @class */ (function () { function OpusRecorder(options) { var _this = this; this.Record = function (context, mediaStream, outputStream) { var mediaRecorder = new MediaRecorder(mediaStream, _this.mediaRecorderOptions); var timeslice = 100; // this is in ms - 100 ensures that the chunk doesn't exceed the max size of chunk allowed in WS connection mediaRecorder.ondataavailable = function (dataAvailableEvent) { if (outputStream) { var reader_1 = new FileReader(); reader_1.readAsArrayBuffer(dataAvailableEvent.data); reader_1.onloadend = function (event) { outputStream.Write(reader_1.result); }; } }; _this.mediaResources = { recorder: mediaRecorder, stream: mediaStream, }; mediaRecorder.start(timeslice); }; this.ReleaseMediaResources = function (context) { if (_this.mediaResources.recorder.state !== "inactive") { _this.mediaResources.recorder.stop(); } _this.mediaResources.stream.getTracks().forEach(function (track) { return track.stop(); }); }; this.mediaRecorderOptions = options; } return OpusRecorder; }()); exports.OpusRecorder = OpusRecorder; /* Declaring this inline to avoid compiler warnings declare class MediaRecorder { constructor(mediaStream: MediaStream, options: any); public state: string; public ondataavailable(dataAvailableEvent: any): void; public stop(): void; }*/ //# sourceMappingURL=OpusRecorder.js.map