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