@euirim/microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
76 lines (74 loc) • 2.75 kB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
/**
* Represents audio stream format used for custom audio input configurations.
* @class AudioStreamFormat
*/
export class AudioStreamFormat {
/**
* Creates an audio stream format object representing the default audio stream
* format (16KHz 16bit mono PCM).
* @member AudioStreamFormat.getDefaultInputFormat
* @function
* @public
* @returns {AudioStreamFormat} The audio stream format being created.
*/
static getDefaultInputFormat() {
return AudioStreamFormatImpl.getDefaultInputFormat();
}
/**
* Creates an audio stream format object with the specified pcm waveformat characteristics.
* @member AudioStreamFormat.getWaveFormatPCM
* @function
* @public
* @param {number} samplesPerSecond - Sample rate, in samples per second (Hertz).
* @param {number} bitsPerSample - Bits per sample, typically 16.
* @param {number} channels - Number of channels in the waveform-audio data. Monaural data
* uses one channel and stereo data uses two channels.
* @returns {AudioStreamFormat} The audio stream format being created.
*/
static getWaveFormatPCM(samplesPerSecond, bitsPerSample, channels) {
return new AudioStreamFormatImpl(samplesPerSecond, bitsPerSample, channels);
}
}
/**
* @private
* @class AudioStreamFormatImpl
*/
// tslint:disable-next-line:max-classes-per-file
export class AudioStreamFormatImpl extends AudioStreamFormat {
/**
* Creates an instance with the given values.
* @constructor
* @param {number} samplesPerSec - Samples per second.
* @param {number} bitsPerSample - Bits per sample.
* @param {number} channels - Number of channels.
*/
constructor(samplesPerSec = 16000, bitsPerSample = 16, channels = 1) {
super();
this.formatTag = 1;
this.bitsPerSample = bitsPerSample;
this.samplesPerSec = samplesPerSec;
this.channels = channels;
this.avgBytesPerSec = this.samplesPerSec * this.channels * (this.bitsPerSample / 8);
this.blockAlign = this.channels * Math.max(this.bitsPerSample, 8);
}
/**
* Retrieves the default input format.
* @member AudioStreamFormatImpl.getDefaultInputFormat
* @function
* @public
* @returns {AudioStreamFormatImpl} The default input format.
*/
static getDefaultInputFormat() {
return new AudioStreamFormatImpl();
}
/**
* Closes the configuration object.
* @member AudioStreamFormatImpl.prototype.close
* @function
* @public
*/
close() { return; }
}
//# sourceMappingURL=AudioStreamFormat.js.map