@mediapipe/tasks-audio 1.2.0-rc.20261021 → 1.2.0-rc.20261024

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 CHANGED
@@ -89,6 +89,143 @@ declare abstract class AudioTaskRunner<T> extends TaskRunner {
89
89
  setDefaultSampleRate(sampleRate: number): void;
90
90
  }
91
91
 
92
+ /**
93
+ * MediaPipe Audio Task that performs automatic speech recognition (ASR) in
94
+ * unary and streaming modes via WASM SIMD or WebGPU.
95
+ */
96
+ export declare class AudioTranscriber extends TaskRunner {
97
+ /**
98
+ * Initializes the Wasm runtime and creates a new `AudioTranscriber` based on
99
+ * the provided options.
100
+ *
101
+ * @export
102
+ * @param wasmFileset A configuration object that provides the location of
103
+ * the Wasm binary and its loader.
104
+ * @param options The options for the AudioTranscriber. Note that either a
105
+ * path to the model or the model buffer itself must be provided via
106
+ * `baseOptions`.
107
+ */
108
+ static createFromOptions(wasmFileset: WasmFileset, options: AudioTranscriberOptions): Promise<AudioTranscriber>;
109
+ /**
110
+ * Initializes the Wasm runtime and creates a new `AudioTranscriber` from a
111
+ * model asset path.
112
+ *
113
+ * @export
114
+ * @param wasmFileset A configuration object that provides the location of
115
+ * the Wasm binary and its loader.
116
+ * @param modelAssetPath The path or URL to the `.litertlm` model asset.
117
+ */
118
+ static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string | string): Promise<AudioTranscriber>;
119
+ /**
120
+ * Initializes the Wasm runtime and creates a new `AudioTranscriber` from a
121
+ * model asset buffer or stream.
122
+ *
123
+ * @export
124
+ * @param wasmFileset A configuration object that provides the location of
125
+ * the Wasm binary and its loader.
126
+ * @param modelAssetBuffer A `Uint8Array` or `ReadableStreamDefaultReader`
127
+ * containing the `.litertlm` model bytes.
128
+ */
129
+ static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<AudioTranscriber>;
130
+ private constructor();
131
+ /**
132
+ * Sets the options for the `AudioTranscriber` and initializes the underlying
133
+ * engine. Options cannot be updated once the engine has been created.
134
+ *
135
+ * @export
136
+ * @param options The options for the AudioTranscriber.
137
+ */
138
+ setOptions(options: AudioTranscriberOptions): Promise<void>;
139
+ /**
140
+ * Transcribes mono PCM float audio samples in `[-1.0, 1.0]`.
141
+ *
142
+ * @export
143
+ * @param audioSamples Mono PCM float audio samples at `sampleRateHz`.
144
+ * @param endOfStream Whether this chunk marks the end of the audio stream.
145
+ * Defaults to `true` (unary single-utterance mode).
146
+ * @return The transcription result containing segments and concatenated text.
147
+ */
148
+ transcribe(audioSamples: Float32Array | number[], endOfStream?: boolean): Promise<AudioTranscriberResult>;
149
+ /**
150
+ * Feeds a streaming chunk of mono PCM float audio samples (`endOfStream = false`)
151
+ * and returns any newly emitted interim or final segments.
152
+ *
153
+ * @export
154
+ * @param audioSamples Mono PCM float audio samples at `sampleRateHz`.
155
+ * @return Newly emitted segments from the streaming session.
156
+ */
157
+ transcribeStream(audioSamples: Float32Array | number[]): Promise<AudioTranscriberResult>;
158
+ /**
159
+ * Flushes any remaining buffered audio and finalizes the current stream.
160
+ *
161
+ * @export
162
+ * @return Finalized transcription segments.
163
+ */
164
+ finishStream(): Promise<AudioTranscriberResult>;
165
+ /**
166
+ * Prewarms the underlying inference engine to reduce first-chunk latency.
167
+ *
168
+ * @export
169
+ */
170
+ prewarm(): Promise<void>;
171
+ /**
172
+ * Closes the `AudioTranscriber` and releases native engine and Wasm memory.
173
+ *
174
+ * @export
175
+ */
176
+ close(): void;
177
+ }
178
+
179
+ /**
180
+ * Model architecture family for AudioTranscriber.
181
+ */
182
+ export declare type AudioTranscriberModelArchitecture = "AUTO" | "OMNI" | "TINY_GEMMA";
183
+
184
+ /**
185
+ * Options to configure the MediaPipe AudioTranscriber Task on the Web.
186
+ */
187
+ export declare interface AudioTranscriberOptions extends TaskRunnerOptions {
188
+ /**
189
+ * Input audio sample rate in Hz. Defaults to 16000 Hz when unset or 0.
190
+ */
191
+ sampleRateHz?: number;
192
+ /**
193
+ * Whether to emit interim (non-final) transcription segments during
194
+ * streaming. Defaults to false.
195
+ */
196
+ enableInterimResults?: boolean;
197
+ /**
198
+ * Model architecture backend family ('AUTO', 'OMNI', or 'TINY_GEMMA', or
199
+ * numeric code 0=AUTO, 1=OMNI, 2=TINY_GEMMA). Defaults to 'AUTO'.
200
+ */
201
+ modelArchitecture?: AudioTranscriberModelArchitecture | number;
202
+ /**
203
+ * Optional system or user prompt override for generative ASR models.
204
+ */
205
+ prompt?: string;
206
+ /**
207
+ * Optional directory path in the Wasm virtual filesystem for caching
208
+ * compiled model artifacts.
209
+ */
210
+ cacheDir?: string;
211
+ /**
212
+ * Optional byte length of `baseOptions.modelAssetBuffer` when provided as a
213
+ * `ReadableStreamDefaultReader`, enabling single-pass zero-copy streaming
214
+ * allocation directly in the Wasm heap.
215
+ */
216
+ modelAssetSize?: number;
217
+ }
218
+
219
+ /**
220
+ * Result of an AudioTranscriber invocation.
221
+ */
222
+ export declare interface AudioTranscriberResult {
223
+ /** Ordered list of transcribed segments. */
224
+ segments: TranscriptionSegment[];
225
+ /** Concatenated full transcript across all segments in this result. */
226
+ text: string;
227
+ }
228
+
92
229
  /**
93
230
  * Copyright 2022 The MediaPipe Authors.
94
231
  *
@@ -325,6 +462,17 @@ export declare class FilesetResolver {
325
462
  static forVisionTasks(basePath?: string, useModule?: boolean): Promise<WasmFileset>;
326
463
  }
327
464
 
465
+ /**
466
+ * Per-utterance synthesis overrides passed to `TextToSpeech.synthesize()` and
467
+ * `TextToSpeech.synthesizeStream()`.
468
+ */
469
+ export declare interface SynthesisOptions {
470
+ /** Optional voice identifier override (e.g. "af_heart", "ef_dora"). */
471
+ voiceId?: string;
472
+ /** Optional BCP-47 locale override (e.g. "en-US", "es-ES", "ja-JP"). */
473
+ locale?: string;
474
+ }
475
+
328
476
  /** Base class for all MediaPipe Tasks. */
