UNPKG

@euirim/microsoft-cognitiveservices-speech-sdk

Version:
176 lines (174 loc) 6.47 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var Guid_1 = require("../../../src/common/Guid"); var Exports_1 = require("../../common/Exports"); var AudioStreamFormat_1 = require("./AudioStreamFormat"); exports.bufferSize = 4096; /** * Represents audio input stream used for custom audio input configurations. * @class AudioInputStream */ var AudioOutputStream = /** @class */ (function () { /** * Creates and initializes an instance. * @constructor */ function AudioOutputStream() { } /** * Creates a memory backed PullAudioOutputStream with the specified audio format. * @member AudioInputStream.createPullStream * @function * @public * @param {AudioStreamFormat} format - The audio data format in which audio will be * written to the push audio stream's write() method (currently only support 16 kHz 16bit mono PCM). * @returns {PullAudioOutputStream} The audio input stream being created. */ AudioOutputStream.createPullStream = function (format) { return PullAudioOutputStream.create(format); }; return AudioOutputStream; }()); exports.AudioOutputStream = AudioOutputStream; /** * Represents memory backed push audio input stream used for custom audio input configurations. * @class PullAudioOutputStream */ // tslint:disable-next-line:max-classes-per-file var PullAudioOutputStream = /** @class */ (function (_super) { __extends(PullAudioOutputStream, _super); function PullAudioOutputStream() { return _super !== null && _super.apply(this, arguments) || this; } /** * Creates a memory backed PullAudioOutputStream with the specified audio format. * @member PullAudioOutputStream.create * @function * @public * @param {AudioStreamFormat} format - The audio data format in which audio will be written to the * push audio stream's write() method (currently only support 16 kHz 16bit mono PCM). * @returns {PullAudioOutputStream} The push audio input stream being created. */ PullAudioOutputStream.create = function (format) { return new PullAudioOutputStreamImpl(exports.bufferSize, format); }; return PullAudioOutputStream; }(AudioOutputStream)); exports.PullAudioOutputStream = PullAudioOutputStream; /** * Represents memory backed push audio input stream used for custom audio input configurations. * @private * @class PullAudioOutputStreamImpl */ // tslint:disable-next-line:max-classes-per-file var PullAudioOutputStreamImpl = /** @class */ (function (_super) { __extends(PullAudioOutputStreamImpl, _super); /** * Creates and initalizes an instance with the given values. * @constructor * @param {AudioStreamFormat} format - The audio stream format. */ function PullAudioOutputStreamImpl(chunkSize, format) { var _this = _super.call(this) || this; if (format === undefined) { _this.privFormat = AudioStreamFormat_1.AudioStreamFormatImpl.getDefaultInputFormat(); } else { _this.privFormat = format; } _this.privId = Guid_1.createNoDashGuid(); _this.privStream = new Exports_1.ChunkedArrayBufferStream(chunkSize); _this.streamReader = _this.privStream.getReader(); return _this; } Object.defineProperty(PullAudioOutputStreamImpl.prototype, "format", { /** * Format information for the audio */ get: function () { return this.privFormat; }, enumerable: true, configurable: true }); Object.defineProperty(PullAudioOutputStreamImpl.prototype, "isClosed", { /** * Checks if the stream is closed * @member PullAudioOutputStreamImpl.prototype.isClosed * @property * @public */ get: function () { return this.privStream.isClosed; }, enumerable: true, configurable: true }); Object.defineProperty(PullAudioOutputStreamImpl.prototype, "id", { /** * Gets the id of the stream * @member PullAudioOutputStreamImpl.prototype.id * @property * @public */ get: function () { return this.privId; }, enumerable: true, configurable: true }); /** * Reads data from the buffer * @member PullAudioOutputStreamImpl.prototype.read * @function * @public * @param {ArrayBuffer} dataBuffer - The audio buffer of which this function will make a copy. */ PullAudioOutputStreamImpl.prototype.read = function () { return this.streamReader.read() .onSuccessContinueWithPromise(function (chunk) { return Exports_1.PromiseHelper.fromResult(chunk.buffer); }); }; /** * Writes the audio data specified by making an internal copy of the data. * @member PullAudioOutputStreamImpl.prototype.write * @function * @public * @param {ArrayBuffer} dataBuffer - The audio buffer of which this function will make a copy. */ PullAudioOutputStreamImpl.prototype.write = function (dataBuffer) { this.privStream.writeStreamChunk({ buffer: dataBuffer, isEnd: false, timeReceived: Date.now() }); }; /** * Closes the stream. * @member PullAudioOutputStreamImpl.prototype.close * @function * @public */ PullAudioOutputStreamImpl.prototype.close = function () { this.privStream.close(); }; return PullAudioOutputStreamImpl; }(PullAudioOutputStream)); exports.PullAudioOutputStreamImpl = PullAudioOutputStreamImpl; //# sourceMappingURL=AudioOutputStream.js.map