Typescript: AudioWorkletProcessor type definition is missing

Created on 2 Nov 2018  路  9Comments  路  Source: microsoft/TypeScript


TypeScript Version: 3.2.0-dev.201xxxxx


Search Terms: AudioWorkletProcessor

You guys have type definitions for AudioWorkletNode and such but missed the definition for AudioWorkletProcessor as per: https://webaudio.github.io/web-audio-api/#audioworkletprocessor

This is what I have for now:

interface AudioWorkletProcessor {
    readonly port: MessagePort;
    process(inputs: Float32Array[][], outputs: Float32Array[][], parameters: Map<string, Float32Array>): void;
}

declare var AudioWorkletProcessor: {
    prototype: AudioWorkletProcessor;
    new(options?: AudioWorkletNodeOptions): AudioWorkletProcessor;
}

Cheers

Bug lib.d.ts help wanted

Most helpful comment

The definition of registerProcessor was missing as well.

I'm using the following definitions:

interface AudioWorkletProcessor {
  readonly port: MessagePort;
  process(
    inputs: Float32Array[][],
    outputs: Float32Array[][],
    parameters: Record<string, Float32Array>
  ): boolean;
}

declare var AudioWorkletProcessor: {
  prototype: AudioWorkletProcessor;
  new (options?: AudioWorkletNodeOptions): AudioWorkletProcessor;
};

declare function registerProcessor(
  name: string,
  processorCtor: (new (
    options?: AudioWorkletNodeOptions
  ) => AudioWorkletProcessor) & {
    parameterDescriptors?: AudioParamDescriptor[];
  }
);


EDIT: added the parameter descriptors to the registerProcessor() declaration.

All 9 comments

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

AudioWorkletProcessor is a type only for AudioWorklet. Do we want to add dom.audioworklet.d.ts for this, or do we have to add all worklet types into dom.worker.d.ts?

@DanielRosenwasser you have a preference here?

@teali It looks like the type of the parameters-parameter is not right. It should not be a Map. When typing it to a Map you need to use the get methode to get a value from the Map. In the specs they also are talking about a Map. But that has been clarified in the specs after I created a bug report for Chromium, because in Chromium the parameters-parameter is an Object.

Hongchan Choi (one of the authors of the spec) responded with the next comment:

The description says it is a "map", but it's actually an associative array, which is a JS object.

For a project I'm working on I added:

declare type AudioParamList = {
  [key: string]: Float32Array
}

This way typescript works great with the workletNode.

@navelpluisje parameters: Record<string, Float32Array> should also work.

Wasn't aware of that one. Not using typescript for that long. Thanx

Working on Web Audio API library I was surprised it's missing in TS. Most of other stuff, including other Audio Worklet related classes/interfaces are present.

Note that the return type of the process method should be boolean, not void.

The return value of this method controls the lifetime of the AudioWorkletProcessor's associated AudioWorkletNode.

See the docs for more details.

The definition of registerProcessor was missing as well.

I'm using the following definitions:

interface AudioWorkletProcessor {
  readonly port: MessagePort;
  process(
    inputs: Float32Array[][],
    outputs: Float32Array[][],
    parameters: Record<string, Float32Array>
  ): boolean;
}

declare var AudioWorkletProcessor: {
  prototype: AudioWorkletProcessor;
  new (options?: AudioWorkletNodeOptions): AudioWorkletProcessor;
};

declare function registerProcessor(
  name: string,
  processorCtor: (new (
    options?: AudioWorkletNodeOptions
  ) => AudioWorkletProcessor) & {
    parameterDescriptors?: AudioParamDescriptor[];
  }
);


EDIT: added the parameter descriptors to the registerProcessor() declaration.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fdecampredon picture fdecampredon  路  358Comments

Taytay picture Taytay  路  174Comments

rbuckton picture rbuckton  路  139Comments

blakeembrey picture blakeembrey  路  171Comments

yortus picture yortus  路  157Comments