329
477
  declare abstract class TaskRunner {
330
478
  protected constructor();
@@ -344,6 +492,259 @@ declare interface TaskRunnerOptions {
344
492
  baseOptions?: BaseOptions_2;
345
493
  }
346
494
 
495
+ /**
496
+ * MediaPipe Audio Task that performs neural text-to-speech synthesis in unary
497
+ * and streaming modes via WASM SIMD or WebGPU.
498
+ */
499
+ export declare class TextToSpeech extends TaskRunner {
500
+ /**
501
+ * Initializes the Wasm runtime and creates a new `TextToSpeech` instance
502
+ * based on the provided options.
503
+ *
504
+ * @export
505
+ * @param wasmFileset A configuration object that provides the location of
506
+ * the Wasm binary and its loader.
507
+ * @param options The options for TextToSpeech. Note that either a path to the
508
+ * model or the model buffer itself must be provided via `baseOptions`.
509
+ */
510
+ static createFromOptions(wasmFileset: WasmFileset, options: TextToSpeechOptions): Promise<TextToSpeech>;
511
+ /**
512
+ * Initializes the Wasm runtime and creates a new `TextToSpeech` instance
513
+ * from a model asset path.
514
+ *
515
+ * @export
516
+ * @param wasmFileset A configuration object that provides the location of
517
+ * the Wasm binary and its loader.
518
+ * @param modelAssetPath The path or URL to the `.litertlm` model asset.
519
+ */
520
+ static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string | string): Promise<TextToSpeech>;
521
+ /**
522
+ * Initializes the Wasm runtime and creates a new `TextToSpeech` instance
523
+ * from a model asset buffer or stream.
524
+ *
525
+ * @export
526
+ * @param wasmFileset A configuration object that provides the location of
527
+ * the Wasm binary and its loader.
528
+ * @param modelAssetBuffer A `Uint8Array` or `ReadableStreamDefaultReader`
529
+ * containing the `.litertlm` model bytes.
530
+ */
531
+ static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader): Promise<TextToSpeech>;
532
+ private constructor();
533
+ /**
534
+ * Sets the options for `TextToSpeech` and initializes the underlying engine.
535
+ * Options cannot be updated once the engine has been created.
536
+ *
537
+ * @export
538
+ * @param options The options for TextToSpeech.
539
+ */
540
+ setOptions(options: TextToSpeechOptions): Promise<void>;
541
+ /**
542
+ * Queries available voices bundled in the initialized model.
543
+ *
544
+ * @export
545
+ */
546
+ listVoices(): Promise<VoiceInfo[]>;
547
+ /**
548
+ * Synthesizes a complete utterance and returns the full PCM audio buffer.
549
+ *
550
+ * @export
551
+ * @param text The text to synthesize.
552
+ * @param options Optional per-utterance voice or locale overrides.
553
+ */
554
+ synthesize(text: string, options?: SynthesisOptions): Promise<TextToSpeechResult>;
555
+ /**
556
+ * Starts a streaming synthesis session returning a `TextToSpeechStream`
557
+ * (supporting both `readNext()` and `for await (const chunk of stream)`).
558
+ *
559
+ * @export
560
+ * @param initialText Initial text to synthesize (pass `""` when streaming
561
+ * incremental LLM text deltas via `stream.pushText()`).
562
+ * @param options Optional per-utterance voice or locale overrides.
563
+ * @param finishInput Pass `true` (default) for single-utterance streaming, or
564
+ * `false` to keep the input stream open for `stream.pushText()` and
565
+ * `stream.finishInput()`.
566
+ */
567
+ synthesizeStream(initialText?: string, options?: SynthesisOptions, finishInput?: boolean): Promise<TextToSpeechStream>;
568
+ /**
569
+ * Cancels any in-flight unary or streaming synthesis on this `TextToSpeech`
570
+ * instance.
571
+ *
572
+ * @export
573
+ */
574
+ cancel(): void;
575
+ /**
576
+ * Closes the `TextToSpeech` instance and releases native engine and Wasm
577
+ * memory.
578
+ *
579
+ * @export
580
+ */
581
+ close(): void;
582
+ }
583
+
584
+ /**
585
+ * A single streaming PCM audio chunk emitted by `TextToSpeechStream`.
586
+ */
587
+ export declare interface TextToSpeechAudioChunk {
588
+ /** Synthesized 32-bit mono float PCM audio samples in `[-1.0, 1.0]`. */
589
+ samples: Float32Array;
590
+ /** Audio sample rate in Hz (e.g. 24000). */
591
+ sampleRateHz: number;
592
+ /** 0-based index of this chunk within the streaming session. */
593
+ chunkIndex: number;
594
+ /** Whether this is the final chunk in the stream. */
595
+ isFinal: boolean;
596
+ }
597
+
598
+ /**
599
+ * Options to configure the MediaPipe TextToSpeech Task on the Web.
600
+ */
601
+ export declare interface TextToSpeechOptions extends TaskRunnerOptions {
602
+ /**
603
+ * Optional default voice ID (e.g. "af_heart"). When unset, the engine's
604
+ * default voice is used.
605
+ */
606
+ defaultVoiceId?: string;
607
+ /**
608
+ * Optional default BCP-47 locale (e.g. "en-US"). When unset, inferred from
609
+ * the selected voice metadata.
610
+ */
611
+ defaultLocale?: string;
612
+ /**
613
+ * Speaking rate multiplier in `(0.0, 4.0]`. Defaults to `1.0` (normal speed).
614
+ */
615
+ speakingRate?: number;
616
+ /**
617
+ * Target sequence length bucket for static-shape Kokoro models (`0` = auto).
618
+ */
619
+ targetBucket?: number;
620
+ /**
621
+ * Optional directory path in the Wasm virtual filesystem for caching unpacked
622
+ * `.litertlm` assets and compiled weights.
623
+ */
624
+ cacheDirectory?: string;
625
+ /**
626
+ * Optional byte length of `baseOptions.modelAssetBuffer` when provided as a
627
+ * `ReadableStreamDefaultReader`, enabling single-pass zero-copy streaming
628
+ * allocation directly in the Wasm heap.
629
+ */
630
+ modelAssetSize?: number;
631
+ }
632
+
633
+ /**
634
+ * Result of a unary `TextToSpeech.synthesize()` invocation.
635
+ */
636
+ export declare interface TextToSpeechResult {
637
+ /** Synthesized 32-bit mono float PCM audio samples in `[-1.0, 1.0]`. */
638
+ samples: Float32Array;
639
+ /** Audio sample rate in Hz (e.g. 24000). */
640
+ sampleRateHz: number;
641
+ }
642
+
643
+ /**
644
+ * Active streaming synthesis session returned by
645
+ * `TextToSpeech.synthesizeStream()`. Supports both pull-based `readNext()`
646
+ * and `for await (const chunk of stream)` iteration, as well as incremental
647
+ * text input via `pushText()` and `finishInput()`.
648
+ */
649
+ export declare class TextToSpeechStream implements AsyncIterable<TextToSpeechAudioChunk> {
650
+ private constructor();
651
+ /**
652
+ * Pulls the next synthesized PCM audio chunk, or returns `null` when the
653
+ * stream reaches end-of-stream.
654
+ *
655
+ * @export
656
+ */
657
+ readNext(): Promise<TextToSpeechAudioChunk | null>;
658
+ /**
659
+ * Appends an incremental text fragment (e.g. from an LLM token stream) to an
660
+ * open stream created with `finishInput = false`.
661
+ *
662
+ * @export
663
+ * @param textDelta The incremental text delta to append.
664
+ */
665
+ pushText(textDelta: string): Promise<void>;
666
+ /**
667
+ * Marks the end of incremental text input on this stream, flushing any
668
+ * remaining partial sentence into the synthesis pipeline.
669
+ *
670
+ * @export
671
+ */
672
+ finishInput(): Promise<void>;
673
+ /**
674
+ * Cancels this streaming synthesis session immediately.
675
+ *
676
+ * @export
677
+ */
678
+ cancel(): void;
679
+ /**
680
+ * Releases native stream resources.
681
+ *
682
+ * @export
683
+ */
684
+ close(): void;
685
+ [Symbol.asyncIterator](): AsyncIterator<TextToSpeechAudioChunk>;
686
+ }
687
+
688
+ /**
689
+ * Copyright 2026 The MediaPipe Authors.
690
+ *
691
+ * Licensed under the Apache License, Version 2.0 (the "License");
692
+ * you may not use this file except in compliance with the License.
693
+ * You may obtain a copy of the License at
694
+ *
695
+ * http://www.apache.org/licenses/LICENSE-2.0
696
+ *
697
+ * Unless required by applicable law or agreed to in writing, software
698
+ * distributed under the License is distributed on an "AS IS" BASIS,
699
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
700
+ * See the License for the specific language governing permissions and
701
+ * limitations under the License.
702
+ */
703
+ /**
704
+ * A single transcribed segment emitted by AudioTranscriber.
705
+ */
706
+ export declare interface TranscriptionSegment {
707
+ /** The transcribed text for this segment. */
708
+ transcript: string;
709
+ /** Whether this segment is finalized (as opposed to an interim hypothesis). */
710
+ isFinal: boolean;
711
+ /** Start timestamp of the segment in milliseconds. */
712
+ fromTimestampMs: number;
713
+ /** End timestamp of the segment in milliseconds. */
714
+ toTimestampMs: number;
715
+ }
716
+
717
+ /**
718
+ * Copyright 2026 The MediaPipe Authors.
719
+ *
720
+ * Licensed under the Apache License, Version 2.0 (the "License");
721
+ * you may not use this file except in compliance with the License.
722
+ * You may obtain a copy of the License at
723
+ *
724
+ * http://www.apache.org/licenses/LICENSE-2.0
725
+ *
726
+ * Unless required by applicable law or agreed to in writing, software
727
+ * distributed under the License is distributed on an "AS IS" BASIS,
728
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
729
+ * See the License for the specific language governing permissions and
730
+ * limitations under the License.
731
+ */
732
+ /**
733
+ * Voice metadata descriptor returned by `TextToSpeech.listVoices()`.
734
+ */
735
+ export declare interface VoiceInfo {
736
+ /** Unique voice identifier (e.g. "af_heart", "bf_emma", "jf_alpha"). */
737
+ voiceId: string;
738
+ /** Human-readable display name for the voice. */
739
+ displayName: string;
740
+ /** BCP-47 locale tag for the voice (e.g. "en-US", "en-GB", "ja-JP"). */
741
+ locale: string;
742
+ /** Output PCM audio sample rate in Hz (e.g. 24000). */
743
+ sampleRateHz: number;
744
+ /** Whether the voice embedding is bundled and ready for offline use. */
745
+ isDownloaded: boolean;
746
+ }
747
+
347
748
  /**
348
749
  * Copyright 2022 The MediaPipe Authors.
349
750
  *