UNPKG

@mindconnect/mindconnect-nodejs

Version:

MindConnect Library for NodeJS (community based)

98 lines 4.89 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const sdk_client_1 = require("../common/sdk-client"); const spectrum_analysis_models_1 = require("./spectrum-analysis-models"); const spectrum_analysis_template_1 = require("./spectrum-analysis-template"); /** * Signal Spectrum Analysis API * * * Fourier Transformation * * Provides Fourier Transform functionality for sound analysis. * * @export * @class SpectrumAnalysisClient * @extends {SdkClient} */ class SpectrumAnalysisClient extends sdk_client_1.SdkClient { constructor() { super(...arguments); this._baseUrl = "/api/spectrumanalysis/v3"; } /** * Decomposes the sound file into frequency components and returns the amplitude of each component. * By default a FLATTOP window is applied before the Fourier transformation to help improve processing results. * * @param {Buffer} file * The sound file that is transformed. * If the sound is stereo then an average operation is made to obtain one channel. * Supports up to 1MB input files and the file must be either 8 bits or 16 bits wav format. * @param {SpectrumAnalysisModels.WindowType.WindowTypeEnum} [windowType] * * The input properties for the Short Time Fourier transformation processing. windowType - * the type of window used for preprocessing input signal. * The allowed values for window type are: FLATTOP, HAMMING, HANNING and BLACKMAN. * The input format for the paramater is a JSON string like the example below * * @param {{ filename?: string; mimetype?: string }} [params] * @returns {Promise<SpectrumAnalysisModels.FFTOutput>} * * @memberOf SpectrumAnalysisClient */ CalculateFrequencies(file, windowType, params) { return __awaiter(this, void 0, void 0, function* () { const selectedWindowType = windowType || spectrum_analysis_models_1.SpectrumAnalysisModels.WindowType.WindowTypeEnum.FLATTOP; const parameters = params || {}; const { filename, mimetype } = parameters; const result = yield this.HttpAction({ verb: "POST", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/calculateFrequencies`, body: spectrum_analysis_template_1.spectralAnalysisTemplate(file, filename, selectedWindowType.toString(), mimetype), multiPartFormData: true }); return result; }); } /** * * Threshold Alert * * Performs amplitude breaching detection. * * Detects out of bounds frequency amplitudes inside a frequency range. * * Detects Fourier Transformation components which breach given thresholds. (Either lower, upper thresholds or both) * * @param {SpectrumAnalysisModels.ThresholdViolationInput} data * * Data structure with two parts - data and spectrumFilter. * * data - array of amplitudes of frequency components as returned by the Fourier Transformation. * * Conforms to data array from output of /calculateFrequencies. * * spectrumFilter - represents a frequency interval and thresholds that, when breached, will be signalled in the response. * * You can specify either lower or upper thresholds, or both but at least one of the thresholds must be specified. * @returns {Promise<SpectrumAnalysisModels.ThresholdViolationOutput>} * * @memberOf SpectrumAnalysisClient */ DetectThresholdViolations(data) { return __awaiter(this, void 0, void 0, function* () { const result = yield this.HttpAction({ verb: "POST", gateway: this.GetGateway(), authorization: yield this.GetToken(), baseUrl: `${this._baseUrl}/detectThresholdViolations`, body: data }); return result; }); } } exports.SpectrumAnalysisClient = SpectrumAnalysisClient; //# sourceMappingURL=spectrum-analysis.js.map