ChromeTts class
class ChromeTts extends ChromeApi { static final JsObject _tts = chrome['tts']; ChromeTts._(); bool get available => _tts != null; /** * Speaks text using a text-to-speech engine. * * [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. * * [options] The speech options. */ Future speak(String utterance, [TtsSpeakParams options]) { if (_tts == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _tts.callMethod('speak', [utterance, jsify(options), completer.callback]); return completer.future; } /** * 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. */ void stop() { if (_tts == null) _throwNotAvailable(); _tts.callMethod('stop'); } /** * Pauses speech synthesis, potentially in the middle of an utterance. A call * to resume or stop will un-pause speech. */ void pause() { if (_tts == null) _throwNotAvailable(); _tts.callMethod('pause'); } /** * If speech was paused, resumes speaking where it left off. */ void resume() { if (_tts == null) _throwNotAvailable(); _tts.callMethod('resume'); } /** * 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. * * Returns: * True if speaking, false otherwise. */ Future<bool> isSpeaking() { if (_tts == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _tts.callMethod('isSpeaking', [completer.callback]); return completer.future; } /** * Gets an array of all available voices. * * Returns: * Array of [TtsVoice] objects representing the available voices for speech * synthesis. */ Future<List<TtsVoice>> getVoices() { if (_tts == null) _throwNotAvailable(); var completer = new ChromeCompleter<List<TtsVoice>>.oneArg((e) => listify(e, _createTtsVoice)); _tts.callMethod('getVoices', [completer.callback]); return completer.future; } /** * Used to pass events back to the function calling speak(). */ Stream<TtsEvent> get onEvent => _onEvent.stream; final ChromeStreamController<TtsEvent> _onEvent = new ChromeStreamController<TtsEvent>.oneArg(_tts, 'onEvent', _createTtsEvent); void _throwNotAvailable() { throw new UnsupportedError("'chrome.tts' is not available"); } }
Extends
ChromeApi > ChromeTts
Properties
final bool available #
Returns true if the API is available. The common causes of an API not being avilable are:
- a permission is missing in the application's manifest.json file
- the API is defined on a newer version of Chrome then the current runtime
bool get available => _tts != null;
Methods
Future<List<TtsVoice>> getVoices() #
Gets an array of all available voices.
Returns: Array of TtsVoice objects representing the available voices for speech synthesis.
Future<List<TtsVoice>> getVoices() { if (_tts == null) _throwNotAvailable(); var completer = new ChromeCompleter<List<TtsVoice>>.oneArg((e) => listify(e, _createTtsVoice)); _tts.callMethod('getVoices', [completer.callback]); return completer.future; }
Future<bool> isSpeaking() #
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.
Returns: True if speaking, false otherwise.
Future<bool> isSpeaking() { if (_tts == null) _throwNotAvailable(); var completer = new ChromeCompleter<bool>.oneArg(); _tts.callMethod('isSpeaking', [completer.callback]); return completer.future; }
void pause() #
Pauses speech synthesis, potentially in the middle of an utterance. A call to resume or stop will un-pause speech.
void pause() { if (_tts == null) _throwNotAvailable(); _tts.callMethod('pause'); }
void resume() #
If speech was paused, resumes speaking where it left off.
void resume() { if (_tts == null) _throwNotAvailable(); _tts.callMethod('resume'); }
Future speak(String utterance, [TtsSpeakParams options]) #
Speaks text using a text-to-speech engine.
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.
options The speech options.
Future speak(String utterance, [TtsSpeakParams options]) { if (_tts == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _tts.callMethod('speak', [utterance, jsify(options), completer.callback]); return completer.future; }
void stop() #
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.
void stop() { if (_tts == null) _throwNotAvailable(); _tts.callMethod('stop'); }