From d6ea0fb641ae388dc6a60a00fb3b4ecb5f3dc285 Mon Sep 17 00:00:00 2001 From: Hugh Rawlinson Date: Wed, 8 Jan 2020 14:15:53 -0500 Subject: [PATCH] Add types for meyda (#41411) --- types/meyda/index.d.ts | 108 +++++++++++++++++++++++++++++++++++++ types/meyda/meyda-tests.ts | 20 +++++++ types/meyda/tsconfig.json | 24 +++++++++ types/meyda/tslint.json | 1 + 4 files changed, 153 insertions(+) create mode 100644 types/meyda/index.d.ts create mode 100644 types/meyda/meyda-tests.ts create mode 100644 types/meyda/tsconfig.json create mode 100644 types/meyda/tslint.json diff --git a/types/meyda/index.d.ts b/types/meyda/index.d.ts new file mode 100644 index 0000000000..8f7faaad27 --- /dev/null +++ b/types/meyda/index.d.ts @@ -0,0 +1,108 @@ +// Type definitions for meyda 4.3 +// Project: https://github.com/meyda/meyda +// Definitions by: Damien Erambert +// Hugh Rawlinson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace Meyda; + +export type MeydaWindowingFunction = 'blackman' | 'sine' | 'hanning' | 'hamming'; + +export type MeydaAudioFeature = + | 'amplitudeSpectrum' + | 'chroma' + | 'complexSpectrum' + | 'energy' + | 'loudness' + | 'mfcc' + | 'perceptualSharpness' + | 'perceptualSpread' + | 'powerSpectrum' + | 'rms' + | 'spectralCentroid' + | 'spectralFlatness' + | 'spectralFlux' + | 'spectralKurtosis' + | 'spectralRolloff' + | 'spectralSkewness' + | 'spectralSlope' + | 'spectralSpread' + | 'zcr' + | 'buffer'; + +export interface MeydaAnalyzerOptions { + audioContext: AudioContext; + source: AudioNode; + bufferSize: number; + hopSize?: number; + windowingFunction?: MeydaWindowingFunction; + featureExtractors?: MeydaAudioFeature | MeydaAudioFeature[]; + numberOfMFCCCoefficients?: number; + callback?: (features: Partial) => void; +} + +export type MeydaSignal = SliceableArrayLike; + +export interface SliceableArrayLike extends ArrayLike { + slice(start: number, end: number): SliceableArrayLike; +} + +export interface MeydaFeaturesObject { + amplitudeSpectrum: Float32Array; + buffer: number[]; + chroma: number[]; + complexSpectrum: { + real: number[]; + imag: number[]; + }; + energy: number; + loudness: { + specific: Float32Array; + total: number; + }; + mfcc: number[]; + perceptualSharpness: number; + perceptualSpread: number; + powerSpectrum: Float32Array; + rms: number; + spectralCentroid: number; + spectralFlatness: number; + spectralKurtosis: number; + spectralRolloff: number; + spectralSkewness: number; + spectralSlope: number; + spectralSpread: number; + zcr: number; +} + +export class MeydaAnalyzer { + start(features: MeydaAudioFeature[]): void; + + stop(): void; + + setSource(source: AudioNode): void; + + get(features: MeydaAudioFeature[]): Partial | null; +} + +export const audioContext: AudioContext | null; +export const spn: ScriptProcessorNode | null; +export const bufferSize: number; +export const sampleRate: number; +export const melBands: number; +export const chromaBands: number; +export const callback: ((features: Partial) => void | null); +export const windowingFunction: MeydaWindowingFunction; +export const featureExtractors: any; +export const EXTRACTION_STARTED: boolean; +export const numberOfMFCCCoefficients: number; + +export function windowing(signal: MeydaSignal, windowname?: MeydaWindowingFunction): MeydaSignal; + +export function createMeydaAnalyzer(options: MeydaAnalyzerOptions): MeydaAnalyzer; + +export function extract( + feature: MeydaAudioFeature | MeydaAudioFeature[], + signal: MeydaSignal, + previousSignal?: MeydaSignal, +): Partial | null; diff --git a/types/meyda/meyda-tests.ts b/types/meyda/meyda-tests.ts new file mode 100644 index 0000000000..8959568d25 --- /dev/null +++ b/types/meyda/meyda-tests.ts @@ -0,0 +1,20 @@ +// import Meyda from 'meyda'; + +function dummyNumbers(a: number): void {} + +const AC = new AudioContext(); + +const result = Meyda.extract('rms', []); +if (result) { + if (result.zcr) { + dummyNumbers(result.zcr); + } +} + +Meyda.createMeydaAnalyzer({ + audioContext: AC, + source: AC.createOscillator(), + bufferSize: 2048, +}); + +Meyda.windowing([], Meyda.windowingFunction); diff --git a/types/meyda/tsconfig.json b/types/meyda/tsconfig.json new file mode 100644 index 0000000000..a9fef6cfd8 --- /dev/null +++ b/types/meyda/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "DOM", + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "meyda-tests.ts" + ] +} diff --git a/types/meyda/tslint.json b/types/meyda/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/meyda/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }