TextToSpeech
open class TextToSpeech
kotlin.Any | |
↳ | android.speech.tts.TextToSpeech |
Synthesizes speech from text for immediate playback or to create a sound file.
A TextToSpeech instance can only be used to synthesize text once it has completed its initialization. Implement the TextToSpeech.OnInitListener
to be notified of the completion of the initialization.
When you are done using the TextToSpeech instance, call the shutdown()
method to release the native resources used by the TextToSpeech engine. Apps targeting Android 11 that use text-to-speech should declare android.speech.tts.TextToSpeech.Engine#INTENT_ACTION_TTS_SERVICE
in the queries
elements of their manifest:
<queries> ... <intent> <action android:name="android.intent.action.TTS_SERVICE" /> </intent> </queries>
Summary
Nested classes | |
---|---|
open |
Constants and parameter names for controlling text-to-speech. |
open |
Information about an installed text-to-speech engine. |
abstract |
Interface definition of a callback to be invoked indicating the completion of the TextToSpeech engine initialization. |
abstract |
Listener that will be called when the TTS service has completed synthesizing an utterance. |
Constants | |
---|---|
static String |
Broadcast Action: The TextToSpeech synthesizer has completed processing of all the text in the speech queue. |
static Int |
Denotes a generic operation failure. |
static Int |
Denotes a failure caused by an invalid request. |
static Int |
Denotes a failure caused by a network connectivity problems. |
static Int |
Denotes a failure caused by network timeout. |
static Int |
Denotes a failure caused by an unfinished download of the voice data. |
static Int |
Denotes a failure related to the output (audio device or a file). |
static Int |
Denotes a failure of a TTS service. |
static Int |
Denotes a failure of a TTS engine to synthesize the given input. |
static Int |
Denotes the language is available for the language by the locale, but not the country and variant. |
static Int |
Denotes the language is available for the language and country specified by the locale, but not the variant. |
static Int |
Denotes the language is available exactly as specified by the locale. |
static Int |
Denotes the language data is missing. |
static Int |
Denotes the language is not supported. |
static Int |
Queue mode where the new entry is added at the end of the playback queue. |
static Int |
Queue mode where all entries in the playback queue (media to be played and text to be synthesized) are dropped and replaced by the new entry. |
static Int |
Denotes a stop requested by a client. |
static Int |
Denotes a successful operation. |
Public constructors | |
---|---|
TextToSpeech(context: Context!, listener: TextToSpeech.OnInitListener!) The constructor for the TextToSpeech class, using the default TTS engine. |
|
TextToSpeech(context: Context!, listener: TextToSpeech.OnInitListener!, engine: String!) The constructor for the TextToSpeech class, using the given TTS engine. |
Public methods | |
---|---|
open Int |
Adds a mapping between a string of text and a sound resource in a package. |
open Int |
Adds a mapping between a string of text and a sound file. |
open Int |
Adds a mapping between a string of text and a sound file. |
open Int |
Adds a mapping between a string of text and a sound file. |
open Int |
Adds a mapping between a string of text and a sound resource in a package. |
open Int |
addSpeech(text: CharSequence!, packagename: String!, resourceId: Int) Adds a mapping between a CharSequence (may be spanned with TtsSpans) of text and a sound resource in a package. |
open Int |
Adds a mapping between a string of text and a sound file. |
open Int |
addSpeech(text: CharSequence!, file: File!) Adds a mapping between a CharSequence (may be spanned with TtsSpans) and a sound file. |
open Int |
addSpeech(text: CharSequence, uri: Uri) Adds a mapping between a CharSequence (may be spanned with TtsSpans) and a sound file. |
open Boolean |
Checks whether the user's settings should override settings requested by the calling application. |
open MutableSet<Locale!>! |
Query the engine about the set of available languages. |
open String! |
Gets the package name of the default speech synthesis engine. |
open Locale! |
Returns a Locale instance describing the language currently being used as the default Text-to-speech language. |
open Voice! |
Returns a Voice instance that's the default voice for the default Text-to-speech language. |
open MutableList<TextToSpeech.EngineInfo!>! |
Gets a list of all installed TTS engines. |
open MutableSet<String!>! |
getFeatures(locale: Locale!) Queries the engine for the set of features it supports for a given locale. |
open Locale! |
Returns a Locale instance describing the language currently being used for synthesis requests sent to the TextToSpeech engine. |
open static Int |
Limit of length of input string passed to speak and synthesizeToFile. |
open Voice! |
getVoice() Returns a Voice instance describing the voice currently being used for synthesis requests sent to the TextToSpeech engine. |
open MutableSet<Voice!>! |
Query the engine about the set of available voices. |
open Int |
isLanguageAvailable(loc: Locale!) Checks if the specified language as represented by the Locale is available and supported. |
open Boolean |
Checks whether the TTS engine is busy speaking. |
open Int |
playEarcon(earcon: String!, queueMode: Int, params: Bundle!, utteranceId: String!) Plays the earcon using the specified queueing mode and parameters. |
open Int |
Plays the earcon using the specified queueing mode and parameters. |
open Int |
Plays silence for the specified amount of time using the specified queue mode. |
open Int |
playSilentUtterance(durationInMs: Long, queueMode: Int, utteranceId: String!) Plays silence for the specified amount of time using the specified queue mode. |
open Int |
setAudioAttributes(audioAttributes: AudioAttributes!) Sets the audio attributes to be used when speaking text or playing back a file. |
open Int |
setEngineByPackageName(enginePackageName: String!) Sets the TTS engine to use. |
open Int |
setLanguage(loc: Locale!) Sets the text-to-speech language. |
open Int |
Sets the listener that will be notified when synthesis of an utterance completes. |
open Int |
Sets the listener that will be notified of various events related to the synthesis of a given utterance. |
open Int |
Sets the speech pitch for the TextToSpeech engine. |
open Int |
setSpeechRate(speechRate: Float) Sets the speech rate. |
open Int |
Sets the text-to-speech voice. |
open Unit |
shutdown() Releases the resources used by the TextToSpeech engine. |
open Int |
speak(text: CharSequence!, queueMode: Int, params: Bundle!, utteranceId: String!) Speaks the text using the specified queuing strategy and speech parameters, the text may be spanned with TtsSpans. |
open Int |
Speaks the string using the specified queuing strategy and speech parameters. |
open Int |
stop() Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue. |
open Int |
synthesizeToFile(text: CharSequence, params: Bundle, fileDescriptor: ParcelFileDescriptor, utteranceId: String) Synthesizes the given text to a ParcelFileDescriptor using the specified parameters. |
open Int |
synthesizeToFile(text: CharSequence!, params: Bundle!, file: File!, utteranceId: String!) Synthesizes the given text to a file using the specified parameters. |
open Int |
Synthesizes the given text to a file using the specified parameters. |
Constants
ACTION_TTS_QUEUE_PROCESSING_COMPLETED
static val ACTION_TTS_QUEUE_PROCESSING_COMPLETED: String
Broadcast Action: The TextToSpeech synthesizer has completed processing of all the text in the speech queue. Note that this notifies callers when the engine has finished has processing text data. Audio playback might not have completed (or even started) at this point. If you wish to be notified when this happens, see OnUtteranceCompletedListener
.
Value: "android.speech.tts.TTS_QUEUE_PROCESSING_COMPLETED"
ERROR_INVALID_REQUEST
static val ERROR_INVALID_REQUEST: Int
Denotes a failure caused by an invalid request.
Value: -8
ERROR_NETWORK
static val ERROR_NETWORK: Int
Denotes a failure caused by a network connectivity problems.
Value: -6
ERROR_NETWORK_TIMEOUT
static val ERROR_NETWORK_TIMEOUT: Int
Denotes a failure caused by network timeout.
Value: -7
ERROR_NOT_INSTALLED_YET
static val ERROR_NOT_INSTALLED_YET: Int
Denotes a failure caused by an unfinished download of the voice data.
Value: -9
ERROR_OUTPUT
static val ERROR_OUTPUT: Int
Denotes a failure related to the output (audio device or a file).
Value: -5
ERROR_SERVICE
static val ERROR_SERVICE: Int
Denotes a failure of a TTS service.
Value: -4
ERROR_SYNTHESIS
static val ERROR_SYNTHESIS: Int
Denotes a failure of a TTS engine to synthesize the given input.
Value: -3
LANG_AVAILABLE
static val LANG_AVAILABLE: Int
Denotes the language is available for the language by the locale, but not the country and variant.
Value: 0
LANG_COUNTRY_AVAILABLE
static val LANG_COUNTRY_AVAILABLE: Int
Denotes the language is available for the language and country specified by the locale, but not the variant.
Value: 1
LANG_COUNTRY_VAR_AVAILABLE
static val LANG_COUNTRY_VAR_AVAILABLE: Int
Denotes the language is available exactly as specified by the locale.
Value: 2
LANG_MISSING_DATA
static val LANG_MISSING_DATA: Int
Denotes the language data is missing.
Value: -1
LANG_NOT_SUPPORTED
static val LANG_NOT_SUPPORTED: Int
Denotes the language is not supported.
Value: -2
QUEUE_ADD
static val QUEUE_ADD: Int
Queue mode where the new entry is added at the end of the playback queue.
Value: 1
QUEUE_FLUSH
static val QUEUE_FLUSH: Int
Queue mode where all entries in the playback queue (media to be played and text to be synthesized) are dropped and replaced by the new entry. Queues are flushed with respect to a given calling app. Entries in the queue from other callees are not discarded.
Value: 0
STOPPED
static val STOPPED: Int
Denotes a stop requested by a client. It's used only on the service side of the API, client should never expect to see this result code.
Value: -2
Public constructors
TextToSpeech
TextToSpeech(
context: Context!,
listener: TextToSpeech.OnInitListener!)
The constructor for the TextToSpeech class, using the default TTS engine. This will also initialize the associated TextToSpeech engine if it isn't already running.
Parameters | |
---|---|
context |
Context!: The context this instance is running in. |
listener |
TextToSpeech.OnInitListener!: The TextToSpeech.OnInitListener that will be called when the TextToSpeech engine has initialized. In a case of a failure the listener may be called immediately, before TextToSpeech instance is fully constructed. |
TextToSpeech
TextToSpeech(
context: Context!,
listener: TextToSpeech.OnInitListener!,
engine: String!)
The constructor for the TextToSpeech class, using the given TTS engine. This will also initialize the associated TextToSpeech engine if it isn't already running.
Parameters | |
---|---|
context |
Context!: The context this instance is running in. |
listener |
TextToSpeech.OnInitListener!: The TextToSpeech.OnInitListener that will be called when the TextToSpeech engine has initialized. In a case of a failure the listener may be called immediately, before TextToSpeech instance is fully constructed. |
engine |
String!: Package name of the TTS engine to use. |
Public methods
addEarcon
open fun addEarcon(
earcon: String!,
packagename: String!,
resourceId: Int
): Int
Adds a mapping between a string of text and a sound resource in a package. Use this to add custom earcons.
Parameters | |
---|---|
earcon |
String!: The name of the earcon. Example: "[tick]" |
packagename |
String!: the package name of the application that contains the resource. This can for instance be the package name of your own application. Example: "com.google.marvin.compass" The package name can be found in the AndroidManifest.xml of the application containing the resource. |
resourceId |
Int: Example: R.raw.tick_snd |
Return | |
---|---|
Int |
Code indicating success or failure. See ERROR and SUCCESS . |
See Also
addEarcon
open funaddEarcon(
earcon: String!,
filename: String!
): Int
Deprecated: As of API level 21, replaced by addEarcon(java.lang.String,java.io.File)
.
Adds a mapping between a string of text and a sound file. Use this to add custom earcons.
Parameters | |
---|---|
earcon |
String!: The name of the earcon. Example: "[tick]" |
filename |
String!: The full path to the sound file (for example: "/sdcard/mysounds/tick.wav") |
Return | |
---|---|
Int |
Code indicating success or failure. See ERROR and SUCCESS . |
See Also
addEarcon
open fun addEarcon(
earcon: String!,
file: File!
): Int
Adds a mapping between a string of text and a sound file. Use this to add custom earcons.
Parameters | |
---|---|
earcon |
String!: The name of the earcon. Example: "[tick]" |
file |
File!: File object pointing to the sound file. |
Return | |
---|---|
Int |
Code indicating success or failure. See ERROR and SUCCESS . |
See Also
addEarcon
open fun addEarcon(
earcon: String,
uri: Uri
): Int
Adds a mapping between a string of text and a sound file. Use this to add custom earcons.
Parameters | |
---|---|
earcon |
String: The name of the earcon. Example: "[tick]" This value cannot be null . |
uri |
Uri: Uri object pointing to the sound file. This value cannot be null . |
Return | |
---|---|
Int |
Code indicating success or failure. See ERROR and SUCCESS . |
See Also
addSpeech
open fun addSpeech(
text: String!,
packagename: String!,
resourceId: Int
): Int
Adds a mapping between a string of text and a sound resource in a package. After a call to this method, subsequent calls to speak(java.lang.CharSequence,int,android.os.Bundle,java.lang.String)
will play the specified sound resource if it is available, or synthesize the text it is missing.
Parameters | |
---|---|
text |
String!: The string of text. Example: "south_south_east" |
packagename |
String!: Pass the packagename of the application that contains the resource. If the resource is in your own application (this is the most common case), then put the packagename of your application here. Example: "com.google.marvin.compass" The packagename can be found in the AndroidManifest.xml of your application. |
resourceId |
Int: Example: R.raw.south_south_east |
Return | |
---|---|
Int |
Code indicating success or failure. See ERROR and SUCCESS . |
addSpeech
open fun addSpeech(
text: CharSequence!,
packagename: String!,
resourceId: Int
): Int
Adds a mapping between a CharSequence (may be spanned with TtsSpans) of text and a sound resource in a package. After a call to this method, subsequent calls to speak(java.lang.CharSequence,int,android.os.Bundle,java.lang.String)
will play the specified sound resource if it is available, or synthesize the text it is missing.
Parameters | |
---|---|
text |
CharSequence!: The string of text. Example: "south_south_east" |
packagename |
String!: Pass the packagename of the application that contains the resource. If the resource is in your own application (this is the most common case), then put the packagename of your application here. Example: "com.google.marvin.compass" The packagename can be found in the AndroidManifest.xml of your application. |
resourceId |
Int: Example: R.raw.south_south_east |
Return | |
---|---|
Int |
Code indicating success or failure. See ERROR and SUCCESS . |
addSpeech
open fun addSpeech(
text: String!,
filename: String!
): Int
Adds a mapping between a string of text and a sound file. Using this, it is possible to add custom pronounciations for a string of text. After a call to this method, subsequent calls to speak(java.lang.CharSequence,int,android.os.Bundle,java.lang.String)
will play the specified sound resource if it is available, or synthesize the text it is missing.
Parameters | |
---|---|
text |
String!: The string of text. Example: "south_south_east" |
filename |
String!: The full path to the sound file (for example: "/sdcard/mysounds/hello.wav") |
Return | |
---|---|
Int |
Code indicating success or failure. See ERROR and SUCCESS . |
addSpeech
open fun addSpeech(
text: CharSequence!,
file: File!
): Int
Adds a mapping between a CharSequence (may be spanned with TtsSpans) and a sound file. Using this, it is possible to add custom pronounciations for a string of text. After a call to this method, subsequent calls to speak(java.lang.CharSequence,int,android.os.Bundle,java.lang.String)
will play the specified sound resource if it is available, or synthesize the text it is missing.
Parameters | |
---|---|
text |
CharSequence!: The string of text. Example: "south_south_east" |
file |
File!: File object pointing to the sound file. |
Return | |
---|---|
Int |
Code indicating success or failure. See ERROR and SUCCESS . |
addSpeech
open fun addSpeech(
text: CharSequence,
uri: Uri
): Int
Adds a mapping between a CharSequence (may be spanned with TtsSpans) and a sound file. Using this, it is possible to add custom pronounciations for a string of text. After a call to this method, subsequent calls to speak(java.lang.CharSequence,int,android.os.Bundle,java.lang.String)
will play the specified sound resource if it is available, or synthesize the text it is missing.
Parameters | |
---|---|
text |
CharSequence: The string of text. Example: "south_south_east" This value cannot be null . |
uri |
Uri: Uri object pointing to the sound file. This value cannot be null . |
Return | |
---|---|
Int |
Code indicating success or failure. See ERROR and SUCCESS . |
areDefaultsEnforced
open funareDefaultsEnforced(): Boolean
Deprecated: Deprecated in Java.
Checks whether the user's settings should override settings requested by the calling application. As of the Ice cream sandwich release, user settings never forcibly override the app's settings.
getAvailableLanguages
open fun getAvailableLanguages(): MutableSet<Locale!>!
Query the engine about the set of available languages.
getDefaultEngine
open fun getDefaultEngine(): String!
Gets the package name of the default speech synthesis engine.
Return | |
---|---|
String! |
Package name of the TTS engine that the user has chosen as their default. |
getDefaultLanguage
open fungetDefaultLanguage(): Locale!
Deprecated: As of API level 21, use getDefaultVoice().getLocale()
(getDefaultVoice()
)
Returns a Locale instance describing the language currently being used as the default Text-to-speech language. The locale object returned by this method is NOT a valid one. It has identical form to the one in getLanguage()
. Please refer to getLanguage()
for more information.
Return | |
---|---|
Locale! |
language, country (if any) and variant (if any) used by the client stored in a Locale instance, or null on error. |
getDefaultVoice
open fun getDefaultVoice(): Voice!
Returns a Voice instance that's the default voice for the default Text-to-speech language.
Return | |
---|---|
Voice! |
The default voice instance for the default language, or null if not set or on error. |
getEngines
open fun getEngines(): MutableList<TextToSpeech.EngineInfo!>!
Gets a list of all installed TTS engines.
Return | |
---|---|
MutableList<TextToSpeech.EngineInfo!>! |
A list of engine info objects. The list can be empty, but never null . |
getFeatures
open fungetFeatures(locale: Locale!): MutableSet<String!>!
Deprecated: As of API level 21, please use voices. In order to query features of the voice, call getVoices()
to retrieve the list of available voices and Voice#getFeatures()
to retrieve the set of features.
Queries the engine for the set of features it supports for a given locale. Features can either be framework defined, e.g. TextToSpeech.Engine#KEY_FEATURE_NETWORK_SYNTHESIS
or engine specific. Engine specific keys must be prefixed by the name of the engine they are intended for. These keys can be used as parameters to TextToSpeech#speak(String, int, java.util.HashMap)
and TextToSpeech#synthesizeToFile(String, java.util.HashMap, String)
. Features values are strings and their values must meet restrictions described in their documentation.
Parameters | |
---|---|
locale |
Locale!: The locale to query features for. |
Return | |
---|---|
MutableSet<String!>! |
Set instance. May return null on error. |
getLanguage
open fungetLanguage(): Locale!
Deprecated: As of API level 21, please use getVoice().getLocale()
(getVoice()
).
Returns a Locale instance describing the language currently being used for synthesis requests sent to the TextToSpeech engine. In Android 4.2 and before (API <= 17) this function returns the language that is currently being used by the TTS engine. That is the last language set by this or any other client by a TextToSpeech#setLanguage
call to the same engine. In Android versions after 4.2 this function returns the language that is currently being used for the synthesis requests sent from this client. That is the last language set by a TextToSpeech#setLanguage
call on this instance. If a voice is set (by setVoice(android.speech.tts.Voice)
), getLanguage will return the language of the currently set voice. Please note that the Locale object returned by this method is NOT a valid Locale object. Its language field contains a three-letter ISO 639-2/T code (where a proper Locale would use a two-letter ISO 639-1 code), and the country field contains a three-letter ISO 3166 country code (where a proper Locale would use a two-letter ISO 3166-1 code).
Return | |
---|---|
Locale! |
language, country (if any) and variant (if any) used by the client stored in a Locale instance, or null on error. |
getMaxSpeechInputLength
open static fun getMaxSpeechInputLength(): Int
Limit of length of input string passed to speak and synthesizeToFile.
See Also
getVoice
open fun getVoice(): Voice!
Returns a Voice instance describing the voice currently being used for synthesis requests sent to the TextToSpeech engine.
Return | |
---|---|
Voice! |
Voice instance used by the client, or null if not set or on error. |
See Also
getVoices
open fun getVoices(): MutableSet<Voice!>!
Query the engine about the set of available voices. Each TTS Engine can expose multiple voices for each locale, each with a different set of features.
See Also
isLanguageAvailable
open fun isLanguageAvailable(loc: Locale!): Int
Checks if the specified language as represented by the Locale is available and supported.
Parameters | |
---|---|
loc |
Locale!: The Locale describing the language to be used. |
Return | |
---|---|
Int |
Code indicating the support status for the locale. See LANG_AVAILABLE , LANG_COUNTRY_AVAILABLE , LANG_COUNTRY_VAR_AVAILABLE , LANG_MISSING_DATA and LANG_NOT_SUPPORTED . |
isSpeaking
open fun isSpeaking(): Boolean
Checks whether the TTS engine is busy speaking. Note that a speech item is considered complete once it's audio data has been sent to the audio mixer, or written to a file. There might be a finite lag between this point, and when the audio hardware completes playback.
Return | |
---|---|
Boolean |
true if the TTS engine is speaking. |
playEarcon
open fun playEarcon(
earcon: String!,
queueMode: Int,
params: Bundle!,
utteranceId: String!
): Int
Plays the earcon using the specified queueing mode and parameters. The earcon must already have been added with addEarcon(java.lang.String,java.lang.String)
or addEarcon(java.lang.String,java.lang.String,int)
. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener
) and using the Engine#KEY_PARAM_UTTERANCE_ID
parameter.
Parameters | |
---|---|
earcon |
String!: The earcon that should be played |
queueMode |
Int: QUEUE_ADD or QUEUE_FLUSH . |
params |
Bundle!: Parameters for the request. Can be null. Supported parameter names: Engine#KEY_PARAM_STREAM , Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used. |
Return | |
---|---|
Int |
ERROR or SUCCESS of queuing the playEarcon operation. |
playEarcon
open funplayEarcon(
earcon: String!,
queueMode: Int,
params: HashMap<String!, String!>!
): Int
Deprecated: As of API level 21, replaced by playEarcon(java.lang.String,int,android.os.Bundle,java.lang.String)
.
Plays the earcon using the specified queueing mode and parameters. The earcon must already have been added with addEarcon(java.lang.String,java.lang.String)
or addEarcon(java.lang.String,java.lang.String,int)
. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener
) and using the Engine#KEY_PARAM_UTTERANCE_ID
parameter.
Parameters | |
---|---|
earcon |
String!: The earcon that should be played |
queueMode |
Int: QUEUE_ADD or QUEUE_FLUSH . |
params |
HashMap<String!, String!>!: Parameters for the request. Can be null. Supported parameter names: Engine#KEY_PARAM_STREAM , Engine#KEY_PARAM_UTTERANCE_ID . Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used. |
Return | |
---|---|
Int |
ERROR or SUCCESS of queuing the playEarcon operation. |
playSilence
open funplaySilence(
durationInMs: Long,
queueMode: Int,
params: HashMap<String!, String!>!
): Int
Deprecated: As of API level 21, replaced by playSilentUtterance(long,int,java.lang.String)
.
Plays silence for the specified amount of time using the specified queue mode. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener
) and using the Engine#KEY_PARAM_UTTERANCE_ID
parameter.
Parameters | |
---|---|
durationInMs |
Long: The duration of the silence. |
queueMode |
Int: QUEUE_ADD or QUEUE_FLUSH . |
params |
HashMap<String!, String!>!: Parameters for the request. Can be null. Supported parameter names: Engine#KEY_PARAM_UTTERANCE_ID . Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used. |
Return | |
---|---|
Int |
ERROR or SUCCESS of queuing the playSilence operation. |
playSilentUtterance
open fun playSilentUtterance(
durationInMs: Long,
queueMode: Int,
utteranceId: String!
): Int
Plays silence for the specified amount of time using the specified queue mode. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener
) and using the Engine#KEY_PARAM_UTTERANCE_ID
parameter.
Parameters | |
---|---|
durationInMs |
Long: The duration of the silence. |
queueMode |
Int: QUEUE_ADD or QUEUE_FLUSH . |
utteranceId |
String!: An unique identifier for this request. |
Return | |
---|---|
Int |
ERROR or SUCCESS of queuing the playSilentUtterance operation. |
setAudioAttributes
open fun setAudioAttributes(audioAttributes: AudioAttributes!): Int
Sets the audio attributes to be used when speaking text or playing back a file.
Parameters | |
---|---|
audioAttributes |
AudioAttributes!: Valid AudioAttributes instance. |
Return | |
---|---|
Int |
ERROR or SUCCESS . |
setEngineByPackageName
open funsetEngineByPackageName(enginePackageName: String!): Int
Deprecated: This doesn't inform callers when the TTS engine has been initialized. TextToSpeech(android.content.Context,android.speech.tts.TextToSpeech.OnInitListener,java.lang.String)
can be used with the appropriate engine name. Also, there is no guarantee that the engine specified will be loaded. If it isn't installed or disabled, the user / system wide defaults will apply.
Sets the TTS engine to use.
Parameters | |
---|---|
enginePackageName |
String!: The package name for the synthesis engine (e.g. "com.svox.pico") |
Return | |
---|---|
Int |
ERROR or SUCCESS . |
setLanguage
open fun setLanguage(loc: Locale!): Int
Sets the text-to-speech language. The TTS engine will try to use the closest match to the specified language as represented by the Locale, but there is no guarantee that the exact same Locale will be used. Use isLanguageAvailable(java.util.Locale)
to check the level of support before choosing the language to use for the next utterances. This method sets the current voice to the default one for the given Locale; getVoice()
can be used to retrieve it.
Parameters | |
---|---|
loc |
Locale!: The locale describing the language to be used. |
Return | |
---|---|
Int |
Code indicating the support status for the locale. See LANG_AVAILABLE , LANG_COUNTRY_AVAILABLE , LANG_COUNTRY_VAR_AVAILABLE , LANG_MISSING_DATA and LANG_NOT_SUPPORTED . |
setOnUtteranceCompletedListener
open funsetOnUtteranceCompletedListener(listener: TextToSpeech.OnUtteranceCompletedListener!): Int
Deprecated: Use setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)
instead.
Sets the listener that will be notified when synthesis of an utterance completes.
Parameters | |
---|---|
listener |
TextToSpeech.OnUtteranceCompletedListener!: The listener to use. |
Return | |
---|---|
Int |
ERROR or SUCCESS . |
setOnUtteranceProgressListener
open fun setOnUtteranceProgressListener(listener: UtteranceProgressListener!): Int
Sets the listener that will be notified of various events related to the synthesis of a given utterance. See UtteranceProgressListener
and TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID
.
Parameters | |
---|---|
listener |
UtteranceProgressListener!: the listener to use. |
Return | |
---|---|
Int |
ERROR or SUCCESS |
setPitch
open fun setPitch(pitch: Float): Int
Sets the speech pitch for the TextToSpeech engine. This has no effect on any pre-recorded speech.
Parameters | |
---|---|
pitch |
Float: Speech pitch. 1.0 is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it. |
Return | |
---|---|
Int |
ERROR or SUCCESS . |
setSpeechRate
open fun setSpeechRate(speechRate: Float): Int
Sets the speech rate. This has no effect on any pre-recorded speech.
Parameters | |
---|---|
speechRate |
Float: Speech rate. 1.0 is the normal speech rate, lower values slow down the speech (0.5 is half the normal speech rate), greater values accelerate it (2.0 is twice the normal speech rate). |
Return | |
---|---|
Int |
ERROR or SUCCESS . |
setVoice
open fun setVoice(voice: Voice!): Int
Sets the text-to-speech voice.
Parameters | |
---|---|
voice |
Voice!: One of objects returned by getVoices() . |
Return | |
---|---|
Int |
ERROR or SUCCESS . |
See Also
shutdown
open fun shutdown(): Unit
Releases the resources used by the TextToSpeech engine. It is good practice for instance to call this method in the onDestroy() method of an Activity so the TextToSpeech engine can be cleanly stopped.
speak
open fun speak(
text: CharSequence!,
queueMode: Int,
params: Bundle!,
utteranceId: String!
): Int
Speaks the text using the specified queuing strategy and speech parameters, the text may be spanned with TtsSpans. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener
) and using the Engine#KEY_PARAM_UTTERANCE_ID
parameter.
Parameters | |
---|---|
text |
CharSequence!: The string of text to be spoken. No longer than getMaxSpeechInputLength() characters. |
queueMode |
Int: The queuing strategy to use, QUEUE_ADD or QUEUE_FLUSH . |
params |
Bundle!: Parameters for the request. Can be null. Supported parameter names: Engine#KEY_PARAM_STREAM , Engine#KEY_PARAM_VOLUME , Engine#KEY_PARAM_PAN . Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used. |
utteranceId |
String!: An unique identifier for this request. |
Return | |
---|---|
Int |
ERROR or SUCCESS of queuing the speak operation. |
speak
open funspeak(
text: String!,
queueMode: Int,
params: HashMap<String!, String!>!
): Int
Deprecated: As of API level 21, replaced by speak(java.lang.CharSequence,int,android.os.Bundle,java.lang.String)
.
Speaks the string using the specified queuing strategy and speech parameters. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener
) and using the Engine#KEY_PARAM_UTTERANCE_ID
parameter.
Parameters | |
---|---|
text |
String!: The string of text to be spoken. No longer than getMaxSpeechInputLength() characters. |
queueMode |
Int: The queuing strategy to use, QUEUE_ADD or QUEUE_FLUSH . |
params |
HashMap<String!, String!>!: Parameters for the request. Can be null. Supported parameter names: Engine#KEY_PARAM_STREAM , Engine#KEY_PARAM_UTTERANCE_ID , Engine#KEY_PARAM_VOLUME , Engine#KEY_PARAM_PAN . Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used. |
Return | |
---|---|
Int |
ERROR or SUCCESS of queuing the speak operation. |
stop
open fun stop(): Int
Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue.
Return | |
---|---|
Int |
ERROR or SUCCESS . |
synthesizeToFile
open fun synthesizeToFile(
text: CharSequence,
params: Bundle,
fileDescriptor: ParcelFileDescriptor,
utteranceId: String
): Int
Synthesizes the given text to a ParcelFileDescriptor using the specified parameters. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener
).
Parameters | |
---|---|
text |
CharSequence: The text that should be synthesized. No longer than getMaxSpeechInputLength() characters. This value cannot be null . |
params |
Bundle: Parameters for the request. Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used. This value cannot be null . |
fileDescriptor |
ParcelFileDescriptor: ParcelFileDescriptor to write the generated audio data to. This value cannot be null . |
utteranceId |
String: An unique identifier for this request. This value cannot be null . |
Return | |
---|---|
Int |
ERROR or SUCCESS of queuing the synthesizeToFile operation. |
synthesizeToFile
open fun synthesizeToFile(
text: CharSequence!,
params: Bundle!,
file: File!,
utteranceId: String!
): Int
Synthesizes the given text to a file using the specified parameters. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener
).
Parameters | |
---|---|
text |
CharSequence!: The text that should be synthesized. No longer than getMaxSpeechInputLength() characters. |
params |
Bundle!: Parameters for the request. Cannot be null. Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used. |
file |
File!: File to write the generated audio data to. |
utteranceId |
String!: An unique identifier for this request. |
Return | |
---|---|
Int |
ERROR or SUCCESS of queuing the synthesizeToFile operation. |
synthesizeToFile
open funsynthesizeToFile(
text: String!,
params: HashMap<String!, String!>!,
filename: String!
): Int
Deprecated: As of API level 21, replaced by synthesizeToFile(java.lang.CharSequence,android.os.Bundle,java.io.File,java.lang.String)
.
Synthesizes the given text to a file using the specified parameters. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener
) and using the Engine#KEY_PARAM_UTTERANCE_ID
parameter.
Parameters | |
---|---|
text |
String!: The text that should be synthesized. No longer than getMaxSpeechInputLength() characters. |
params |
HashMap<String!, String!>!: Parameters for the request. Cannot be null. Supported parameter names: Engine#KEY_PARAM_UTTERANCE_ID . Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used. |
filename |
String!: Absolute file filename to write the generated audio data to.It should be something like "/sdcard/myappsounds/mysound.wav". |
Return | |
---|---|
Int |
ERROR or SUCCESS of queuing the synthesizeToFile operation. |