@mediapipe/tasks-audio 0.1.0-alpha-1668420867
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audio.d.ts +690 -0
- package/audio_bundle.js +13633 -0
- package/package.json +20 -0
- package/wasm/audio_wasm_internal.js +6501 -0
- package/wasm/audio_wasm_internal.wasm +0 -0
package/audio.d.ts
ADDED
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
/// <reference types="@types/offscreencanvas" />
|
|
2
|
+
|
|
3
|
+
import { ClassifierOptions as AudioClassifierOptions } from '../../../../tasks/web/core/classifier_options';
|
|
4
|
+
import { ClassificationResult as AudioClassifierResult } from '../../../../tasks/web/components/containers/classification_result';
|
|
5
|
+
import { Category } from '../../../../tasks/web/components/containers/category';
|
|
6
|
+
import { Classifications } from '../../../../tasks/web/components/containers/classification_result';
|
|
7
|
+
import { WasmLoaderOptions } from '../../../../tasks/web/core/wasm_loader_options';
|
|
8
|
+
|
|
9
|
+
/** Performs audio classification. */
|
|
10
|
+
export declare class AudioClassifier extends TaskRunner {
|
|
11
|
+
private classificationResults;
|
|
12
|
+
private defaultSampleRate;
|
|
13
|
+
private readonly options;
|
|
14
|
+
/**
|
|
15
|
+
* Initializes the Wasm runtime and creates a new audio classifier from the
|
|
16
|
+
* provided options.
|
|
17
|
+
* @param wasmLoaderOptions A configuration object that provides the location
|
|
18
|
+
* of the Wasm binary and its loader.
|
|
19
|
+
* @param audioClassifierOptions The options for the audio classifier. Note
|
|
20
|
+
* that either a path to the model asset or a model buffer needs to be
|
|
21
|
+
* provided (via `baseOptions`).
|
|
22
|
+
*/
|
|
23
|
+
static createFromOptions(wasmLoaderOptions: WasmLoaderOptions, audioClassifierOptions: AudioClassifierOptions): Promise<AudioClassifier>;
|
|
24
|
+
/**
|
|
25
|
+
* Initializes the Wasm runtime and creates a new audio classifier based on
|
|
26
|
+
* the provided model asset buffer.
|
|
27
|
+
* @param wasmLoaderOptions A configuration object that provides the location
|
|
28
|
+
* of the Wasm binary and its loader.
|
|
29
|
+
* @param modelAssetBuffer A binary representation of the model.
|
|
30
|
+
*/
|
|
31
|
+
static createFromModelBuffer(wasmLoaderOptions: WasmLoaderOptions, modelAssetBuffer: Uint8Array): Promise<AudioClassifier>;
|
|
32
|
+
/**
|
|
33
|
+
* Initializes the Wasm runtime and creates a new audio classifier based on
|
|
34
|
+
* the path to the model asset.
|
|
35
|
+
* @param wasmLoaderOptions A configuration object that provides the location
|
|
36
|
+
* of the Wasm binary and its loader.
|
|
37
|
+
* @param modelAssetPath The path to the model asset.
|
|
38
|
+
*/
|
|
39
|
+
static createFromModelPath(wasmLoaderOptions: WasmLoaderOptions, modelAssetPath: string): Promise<AudioClassifier>;
|
|
40
|
+
/**
|
|
41
|
+
* Sets new options for the audio classifier.
|
|
42
|
+
*
|
|
43
|
+
* Calling `setOptions()` with a subset of options only affects those options.
|
|
44
|
+
* You can reset an option back to its default value by explicitly setting it
|
|
45
|
+
* to `undefined`.
|
|
46
|
+
*
|
|
47
|
+
* @param options The options for the audio classifier.
|
|
48
|
+
*/
|
|
49
|
+
setOptions(options: AudioClassifierOptions): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Sets the sample rate for all calls to `classify()` that omit an explicit
|
|
52
|
+
* sample rate. `48000` is used as a default if this method is not called.
|
|
53
|
+
*
|
|
54
|
+
* @param sampleRate A sample rate (e.g. `44100`).
|
|
55
|
+
*/
|
|
56
|
+
setDefaultSampleRate(sampleRate: number): void;
|
|
57
|
+
/**
|
|
58
|
+
* Performs audio classification on the provided audio data and waits
|
|
59
|
+
* synchronously for the response.
|
|
60
|
+
*
|
|
61
|
+
* @param audioData An array of raw audio capture data, like
|
|
62
|
+
* from a call to getChannelData on an AudioBuffer.
|
|
63
|
+
* @param sampleRate The sample rate in Hz of the provided audio data. If not
|
|
64
|
+
* set, defaults to the sample rate set via `setDefaultSampleRate()` or
|
|
65
|
+
* `48000` if no custom default was set.
|
|
66
|
+
* @return The classification result of the audio datas
|
|
67
|
+
*/
|
|
68
|
+
classify(audioData: Float32Array, sampleRate?: number): AudioClassifierResult[];
|
|
69
|
+
/**
|
|
70
|
+
* Internal function for converting raw data into classification results, and
|
|
71
|
+
* adding them to our classfication results list.
|
|
72
|
+
**/
|
|
73
|
+
private addJsAudioClassificationResults;
|
|
74
|
+
/** Updates the MediaPipe graph configuration. */
|
|
75
|
+
private refreshGraph;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { AudioClassifierOptions }
|
|
79
|
+
|
|
80
|
+
export { AudioClassifierResult }
|
|
81
|
+
|
|
82
|
+
/** Listener to be passed in by user for handling output audio data. */
|
|
83
|
+
declare type AudioOutputListener = (output: Float32Array) => void;
|
|
84
|
+
|
|
85
|
+
export { Category }
|
|
86
|
+
|
|
87
|
+
export { Classifications }
|
|
88
|
+
|
|
89
|
+
/** A listener that will be invoked with an absl::StatusCode and message. */
|
|
90
|
+
declare type ErrorListener = (code: number, message: string) => void;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Valid types of image sources which we can run our WasmMediaPipeLib over.
|
|
94
|
+
*/
|
|
95
|
+
declare type ImageSource = HTMLCanvasElement | HTMLVideoElement | HTMLImageElement | ImageData | ImageBitmap;
|
|
96
|
+
|
|
97
|
+
/** Base class for all MediaPipe Tasks. */
|
|
98
|
+
declare abstract class TaskRunner extends WasmMediaPipeImageLib {
|
|
99
|
+
private processingErrors;
|
|
100
|
+
constructor(wasmModule: WasmModule);
|
|
101
|
+
/**
|
|
102
|
+
* Takes the raw data from a MediaPipe graph, and passes it to C++ to be run
|
|
103
|
+
* over the video stream. Will replace the previously running MediaPipe graph,
|
|
104
|
+
* if there is one.
|
|
105
|
+
* @param graphData The raw MediaPipe graph data, either in binary
|
|
106
|
+
* protobuffer format (.binarypb), or else in raw text format (.pbtxt or
|
|
107
|
+
* .textproto).
|
|
108
|
+
* @param isBinary This should be set to true if the graph is in
|
|
109
|
+
* binary format, and false if it is in human-readable text format.
|
|
110
|
+
*/
|
|
111
|
+
setGraph(graphData: Uint8Array, isBinary: boolean): void;
|
|
112
|
+
/**
|
|
113
|
+
* Forces all queued-up packets to be pushed through the MediaPipe graph as
|
|
114
|
+
* far as possible, performing all processing until no more processing can be
|
|
115
|
+
* done.
|
|
116
|
+
*/
|
|
117
|
+
finishProcessing(): void;
|
|
118
|
+
/** Throws the error from the error listener if an error was raised. */
|
|
119
|
+
private handleErrors;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
declare const WasmMediaPipeImageLib: (new (...args: any[]) => {
|
|
123
|
+
registerModelResourcesGraphService(): void;
|
|
124
|
+
readonly wasmModule: WasmModule;
|
|
125
|
+
readonly hasMultiStreamSupport: boolean;
|
|
126
|
+
autoResizeCanvas: boolean;
|
|
127
|
+
audioPtr: number | null;
|
|
128
|
+
audioSize: number;
|
|
129
|
+
initializeGraph(graphFile: string): Promise<void>;
|
|
130
|
+
setGraphFromString(graphConfig: string): void;
|
|
131
|
+
setGraph(graphData: Uint8Array, isBinary: boolean): void;
|
|
132
|
+
configureAudio(numChannels: number, numSamples: number, sampleRate: number): void;
|
|
133
|
+
setAutoResizeCanvas(resize: boolean): void;
|
|
134
|
+
setAutoRenderToScreen(enabled: boolean): void;
|
|
135
|
+
bindTextureToStream(imageSource: ImageSource, streamNamePtr?: number | undefined): [number, number];
|
|
136
|
+
processGl(imageSource: ImageSource, timestamp: number): WebGLTexture | undefined;
|
|
137
|
+
wrapStringPtr(stringData: string, stringPtrFunc: (ptr: number) => void): void;
|
|
138
|
+
wrapStringPtrPtr(stringData: string[], ptrFunc: (ptr: number) => void): void;
|
|
139
|
+
setListener<T>(outputStreamName: string, callbackFcn: (data: T) => void): void;
|
|
140
|
+
setVectorListener<T_1>(outputStreamName: string, callbackFcn: (data: T_1[]) => void): void;
|
|
141
|
+
attachErrorListener(callbackFcn: (code: number, message: string) => void): void;
|
|
142
|
+
addAudioToStream(audioData: Float32Array, timestamp: number): void;
|
|
143
|
+
addGpuBufferToStream(imageSource: ImageSource, streamName: string, timestamp: number): void;
|
|
144
|
+
addBoolToStream(data: boolean, streamName: string, timestamp: number): void;
|
|
145
|
+
addDoubleToStream(data: number, streamName: string, timestamp: number): void;
|
|
146
|
+
addFloatToStream(data: number, streamName: string, timestamp: number): void;
|
|
147
|
+
addIntToStream(data: number, streamName: string, timestamp: number): void;
|
|
148
|
+
addStringToStream(data: string, streamName: string, timestamp: number): void;
|
|
149
|
+
addStringRecordToStream(data: Record<string, string>, streamName: string, timestamp: number): void;
|
|
150
|
+
addProtoToStream(data: Uint8Array, protoType: string, streamName: string, timestamp: number): void;
|
|
151
|
+
addBoolToInputSidePacket(data: boolean, sidePacketName: string): void;
|
|
152
|
+
addDoubleToInputSidePacket(data: number, sidePacketName: string): void;
|
|
153
|
+
addFloatToInputSidePacket(data: number, sidePacketName: string): void;
|
|
154
|
+
addIntToInputSidePacket(data: number, sidePacketName: string): void;
|
|
155
|
+
addStringToInputSidePacket(data: string, sidePacketName: string): void;
|
|
156
|
+
addProtoToInputSidePacket(data: Uint8Array, protoType: string, sidePacketName: string): void;
|
|
157
|
+
attachBoolListener(outputStreamName: string, callbackFcn: (data: boolean) => void): void;
|
|
158
|
+
attachBoolVectorListener(outputStreamName: string, callbackFcn: (data: boolean[]) => void): void;
|
|
159
|
+
attachIntListener(outputStreamName: string, callbackFcn: (data: number) => void): void;
|
|
160
|
+
attachIntVectorListener(outputStreamName: string, callbackFcn: (data: number[]) => void): void;
|
|
161
|
+
attachDoubleListener(outputStreamName: string, callbackFcn: (data: number) => void): void;
|
|
162
|
+
attachDoubleVectorListener(outputStreamName: string, callbackFcn: (data: number[]) => void): void;
|
|
163
|
+
attachFloatListener(outputStreamName: string, callbackFcn: (data: number) => void): void;
|
|
164
|
+
attachFloatVectorListener(outputStreamName: string, callbackFcn: (data: number[]) => void): void;
|
|
165
|
+
attachStringListener(outputStreamName: string, callbackFcn: (data: string) => void): void;
|
|
166
|
+
attachStringVectorListener(outputStreamName: string, callbackFcn: (data: string[]) => void): void;
|
|
167
|
+
attachProtoListener(outputStreamName: string, callbackFcn: (data: Uint8Array) => void, makeDeepCopy?: boolean | undefined): void;
|
|
168
|
+
attachProtoVectorListener(outputStreamName: string, callbackFcn: (data: Uint8Array[]) => void, makeDeepCopy?: boolean | undefined): void;
|
|
169
|
+
setOnAudioOutput(audioOutputListener: AudioOutputListener): void;
|
|
170
|
+
finishProcessing(): void;
|
|
171
|
+
}) & (new (...args: any[]) => {
|
|
172
|
+
addGpuBufferAsImageToStream(imageSource: ImageSource, streamName: string, timestamp: number): void;
|
|
173
|
+
readonly wasmModule: WasmModule;
|
|
174
|
+
readonly hasMultiStreamSupport: boolean;
|
|
175
|
+
autoResizeCanvas: boolean;
|
|
176
|
+
audioPtr: number | null;
|
|
177
|
+
audioSize: number;
|
|
178
|
+
initializeGraph(graphFile: string): Promise<void>;
|
|
179
|
+
setGraphFromString(graphConfig: string): void;
|
|
180
|
+
setGraph(graphData: Uint8Array, isBinary: boolean): void;
|
|
181
|
+
configureAudio(numChannels: number, numSamples: number, sampleRate: number): void;
|
|
182
|
+
setAutoResizeCanvas(resize: boolean): void; /**
|
|
183
|
+
* Forces all queued-up packets to be pushed through the MediaPipe graph as
|
|
184
|
+
* far as possible, performing all processing until no more processing can be
|
|
185
|
+
* done.
|
|
186
|
+
*/
|
|
187
|
+
setAutoRenderToScreen(enabled: boolean): void;
|
|
188
|
+
bindTextureToStream(imageSource: ImageSource, streamNamePtr?: number | undefined): [number, number];
|
|
189
|
+
processGl(imageSource: ImageSource, timestamp: number): WebGLTexture | undefined;
|
|
190
|
+
wrapStringPtr(stringData: string, stringPtrFunc: (ptr: number) => void): void;
|
|
191
|
+
wrapStringPtrPtr(stringData: string[], ptrFunc: (ptr: number) => void): void;
|
|
192
|
+
setListener<T_2>(outputStreamName: string, callbackFcn: (data: T_2) => void): void;
|
|
193
|
+
setVectorListener<T_1_1>(outputStreamName: string, callbackFcn: (data: T_1_1[]) => void): void;
|
|
194
|
+
attachErrorListener(callbackFcn: (code: number, message: string) => void): void;
|
|
195
|
+
addAudioToStream(audioData: Float32Array, timestamp: number): void;
|
|
196
|
+
addGpuBufferToStream(imageSource: ImageSource, streamName: string, timestamp: number): void;
|
|
197
|
+
addBoolToStream(data: boolean, streamName: string, timestamp: number): void;
|
|
198
|
+
addDoubleToStream(data: number, streamName: string, timestamp: number): void;
|
|
199
|
+
addFloatToStream(data: number, streamName: string, timestamp: number): void;
|
|
200
|
+
addIntToStream(data: number, streamName: string, timestamp: number): void;
|
|
201
|
+
addStringToStream(data: string, streamName: string, timestamp: number): void;
|
|
202
|
+
addStringRecordToStream(data: Record<string, string>, streamName: string, timestamp: number): void;
|
|
203
|
+
addProtoToStream(data: Uint8Array, protoType: string, streamName: string, timestamp: number): void;
|
|
204
|
+
addBoolToInputSidePacket(data: boolean, sidePacketName: string): void;
|
|
205
|
+
addDoubleToInputSidePacket(data: number, sidePacketName: string): void;
|
|
206
|
+
addFloatToInputSidePacket(data: number, sidePacketName: string): void;
|
|
207
|
+
addIntToInputSidePacket(data: number, sidePacketName: string): void;
|
|
208
|
+
addStringToInputSidePacket(data: string, sidePacketName: string): void;
|
|
209
|
+
addProtoToInputSidePacket(data: Uint8Array, protoType: string, sidePacketName: string): void;
|
|
210
|
+
attachBoolListener(outputStreamName: string, callbackFcn: (data: boolean) => void): void;
|
|
211
|
+
attachBoolVectorListener(outputStreamName: string, callbackFcn: (data: boolean[]) => void): void;
|
|
212
|
+
attachIntListener(outputStreamName: string, callbackFcn: (data: number) => void): void;
|
|
213
|
+
attachIntVectorListener(outputStreamName: string, callbackFcn: (data: number[]) => void): void;
|
|
214
|
+
attachDoubleListener(outputStreamName: string, callbackFcn: (data: number) => void): void;
|
|
215
|
+
attachDoubleVectorListener(outputStreamName: string, callbackFcn: (data: number[]) => void): void;
|
|
216
|
+
attachFloatListener(outputStreamName: string, callbackFcn: (data: number) => void): void;
|
|
217
|
+
attachFloatVectorListener(outputStreamName: string, callbackFcn: (data: number[]) => void): void;
|
|
218
|
+
attachStringListener(outputStreamName: string, callbackFcn: (data: string) => void): void;
|
|
219
|
+
attachStringVectorListener(outputStreamName: string, callbackFcn: (data: string[]) => void): void;
|
|
220
|
+
attachProtoListener(outputStreamName: string, callbackFcn: (data: Uint8Array) => void, makeDeepCopy?: boolean | undefined): void;
|
|
221
|
+
attachProtoVectorListener(outputStreamName: string, callbackFcn: (data: Uint8Array[]) => void, makeDeepCopy?: boolean | undefined): void;
|
|
222
|
+
setOnAudioOutput(audioOutputListener: AudioOutputListener): void;
|
|
223
|
+
finishProcessing(): void;
|
|
224
|
+
}) & typeof WasmMediaPipeLib;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Simple class to run an arbitrary image-in/image-out MediaPipe graph (i.e.
|
|
228
|
+
* as created by wasm_mediapipe_demo BUILD macro), and either render results
|
|
229
|
+
* into canvas, or else return the output WebGLTexture. Takes a WebAssembly
|
|
230
|
+
* Module (must be instantiated to self.Module).
|
|
231
|
+
*/
|
|
232
|
+
declare class WasmMediaPipeLib {
|
|
233
|
+
readonly wasmModule: WasmModule;
|
|
234
|
+
readonly hasMultiStreamSupport: boolean;
|
|
235
|
+
autoResizeCanvas: boolean;
|
|
236
|
+
audioPtr: number | null;
|
|
237
|
+
audioSize: number;
|
|
238
|
+
/**
|
|
239
|
+
* Creates a new MediaPipe WASM module. Must be called *after* wasm Module has
|
|
240
|
+
* initialized. Note that we take control of the GL canvas from here on out,
|
|
241
|
+
* and will resize it to fit input.
|
|
242
|
+
*
|
|
243
|
+
* @param module The underlying Wasm Module to use.
|
|
244
|
+
* @param glCanvas The type of the GL canvas to use, or `null` if no GL
|
|
245
|
+
* canvas should be initialzed. Initializes an offscreen canvas if not
|
|
246
|
+
* provided.
|
|
247
|
+
*/
|
|
248
|
+
constructor(module: WasmModule, glCanvas?: HTMLCanvasElement | OffscreenCanvas | null);
|
|
249
|
+
/**
|
|
250
|
+
* Convenience helper to load a MediaPipe graph from a file and pass it to
|
|
251
|
+
* setGraph.
|
|
252
|
+
* @param graphFile The url of the MediaPipe graph file to load.
|
|
253
|
+
*/
|
|
254
|
+
initializeGraph(graphFile: string): Promise<void>;
|
|
255
|
+
/**
|
|
256
|
+
* Convenience helper for calling setGraph with a string representing a text
|
|
257
|
+
* proto config.
|
|
258
|
+
* @param graphConfig The text proto graph config, expected to be a string in
|
|
259
|
+
* default JavaScript UTF-16 format.
|
|
260
|
+
*/
|
|
261
|
+
setGraphFromString(graphConfig: string): void;
|
|
262
|
+
/**
|
|
263
|
+
* Takes the raw data from a MediaPipe graph, and passes it to C++ to be run
|
|
264
|
+
* over the video stream. Will replace the previously running MediaPipe graph,
|
|
265
|
+
* if there is one.
|
|
266
|
+
* @param graphData The raw MediaPipe graph data, either in binary
|
|
267
|
+
* protobuffer format (.binarypb), or else in raw text format (.pbtxt or
|
|
268
|
+
* .textproto).
|
|
269
|
+
* @param isBinary This should be set to true if the graph is in
|
|
270
|
+
* binary format, and false if it is in human-readable text format.
|
|
271
|
+
*/
|
|
272
|
+
setGraph(graphData: Uint8Array, isBinary: boolean): void;
|
|
273
|
+
/**
|
|
274
|
+
* Configures the current graph to handle audio in a certain way. Must be
|
|
275
|
+
* called before the graph is set/started in order to use processAudio.
|
|
276
|
+
* @param numChannels The number of channels of audio input. Only 1
|
|
277
|
+
* is supported for now.
|
|
278
|
+
* @param numSamples The number of samples that are taken in each
|
|
279
|
+
* audio capture.
|
|
280
|
+
* @param sampleRate The rate, in Hz, of the sampling.
|
|
281
|
+
*/
|
|
282
|
+
configureAudio(numChannels: number, numSamples: number, sampleRate: number): void;
|
|
283
|
+
/**
|
|
284
|
+
* Allows disabling automatic canvas resizing, in case clients want to control
|
|
285
|
+
* control this.
|
|
286
|
+
* @param resize True will re-enable automatic canvas resizing, while false
|
|
287
|
+
* will disable the feature.
|
|
288
|
+
*/
|
|
289
|
+
setAutoResizeCanvas(resize: boolean): void;
|
|
290
|
+
/**
|
|
291
|
+
* Allows disabling the automatic render-to-screen code, in case clients don't
|
|
292
|
+
* need/want this. In particular, this removes the requirement for pipelines
|
|
293
|
+
* to have access to GPU resources, as well as the requirement for graphs to
|
|
294
|
+
* have "input_frames_gpu" and "output_frames_gpu" streams defined, so pure
|
|
295
|
+
* CPU pipelines and non-video pipelines can be created.
|
|
296
|
+
* NOTE: This only affects future graph initializations (via setGraph or
|
|
297
|
+
* initializeGraph), and does NOT affect the currently running graph, so
|
|
298
|
+
* calls to this should be made *before* setGraph/initializeGraph for the
|
|
299
|
+
* graph file being targeted.
|
|
300
|
+
* @param enabled True will re-enable automatic render-to-screen code and
|
|
301
|
+
* cause GPU resources to once again be requested, while false will
|
|
302
|
+
* disable the feature.
|
|
303
|
+
*/
|
|
304
|
+
setAutoRenderToScreen(enabled: boolean): void;
|
|
305
|
+
/**
|
|
306
|
+
* Bind texture to our internal canvas, and upload image source to GPU.
|
|
307
|
+
* Returns tuple [width, height] of texture. Intended for internal usage.
|
|
308
|
+
*/
|
|
309
|
+
bindTextureToStream(imageSource: ImageSource, streamNamePtr?: number): [
|
|
310
|
+
number,
|
|
311
|
+
number
|
|
312
|
+
];
|
|
313
|
+
/**
|
|
314
|
+
* Takes the raw data from a JS image source, and sends it to C++ to be
|
|
315
|
+
* processed, waiting synchronously for the response. Note that we will resize
|
|
316
|
+
* our GL canvas to fit the input, so input size should only change
|
|
317
|
+
* infrequently.
|
|
318
|
+
* @param imageSource An image source to process.
|
|
319
|
+
* @param timestamp The timestamp of the current frame, in ms.
|
|
320
|
+
* @return texture? The WebGL texture reference, if one was produced.
|
|
321
|
+
*/
|
|
322
|
+
processGl(imageSource: ImageSource, timestamp: number): WebGLTexture | undefined;
|
|
323
|
+
/**
|
|
324
|
+
* Converts JavaScript string input parameters into C++ c-string pointers.
|
|
325
|
+
* See b/204830158 for more details. Intended for internal usage.
|
|
326
|
+
*/
|
|
327
|
+
wrapStringPtr(stringData: string, stringPtrFunc: (ptr: number) => void): void;
|
|
328
|
+
/**
|
|
329
|
+
* Converts JavaScript string input parameters into C++ c-string pointers.
|
|
330
|
+
* See b/204830158 for more details.
|
|
331
|
+
*/
|
|
332
|
+
wrapStringPtrPtr(stringData: string[], ptrFunc: (ptr: number) => void): void;
|
|
333
|
+
/**
|
|
334
|
+
* Ensures existence of the simple listeners table and registers the callback.
|
|
335
|
+
* Intended for internal usage.
|
|
336
|
+
*/
|
|
337
|
+
setListener<T>(outputStreamName: string, callbackFcn: (data: T) => void): void;
|
|
338
|
+
/**
|
|
339
|
+
* Ensures existence of the vector listeners table and registers the callback.
|
|
340
|
+
* Intended for internal usage.
|
|
341
|
+
*/
|
|
342
|
+
setVectorListener<T>(outputStreamName: string, callbackFcn: (data: T[]) => void): void;
|
|
343
|
+
/**
|
|
344
|
+
* Attaches a listener that will be invoked when the MediaPipe framework
|
|
345
|
+
* returns an error.
|
|
346
|
+
*/
|
|
347
|
+
attachErrorListener(callbackFcn: (code: number, message: string) => void): void;
|
|
348
|
+
/**
|
|
349
|
+
* Takes the raw data from a JS audio capture array, and sends it to C++ to be
|
|
350
|
+
* processed.
|
|
351
|
+
* @param audioData An array of raw audio capture data, like
|
|
352
|
+
* from a call to getChannelData on an AudioBuffer.
|
|
353
|
+
* @param timestamp The timestamp of the current frame, in ms.
|
|
354
|
+
*/
|
|
355
|
+
addAudioToStream(audioData: Float32Array, timestamp: number): void;
|
|
356
|
+
/**
|
|
357
|
+
* Takes the relevant information from the HTML video or image element, and
|
|
358
|
+
* passes it into the WebGL-based graph for processing on the given stream at
|
|
359
|
+
* the given timestamp. Can be used for additional auxiliary GpuBuffer input
|
|
360
|
+
* streams. Processing will not occur until a blocking call (like
|
|
361
|
+
* processVideoGl or finishProcessing) is made. For use with
|
|
362
|
+
* 'gl_graph_runner_internal_multi_input'.
|
|
363
|
+
* @param imageSource Reference to the video frame we wish to add into our
|
|
364
|
+
* graph.
|
|
365
|
+
* @param streamName The name of the MediaPipe graph stream to add the frame
|
|
366
|
+
* to.
|
|
367
|
+
* @param timestamp The timestamp of the input frame, in ms.
|
|
368
|
+
*/
|
|
369
|
+
addGpuBufferToStream(imageSource: ImageSource, streamName: string, timestamp: number): void;
|
|
370
|
+
/**
|
|
371
|
+
* Sends a boolean packet into the specified stream at the given timestamp.
|
|
372
|
+
* @param data The boolean data to send.
|
|
373
|
+
* @param streamName The name of the graph input stream to send data into.
|
|
374
|
+
* @param timestamp The timestamp of the input data, in ms.
|
|
375
|
+
*/
|
|
376
|
+
addBoolToStream(data: boolean, streamName: string, timestamp: number): void;
|
|
377
|
+
/**
|
|
378
|
+
* Sends a double packet into the specified stream at the given timestamp.
|
|
379
|
+
* @param data The double data to send.
|
|
380
|
+
* @param streamName The name of the graph input stream to send data into.
|
|
381
|
+
* @param timestamp The timestamp of the input data, in ms.
|
|
382
|
+
*/
|
|
383
|
+
addDoubleToStream(data: number, streamName: string, timestamp: number): void;
|
|
384
|
+
/**
|
|
385
|
+
* Sends a float packet into the specified stream at the given timestamp.
|
|
386
|
+
* @param data The float data to send.
|
|
387
|
+
* @param streamName The name of the graph input stream to send data into.
|
|
388
|
+
* @param timestamp The timestamp of the input data, in ms.
|
|
389
|
+
*/
|
|
390
|
+
addFloatToStream(data: number, streamName: string, timestamp: number): void;
|
|
391
|
+
/**
|
|
392
|
+
* Sends an integer packet into the specified stream at the given timestamp.
|
|
393
|
+
* @param data The integer data to send.
|
|
394
|
+
* @param streamName The name of the graph input stream to send data into.
|
|
395
|
+
* @param timestamp The timestamp of the input data, in ms.
|
|
396
|
+
*/
|
|
397
|
+
addIntToStream(data: number, streamName: string, timestamp: number): void;
|
|
398
|
+
/**
|
|
399
|
+
* Sends a string packet into the specified stream at the given timestamp.
|
|
400
|
+
* @param data The string data to send.
|
|
401
|
+
* @param streamName The name of the graph input stream to send data into.
|
|
402
|
+
* @param timestamp The timestamp of the input data, in ms.
|
|
403
|
+
*/
|
|
404
|
+
addStringToStream(data: string, streamName: string, timestamp: number): void;
|
|
405
|
+
/**
|
|
406
|
+
* Sends a Record<string, string> packet into the specified stream at the
|
|
407
|
+
* given timestamp.
|
|
408
|
+
* @param data The records to send (will become a
|
|
409
|
+
* std::flat_hash_map<std::string, std::string).
|
|
410
|
+
* @param streamName The name of the graph input stream to send data into.
|
|
411
|
+
* @param timestamp The timestamp of the input data, in ms.
|
|
412
|
+
*/
|
|
413
|
+
addStringRecordToStream(data: Record<string, string>, streamName: string, timestamp: number): void;
|
|
414
|
+
/**
|
|
415
|
+
* Sends a serialized protobuffer packet into the specified stream at the
|
|
416
|
+
* given timestamp, to be parsed into the specified protobuffer type.
|
|
417
|
+
* @param data The binary (serialized) raw protobuffer data.
|
|
418
|
+
* @param protoType The C++ namespaced type this protobuffer data corresponds
|
|
419
|
+
* to. It will be converted to this type when output as a packet into the
|
|
420
|
+
* graph.
|
|
421
|
+
* @param streamName The name of the graph input stream to send data into.
|
|
422
|
+
* @param timestamp The timestamp of the input data, in ms.
|
|
423
|
+
*/
|
|
424
|
+
addProtoToStream(data: Uint8Array, protoType: string, streamName: string, timestamp: number): void;
|
|
425
|
+
/**
|
|
426
|
+
* Attaches a boolean packet to the specified input_side_packet.
|
|
427
|
+
* @param data The boolean data to send.
|
|
428
|
+
* @param sidePacketName The name of the graph input side packet to send data
|
|
429
|
+
* into.
|
|
430
|
+
*/
|
|
431
|
+
addBoolToInputSidePacket(data: boolean, sidePacketName: string): void;
|
|
432
|
+
/**
|
|
433
|
+
* Attaches a double packet to the specified input_side_packet.
|
|
434
|
+
* @param data The double data to send.
|
|
435
|
+
* @param sidePacketName The name of the graph input side packet to send data
|
|
436
|
+
* into.
|
|
437
|
+
*/
|
|
438
|
+
addDoubleToInputSidePacket(data: number, sidePacketName: string): void;
|
|
439
|
+
/**
|
|
440
|
+
* Attaches a float packet to the specified input_side_packet.
|
|
441
|
+
* @param data The float data to send.
|
|
442
|
+
* @param sidePacketName The name of the graph input side packet to send data
|
|
443
|
+
* into.
|
|
444
|
+
*/
|
|
445
|
+
addFloatToInputSidePacket(data: number, sidePacketName: string): void;
|
|
446
|
+
/**
|
|
447
|
+
* Attaches a integer packet to the specified input_side_packet.
|
|
448
|
+
* @param data The integer data to send.
|
|
449
|
+
* @param sidePacketName The name of the graph input side packet to send data
|
|
450
|
+
* into.
|
|
451
|
+
*/
|
|
452
|
+
addIntToInputSidePacket(data: number, sidePacketName: string): void;
|
|
453
|
+
/**
|
|
454
|
+
* Attaches a string packet to the specified input_side_packet.
|
|
455
|
+
* @param data The string data to send.
|
|
456
|
+
* @param sidePacketName The name of the graph input side packet to send data
|
|
457
|
+
* into.
|
|
458
|
+
*/
|
|
459
|
+
addStringToInputSidePacket(data: string, sidePacketName: string): void;
|
|
460
|
+
/**
|
|
461
|
+
* Attaches a serialized proto packet to the specified input_side_packet.
|
|
462
|
+
* @param data The binary (serialized) raw protobuffer data.
|
|
463
|
+
* @param protoType The C++ namespaced type this protobuffer data corresponds
|
|
464
|
+
* to. It will be converted to this type for use in the graph.
|
|
465
|
+
* @param sidePacketName The name of the graph input side packet to send data
|
|
466
|
+
* into.
|
|
467
|
+
*/
|
|
468
|
+
addProtoToInputSidePacket(data: Uint8Array, protoType: string, sidePacketName: string): void;
|
|
469
|
+
/**
|
|
470
|
+
* Attaches a boolean packet listener to the specified output_stream.
|
|
471
|
+
* @param outputStreamName The name of the graph output stream to grab boolean
|
|
472
|
+
* data from.
|
|
473
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
474
|
+
* it is received. Note that the data is only guaranteed to exist for the
|
|
475
|
+
* duration of the callback, and the callback will be called inline, so it
|
|
476
|
+
* should not perform overly complicated (or any async) behavior.
|
|
477
|
+
*/
|
|
478
|
+
attachBoolListener(outputStreamName: string, callbackFcn: (data: boolean) => void): void;
|
|
479
|
+
/**
|
|
480
|
+
* Attaches a bool[] packet listener to the specified output_stream.
|
|
481
|
+
* @param outputStreamName The name of the graph output stream to grab
|
|
482
|
+
* std::vector<bool> data from.
|
|
483
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
484
|
+
* it is received. Note that the data is only guaranteed to exist for the
|
|
485
|
+
* duration of the callback, and the callback will be called inline, so it
|
|
486
|
+
* should not perform overly complicated (or any async) behavior.
|
|
487
|
+
*/
|
|
488
|
+
attachBoolVectorListener(outputStreamName: string, callbackFcn: (data: boolean[]) => void): void;
|
|
489
|
+
/**
|
|
490
|
+
* Attaches an int packet listener to the specified output_stream.
|
|
491
|
+
* @param outputStreamName The name of the graph output stream to grab int
|
|
492
|
+
* data from.
|
|
493
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
494
|
+
* it is received. Note that the data is only guaranteed to exist for the
|
|
495
|
+
* duration of the callback, and the callback will be called inline, so it
|
|
496
|
+
* should not perform overly complicated (or any async) behavior.
|
|
497
|
+
*/
|
|
498
|
+
attachIntListener(outputStreamName: string, callbackFcn: (data: number) => void): void;
|
|
499
|
+
/**
|
|
500
|
+
* Attaches an int[] packet listener to the specified output_stream.
|
|
501
|
+
* @param outputStreamName The name of the graph output stream to grab
|
|
502
|
+
* std::vector<int> data from.
|
|
503
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
504
|
+
* it is received. Note that the data is only guaranteed to exist for the
|
|
505
|
+
* duration of the callback, and the callback will be called inline, so it
|
|
506
|
+
* should not perform overly complicated (or any async) behavior.
|
|
507
|
+
*/
|
|
508
|
+
attachIntVectorListener(outputStreamName: string, callbackFcn: (data: number[]) => void): void;
|
|
509
|
+
/**
|
|
510
|
+
* Attaches a double packet listener to the specified output_stream.
|
|
511
|
+
* @param outputStreamName The name of the graph output stream to grab double
|
|
512
|
+
* data from.
|
|
513
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
514
|
+
* it is received. Note that the data is only guaranteed to exist for the
|
|
515
|
+
* duration of the callback, and the callback will be called inline, so it
|
|
516
|
+
* should not perform overly complicated (or any async) behavior.
|
|
517
|
+
*/
|
|
518
|
+
attachDoubleListener(outputStreamName: string, callbackFcn: (data: number) => void): void;
|
|
519
|
+
/**
|
|
520
|
+
* Attaches a double[] packet listener to the specified output_stream.
|
|
521
|
+
* @param outputStreamName The name of the graph output stream to grab
|
|
522
|
+
* std::vector<double> data from.
|
|
523
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
524
|
+
* it is received. Note that the data is only guaranteed to exist for the
|
|
525
|
+
* duration of the callback, and the callback will be called inline, so it
|
|
526
|
+
* should not perform overly complicated (or any async) behavior.
|
|
527
|
+
*/
|
|
528
|
+
attachDoubleVectorListener(outputStreamName: string, callbackFcn: (data: number[]) => void): void;
|
|
529
|
+
/**
|
|
530
|
+
* Attaches a float packet listener to the specified output_stream.
|
|
531
|
+
* @param outputStreamName The name of the graph output stream to grab float
|
|
532
|
+
* data from.
|
|
533
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
534
|
+
* it is received. Note that the data is only guaranteed to exist for the
|
|
535
|
+
* duration of the callback, and the callback will be called inline, so it
|
|
536
|
+
* should not perform overly complicated (or any async) behavior.
|
|
537
|
+
*/
|
|
538
|
+
attachFloatListener(outputStreamName: string, callbackFcn: (data: number) => void): void;
|
|
539
|
+
/**
|
|
540
|
+
* Attaches a float[] packet listener to the specified output_stream.
|
|
541
|
+
* @param outputStreamName The name of the graph output stream to grab
|
|
542
|
+
* std::vector<float> data from.
|
|
543
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
544
|
+
* it is received. Note that the data is only guaranteed to exist for the
|
|
545
|
+
* duration of the callback, and the callback will be called inline, so it
|
|
546
|
+
* should not perform overly complicated (or any async) behavior.
|
|
547
|
+
*/
|
|
548
|
+
attachFloatVectorListener(outputStreamName: string, callbackFcn: (data: number[]) => void): void;
|
|
549
|
+
/**
|
|
550
|
+
* Attaches a string packet listener to the specified output_stream.
|
|
551
|
+
* @param outputStreamName The name of the graph output stream to grab string
|
|
552
|
+
* data from.
|
|
553
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
554
|
+
* it is received. Note that the data is only guaranteed to exist for the
|
|
555
|
+
* duration of the callback, and the callback will be called inline, so it
|
|
556
|
+
* should not perform overly complicated (or any async) behavior.
|
|
557
|
+
*/
|
|
558
|
+
attachStringListener(outputStreamName: string, callbackFcn: (data: string) => void): void;
|
|
559
|
+
/**
|
|
560
|
+
* Attaches a string[] packet listener to the specified output_stream.
|
|
561
|
+
* @param outputStreamName The name of the graph output stream to grab
|
|
562
|
+
* std::vector<std::string> data from.
|
|
563
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
564
|
+
* it is received. Note that the data is only guaranteed to exist for the
|
|
565
|
+
* duration of the callback, and the callback will be called inline, so it
|
|
566
|
+
* should not perform overly complicated (or any async) behavior.
|
|
567
|
+
*/
|
|
568
|
+
attachStringVectorListener(outputStreamName: string, callbackFcn: (data: string[]) => void): void;
|
|
569
|
+
/**
|
|
570
|
+
* Attaches a serialized proto packet listener to the specified output_stream.
|
|
571
|
+
* @param outputStreamName The name of the graph output stream to grab binary
|
|
572
|
+
* serialized proto data from (in Uint8Array format).
|
|
573
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
574
|
+
* it is received. Note that by default the data is only guaranteed to
|
|
575
|
+
* exist for the duration of the callback, and the callback will be called
|
|
576
|
+
* inline, so it should not perform overly complicated (or any async)
|
|
577
|
+
* behavior. If the proto data needs to be able to outlive the call, you
|
|
578
|
+
* may set the optional makeDeepCopy parameter to true, or can manually
|
|
579
|
+
* deep-copy the data yourself.
|
|
580
|
+
* @param makeDeepCopy Optional convenience parameter which, if set to true,
|
|
581
|
+
* will override the default memory management behavior and make a deep
|
|
582
|
+
* copy of the underlying data, rather than just returning a view into the
|
|
583
|
+
* C++-managed memory. At the cost of a data copy, this allows the
|
|
584
|
+
* returned data to outlive the callback lifetime (and it will be cleaned
|
|
585
|
+
* up automatically by JS garbage collection whenever the user is finished
|
|
586
|
+
* with it).
|
|
587
|
+
*/
|
|
588
|
+
attachProtoListener(outputStreamName: string, callbackFcn: (data: Uint8Array) => void, makeDeepCopy?: boolean): void;
|
|
589
|
+
/**
|
|
590
|
+
* Attaches a listener for an array of serialized proto packets to the
|
|
591
|
+
* specified output_stream.
|
|
592
|
+
* @param outputStreamName The name of the graph output stream to grab a
|
|
593
|
+
* vector of binary serialized proto data from (in Uint8Array[] format).
|
|
594
|
+
* @param callbackFcn The function that will be called back with the data, as
|
|
595
|
+
* it is received. Note that by default the data is only guaranteed to
|
|
596
|
+
* exist for the duration of the callback, and the callback will be called
|
|
597
|
+
* inline, so it should not perform overly complicated (or any async)
|
|
598
|
+
* behavior. If the proto data needs to be able to outlive the call, you
|
|
599
|
+
* may set the optional makeDeepCopy parameter to true, or can manually
|
|
600
|
+
* deep-copy the data yourself.
|
|
601
|
+
* @param makeDeepCopy Optional convenience parameter which, if set to true,
|
|
602
|
+
* will override the default memory management behavior and make a deep
|
|
603
|
+
* copy of the underlying data, rather than just returning a view into the
|
|
604
|
+
* C++-managed memory. At the cost of a data copy, this allows the
|
|
605
|
+
* returned data to outlive the callback lifetime (and it will be cleaned
|
|
606
|
+
* up automatically by JS garbage collection whenever the user is finished
|
|
607
|
+
* with it).
|
|
608
|
+
*/
|
|
609
|
+
attachProtoVectorListener(outputStreamName: string, callbackFcn: (data: Uint8Array[]) => void, makeDeepCopy?: boolean): void;
|
|
610
|
+
/**
|
|
611
|
+
* Sets a listener to be called back with audio output packet data, as a
|
|
612
|
+
* Float32Array, when graph has finished processing it.
|
|
613
|
+
* @param audioOutputListener The caller's listener function.
|
|
614
|
+
*/
|
|
615
|
+
setOnAudioOutput(audioOutputListener: AudioOutputListener): void;
|
|
616
|
+
/**
|
|
617
|
+
* Forces all queued-up packets to be pushed through the MediaPipe graph as
|
|
618
|
+
* far as possible, performing all processing until no more processing can be
|
|
619
|
+
* done.
|
|
620
|
+
*/
|
|
621
|
+
finishProcessing(): void;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Declarations for Emscripten's WebAssembly Module behavior, so TS compiler
|
|
626
|
+
* doesn't break our JS/C++ bridge.
|
|
627
|
+
*/
|
|
628
|
+
declare interface WasmModule {
|
|
629
|
+
canvas: HTMLCanvasElement | OffscreenCanvas | null;
|
|
630
|
+
HEAPU8: Uint8Array;
|
|
631
|
+
HEAPU32: Uint32Array;
|
|
632
|
+
HEAPF32: Float32Array;
|
|
633
|
+
HEAPF64: Float64Array;
|
|
634
|
+
errorListener?: ErrorListener;
|
|
635
|
+
_bindTextureToCanvas: () => boolean;
|
|
636
|
+
_changeBinaryGraph: (size: number, dataPtr: number) => void;
|
|
637
|
+
_changeTextGraph: (size: number, dataPtr: number) => void;
|
|
638
|
+
_configureAudio: (channels: number, samples: number, sampleRate: number) => void;
|
|
639
|
+
_free: (ptr: number) => void;
|
|
640
|
+
_malloc: (size: number) => number;
|
|
641
|
+
_processAudio: (dataPtr: number, timestamp: number) => void;
|
|
642
|
+
_processFrame: (width: number, height: number, timestamp: number) => void;
|
|
643
|
+
_setAutoRenderToScreen: (enabled: boolean) => void;
|
|
644
|
+
_waitUntilIdle: () => void;
|
|
645
|
+
dataFileDownloads?: {
|
|
646
|
+
[url: string]: {
|
|
647
|
+
loaded: number;
|
|
648
|
+
total: number;
|
|
649
|
+
};
|
|
650
|
+
};
|
|
651
|
+
onAudioOutput?: AudioOutputListener;
|
|
652
|
+
stringToNewUTF8: (data: string) => number;
|
|
653
|
+
_bindTextureToStream: (streamNamePtr: number) => void;
|
|
654
|
+
_addBoundTextureToStream: (streamNamePtr: number, width: number, height: number, timestamp: number) => void;
|
|
655
|
+
_addBoolToInputStream: (data: boolean, streamNamePtr: number, timestamp: number) => void;
|
|
656
|
+
_addDoubleToInputStream: (data: number, streamNamePtr: number, timestamp: number) => void;
|
|
657
|
+
_addFloatToInputStream: (data: number, streamNamePtr: number, timestamp: number) => void;
|
|
658
|
+
_addIntToInputStream: (data: number, streamNamePtr: number, timestamp: number) => void;
|
|
659
|
+
_addStringToInputStream: (dataPtr: number, streamNamePtr: number, timestamp: number) => void;
|
|
660
|
+
_addFlatHashMapToInputStream: (keysPtr: number, valuesPtr: number, count: number, streamNamePtr: number, timestamp: number) => void;
|
|
661
|
+
_addProtoToInputStream: (dataPtr: number, dataSize: number, protoNamePtr: number, streamNamePtr: number, timestamp: number) => void;
|
|
662
|
+
_addBoolToInputSidePacket: (data: boolean, streamNamePtr: number) => void;
|
|
663
|
+
_addDoubleToInputSidePacket: (data: number, streamNamePtr: number) => void;
|
|
664
|
+
_addFloatToInputSidePacket: (data: number, streamNamePtr: number) => void;
|
|
665
|
+
_addIntToInputSidePacket: (data: number, streamNamePtr: number) => void;
|
|
666
|
+
_addStringToInputSidePacket: (dataPtr: number, streamNamePtr: number) => void;
|
|
667
|
+
_addProtoToInputSidePacket: (dataPtr: number, dataSize: number, protoNamePtr: number, streamNamePtr: number) => void;
|
|
668
|
+
simpleListeners?: {
|
|
669
|
+
[outputStreamName: string]: (data: unknown) => void;
|
|
670
|
+
};
|
|
671
|
+
vectorListeners?: {
|
|
672
|
+
[outputStreamName: string]: (data: unknown, index: number, length: number) => void;
|
|
673
|
+
};
|
|
674
|
+
_attachBoolListener: (streamNamePtr: number) => void;
|
|
675
|
+
_attachBoolVectorListener: (streamNamePtr: number) => void;
|
|
676
|
+
_attachDoubleListener: (streamNamePtr: number) => void;
|
|
677
|
+
_attachDoubleVectorListener: (streamNamePtr: number) => void;
|
|
678
|
+
_attachFloatListener: (streamNamePtr: number) => void;
|
|
679
|
+
_attachFloatVectorListener: (streamNamePtr: number) => void;
|
|
680
|
+
_attachIntListener: (streamNamePtr: number) => void;
|
|
681
|
+
_attachIntVectorListener: (streamNamePtr: number) => void;
|
|
682
|
+
_attachStringListener: (streamNamePtr: number) => void;
|
|
683
|
+
_attachStringVectorListener: (streamNamePtr: number) => void;
|
|
684
|
+
_attachProtoListener: (streamNamePtr: number, makeDeepCopy?: boolean) => void;
|
|
685
|
+
_attachProtoVectorListener: (streamNamePtr: number, makeDeepCopy?: boolean) => void;
|
|
686
|
+
_attachAudioOutputListener: () => void;
|
|
687
|
+
_processGl: (frameDataPtr: number) => number;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
export { }
|