You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Use the `chrome.tts` API to play synthesized text-to-speech (TTS). See also the related ttsEngine API, which allows an extension to implement a speech engine.
12370
+
* Use the `chrome.tts` API to play synthesized text-to-speech (TTS). See also the related {@link ttsEngine} API, which allows an extension to implement a speech engine.
12371
12371
*
12372
12372
* Permissions: "tts"
12373
12373
*/
12374
12374
export namespace tts {
12375
+
/** @since Chrome 54 */
12376
+
export enum EventType {
12377
+
START = "start",
12378
+
END = "end",
12379
+
WORD = "word",
12380
+
SENTENCE = "sentence",
12381
+
MARKER = "marker",
12382
+
INTERRUPTED = "interrupted",
12383
+
CANCELLED = "cancelled",
12384
+
ERROR = "error",
12385
+
PAUSE = "pause",
12386
+
RESUME = "resume",
12387
+
}
12388
+
12375
12389
/** An event from the TTS engine to communicate the status of an utterance. */
12376
12390
export interface TtsEvent {
12377
-
/** Optional. The index of the current character in the utterance. */
12378
-
charIndex?: number | undefined;
12379
-
/** Optional. The error description, if the event type is 'error'. */
12380
-
errorMessage?: string | undefined;
12391
+
/** The index of the current character in the utterance. For word events, the event fires at the end of one word and before the beginning of the next. The `charIndex` represents a point in the text at the beginning of the next word to be spoken. */
12392
+
charIndex?: number;
12393
+
/** The error description, if the event type is `error`. */
12394
+
errorMessage?: string;
12395
+
/**
12396
+
* The length of the next part of the utterance. For example, in a `word` event, this is the length of the word which will be spoken next. It will be set to -1 if not set by the speech engine.
12397
+
* @since Chrome 74
12398
+
*/
12399
+
length?: number;
12400
+
/** The type can be `start` as soon as speech has started, `word` when a word boundary is reached, `sentence` when a sentence boundary is reached, `marker` when an SSML mark element is reached, `end` when the end of the utterance is reached, `interrupted` when the utterance is stopped or interrupted before reaching the end, `cancelled` when it's removed from the queue before ever being synthesized, or `error` when any other error occurs. When pausing speech, a `pause` event is fired if a particular utterance is paused in the middle, and `resume` if an utterance resumes speech. Note that pause and resume events may not fire if speech is paused in-between utterances. */
12401
+
type: `${EventType}`;
12402
+
}
12403
+
12404
+
/**
12405
+
* The speech options for the TTS engine.
12406
+
* @since Chrome 77
12407
+
*/
12408
+
export interface TtsOptions {
12409
+
/** The TTS event types that you are interested in listening to. If missing, all event types may be sent. */
12410
+
desiredEventTypes?: string[];
12411
+
/** If true, enqueues this utterance if TTS is already in progress. If false (the default), interrupts any current speech and flushes the speech queue before speaking this new utterance. */
12412
+
enqueue?: boolean;
12413
+
/** The extension ID of the speech engine to use, if known. */
12414
+
extensionId?: string;
12381
12415
/**
12382
-
* The length of the next part of the utterance.
12383
-
* For example, in a word event, this is the length of the word which will be spoken next.
12384
-
* It will be set to -1 if not set by the speech engine.
12416
+
* Gender of voice for synthesized speech.
12417
+
* @deprecated since Chrome 77. Gender is deprecated and will be ignored.
12385
12418
*/
12386
-
length?: number | undefined;
12419
+
gender?: `${VoiceGender}`;
12420
+
/** The language to be used for synthesis, in the form _language_\-_region_. Examples: 'en', 'en-US', 'en-GB', 'zh-CN'. */
12421
+
lang?: string;
12422
+
/** Speaking pitch between 0 and 2 inclusive, with 0 being lowest and 2 being highest. 1.0 corresponds to a voice's default pitch. */
12423
+
pitch?: number;
12424
+
/** Speaking rate relative to the default rate for this voice. 1.0 is the default rate, normally around 180 to 220 words per minute. 2.0 is twice as fast, and 0.5 is half as fast. Values below 0.1 or above 10.0 are strictly disallowed, but many voices will constrain the minimum and maximum rates further—for example a particular voice may not actually speak faster than 3 times normal even if you specify a value larger than 3.0. */
12425
+
rate?: number;
12426
+
/** The TTS event types the voice must support. */
12427
+
requiredEventTypes?: string[];
12428
+
/** The name of the voice to use for synthesis. If empty, uses any available voice. */
12429
+
voiceName?: string;
12430
+
/** Speaking volume between 0 and 1 inclusive, with 0 being lowest and 1 being highest, with a default of 1.0. */
12431
+
volume?: number;
12387
12432
/**
12388
-
* The type can be 'start' as soon as speech has started, 'word' when a word boundary is reached, 'sentence' when a sentence boundary is reached, 'marker' when an SSML mark element is reached, 'end' when the end of the utterance is reached, 'interrupted' when the utterance is stopped or interrupted before reaching the end, 'cancelled' when it's removed from the queue before ever being synthesized, or 'error' when any other error occurs. When pausing speech, a 'pause' event is fired if a particular utterance is paused in the middle, and 'resume' if an utterance resumes speech. Note that pause and resume events may not fire if speech is paused in-between utterances.
12389
-
* One of: "start", "end", "word", "sentence", "marker", "interrupted", "cancelled", "error", "pause", or "resume"
12433
+
* This function is called with events that occur in the process of speaking the utterance.
12434
+
* @param event The update event from the text-to-speech engine indicating the status of this utterance.
12390
12435
*/
12391
-
type:
12392
-
| "start"
12393
-
| "end"
12394
-
| "word"
12395
-
| "sentence"
12396
-
| "marker"
12397
-
| "interrupted"
12398
-
| "cancelled"
12399
-
| "error"
12400
-
| "pause"
12401
-
| "resume";
12436
+
onEvent?: (
12437
+
event: TtsEvent,
12438
+
) => void;
12402
12439
}
12403
12440
12404
12441
/** A description of a voice available for speech synthesis. */
12405
12442
export interface TtsVoice {
12406
-
/** Optional. The language that this voice supports, in the form language-region. Examples: 'en', 'en-US', 'en-GB', 'zh-CN'. */
12407
-
lang?: string | undefined;
12443
+
/** All of the callback event types that this voice is capable of sending. */
12444
+
eventTypes?: `${EventType}`[];
12445
+
/** The ID of the extension providing this voice. */
12446
+
extensionId?: string;
12408
12447
/**
12409
-
* Optional. This voice's gender.
12410
-
* One of: "male", or "female"
12448
+
* This voice's gender.
12411
12449
* @deprecated since Chrome 70. Gender is deprecated and will be ignored.
12412
12450
*/
12413
-
gender?: string | undefined;
12414
-
/** Optional. The name of the voice. */
12415
-
voiceName?: string | undefined;
12416
-
/** Optional. The ID of the extension providing this voice. */
12417
-
extensionId?: string | undefined;
12418
-
/** Optional. All of the callback event types that this voice is capable of sending. */
12419
-
eventTypes?: string[] | undefined;
12420
-
/**
12421
-
* Optional. If true, the synthesis engine is a remote network resource. It may be higher latency and may incur bandwidth costs.
12422
-
* @since Chrome 33
12423
-
*/
12424
-
remote?: boolean | undefined;
12451
+
gender?: `${VoiceGender}`;
12452
+
/** The language that this voice supports, in the form language-region. Examples: 'en', 'en-US', 'en-GB', 'zh-CN'. */
12453
+
lang?: string;
12454
+
/** If true, the synthesis engine is a remote network resource. It may be higher latency and may incur bandwidth costs. */
12455
+
remote?: boolean;
12456
+
/** The name of the voice. */
12457
+
voiceName?: string;
12425
12458
}
12426
12459
12427
-
export interface SpeakOptions {
12428
-
/** Optional. Speaking volume between 0 and 1 inclusive, with 0 being lowest and 1 being highest, with a default of 1.0. */
12429
-
volume?: number | undefined;
12430
-
/**
12431
-
* Optional.
12432
-
* If true, enqueues this utterance if TTS is already in progress. If false (the default), interrupts any current speech and flushes the speech queue before speaking this new utterance.
12433
-
*/
12434
-
enqueue?: boolean | undefined;
12435
-
/**
12436
-
* Optional.
12437
-
* Speaking rate relative to the default rate for this voice. 1.0 is the default rate, normally around 180 to 220 words per minute. 2.0 is twice as fast, and 0.5 is half as fast. Values below 0.1 or above 10.0 are strictly disallowed, but many voices will constrain the minimum and maximum rates further—for example a particular voice may not actually speak faster than 3 times normal even if you specify a value larger than 3.0.
12438
-
*/
12439
-
rate?: number | undefined;
12440
-
/**
12441
-
* Optional. This function is called with events that occur in the process of speaking the utterance.
12442
-
* @param event The update event from the text-to-speech engine indicating the status of this utterance.
* Speaking pitch between 0 and 2 inclusive, with 0 being lowest and 2 being highest. 1.0 corresponds to a voice's default pitch.
12448
-
*/
12449
-
pitch?: number | undefined;
12450
-
/** Optional. The language to be used for synthesis, in the form language-region. Examples: 'en', 'en-US', 'en-GB', 'zh-CN'. */
12451
-
lang?: string | undefined;
12452
-
/** Optional. The name of the voice to use for synthesis. If empty, uses any available voice. */
12453
-
voiceName?: string | undefined;
12454
-
/** Optional. The extension ID of the speech engine to use, if known. */
12455
-
extensionId?: string | undefined;
12456
-
/**
12457
-
* Optional. Gender of voice for synthesized speech.
12458
-
* One of: "male", or "female"
12459
-
*/
12460
-
gender?: string | undefined;
12461
-
/** Optional. The TTS event types the voice must support. */
12462
-
requiredEventTypes?: string[] | undefined;
12463
-
/** Optional. The TTS event types that you are interested in listening to. If missing, all event types may be sent. */
12464
-
desiredEventTypes?: string[] | undefined;
12460
+
/** @deprecated since Chrome 70. Gender is deprecated and is ignored.*/
12461
+
export enum VoiceGender {
12462
+
FEMALE = "female",
12463
+
MALE = "male",
12465
12464
}
12466
12465
12467
-
/** Checks whether the engine is currently speaking. On Mac OS X, the result is true whenever the system speech engine is speaking, even if the speech wasn't initiated by Chrome. */
12468
-
export function isSpeaking(callback?: (speaking: boolean) => void): void;
12469
-
/** Stops any current speech and flushes the queue of any pending utterances. In addition, if speech was paused, it will now be un-paused for the next call to speak. */
12470
-
export function stop(): void;
12471
-
/** Gets an array of all available voices. */
12466
+
/**
12467
+
* Gets an array of all available voices.
12468
+
*
12469
+
* Can return its result via Promise since Chrome Chrome 101
12470
+
*/
12472
12471
export function getVoices(): Promise<TtsVoice[]>;
12473
-
export function getVoices(callback?: (voices: TtsVoice[]) => void): void;
12472
+
export function getVoices(callback: (voices: TtsVoice[]) => void): void;
12473
+
12474
12474
/**
12475
-
* Speaks text using a text-to-speech engine.
12476
-
* @param utterance The text to speak, either plain text or a complete, well-formed SSML document. Speech engines that do not support SSML will strip away the tags and speak the text. The maximum length of the text is 32,768 characters.
12477
-
* @param callback Optional. Called right away, before speech finishes. Check chrome.runtime.lastError to make sure there were no errors. Use options.onEvent to get more detailed feedback.
12475
+
* Checks whether the engine is currently speaking. On Mac OS X, the result is true whenever the system speech engine is speaking, even if the speech wasn't initiated by Chrome.
12476
+
*
12477
+
* Can return its result via Promise since Chrome Chrome 101
12478
12478
*/
12479
-
export function speak(utterance: string, callback?: Function): void;
12479
+
export function isSpeaking(): Promise<boolean>;
12480
+
export function isSpeaking(callback: (speaking: boolean) => void): void;
12481
+
12482
+
/** Pauses speech synthesis, potentially in the middle of an utterance. A call to resume or stop will un-pause speech. */
12483
+
export function pause(): void;
12484
+
12485
+
/** If speech was paused, resumes speaking where it left off. */
12486
+
export function resume(): void;
12487
+
12480
12488
/**
12481
12489
* Speaks text using a text-to-speech engine.
12482
12490
* @param utterance The text to speak, either plain text or a complete, well-formed SSML document. Speech engines that do not support SSML will strip away the tags and speak the text. The maximum length of the text is 32,768 characters.
12483
12491
* @param options Optional. The speech options.
12484
-
* @param callback Optional. Called right away, before speech finishes. Check chrome.runtime.lastError to make sure there were no errors. Use options.onEvent to get more detailed feedback.
12485
-
*/
12486
-
export function speak(utterance: string, options: SpeakOptions, callback?: Function): void;
12487
-
/**
12488
-
* Pauses speech synthesis, potentially in the middle of an utterance. A call to resume or stop will un-pause speech.
12489
-
* @since Chrome 29
12492
+
12493
+
* Can return its result via Promise since Chrome Chrome 101
12490
12494
*/
12491
-
export function pause(): void;
12495
+
export function speak(utterance: string, options?: TtsOptions): Promise<void>;
12496
+
export function speak(utterance: string, callback: () => void): void;
/** Stops any current speech and flushes the queue of any pending utterances. In addition, if speech was paused, it will now be un-paused for the next call to speak. */
12500
+
export function stop(): void;
12501
+
12492
12502
/**
12493
-
* If speech was paused, resumes speaking where it left off.
12494
-
* @since Chrome 29
12503
+
* Called when the list of {@link TtsVoice} that would be returned by getVoices has changed.
0 commit comments