Read a Text File With Speech in Android Studio
                                                                                    
TextToSpeech
                                                  public            class   TextToSpeech                                                
                                                  extends Object                                                                                              
Synthesizes oral communication from text for firsthand playback or to create a sound file.
A TextToSpeech case can only be used to synthesize text once it has completed its  initialization. Implement the                        TextToSpeech.OnInitListener                        to exist  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 apply text-to-speech should declare                        TextToSpeech.Engine.INTENT_ACTION_TTS_SERVICE                        in the                        queries                        elements of their  manifest:                      
<queries> ... <intent> <activeness android:name="android.intent.action.TTS_SERVICE" /> </intent> </queries>
Summary
| Nested classes | |
|---|---|
|                                 grade | TextToSpeech.EngineConstants and parameter names for controlling text-to-voice communication. | 
|                                 class | TextToSpeech.EngineInfoData near an installed text-to-voice communication engine. | 
|                                 interface | TextToSpeech.OnInitListenerInterface definition of a callback to be invoked indicating the completion of the TextToSpeech engine initialization. | 
|                                 interface | TextToSpeech.OnUtteranceCompletedListener                                                                  This interface was deprecated       in API level 18.     Apply                                   | 
| Constants | |
|---|---|
| String | ACTION_TTS_QUEUE_PROCESSING_COMPLETEDCirculate Action: The TextToSpeech synthesizer has completed processing of all the text in the speech queue. | 
| int | ERRORDenotes a generic operation failure. | 
| int | ERROR_INVALID_REQUESTDenotes a failure acquired past an invalid asking. | 
| int | ERROR_NETWORKDenotes a failure acquired past a network connectivity problems. | 
| int | ERROR_NETWORK_TIMEOUTDenotes a failure caused by network timeout. | 
| int | ERROR_NOT_INSTALLED_YETDenotes a failure acquired by an unfinished download of the voice data. | 
| int | ERROR_OUTPUTDenotes a failure related to the output (sound device or a file). | 
| int | ERROR_SERVICEDenotes a failure of a TTS service. | 
| int | ERROR_SYNTHESISDenotes a failure of a TTS engine to synthesize the given input. | 
| int | LANG_AVAILABLEDenotes the linguistic communication is available for the language past the locale, just not the state and variant. | 
| int | LANG_COUNTRY_AVAILABLEDenotes the linguistic communication is available for the language and state specified by the locale, but not the variant. | 
| int | LANG_COUNTRY_VAR_AVAILABLEDenotes the linguistic communication is bachelor exactly equally specified by the locale. | 
| int | LANG_MISSING_DATADenotes the language data is missing. | 
| int | LANG_NOT_SUPPORTEDDenotes the language is not supported. | 
| int | QUEUE_ADDQueue fashion where the new entry is added at the cease of the playback queue. | 
| int | QUEUE_FLUSHQueue style where all entries in the playback queue (media to be played and text to be synthesized) are dropped and replaced by the new entry. | 
| int | STOPPEDDenotes a finish requested past a client. | 
| int | SUCCESSDenotes a successful performance. | 
| Public constructors | |
|---|---|
|                                 TextToSpeech(Context context, TextToSpeech.OnInitListener listener)                              The constructor for the TextToSpeech class, using the default TTS engine. | |
|                                 TextToSpeech(Context context, TextToSpeech.OnInitListener listener, String engine)                              The constructor for the TextToSpeech class, using the given TTS engine. | |
| Public methods | |
|---|---|
|                                 int |                                 addEarcon(String earcon, String packagename, int resourceId)                              Adds a mapping between a string of text and a audio resource in a package. | 
|                                 int |                                 addEarcon(Cord earcon, String filename)                                                                                                This method was deprecated       in API level 21.     As of API level 21, replaced by                                   | 
|                                 int |                                 addEarcon(String earcon, File file)                              Adds a mapping between a string of text and a sound file. | 
|                                 int |                                 addEarcon(String earcon, Uri uri)                              Adds a mapping between a string of text and a sound file. | 
|                                 int |                                 addSpeech(CharSequence text, File file)                              Adds a mapping between a CharSequence (may be spanned with TtsSpans) and a sound file. | 
|                                 int |                                 addSpeech(String text, Cord packagename, int resourceId)                              Adds a mapping between a string of text and a sound resource in a package. | 
|                                 int |                                 addSpeech(CharSequence text, String packagename, int resourceId)                              Adds a mapping between a CharSequence (may be spanned with TtsSpans) of text and a sound resource in a package. | 
|                                 int |                                 addSpeech(Cord text, String filename)                              Adds a mapping between a string of text and a sound file. | 
|                                 int |                                 addSpeech(CharSequence text, Uri uri)                              Adds a mapping between a CharSequence (may be spanned with TtsSpans) and a sound file. | 
|                                 boolean |                                 areDefaultsEnforced()                              Checks whether the user's settings should override settings requested by the calling application. | 
|                                 Set<Locale> |                                 getAvailableLanguages()                              Query the engine almost the prepare of available languages. | 
|                                 String |                                 getDefaultEngine()                              Gets the package proper noun of the default oral communication synthesis engine. | 
|                                 Locale |                                 getDefaultLanguage()                                                                                                This method was deprecated       in API level 21.     As of API level 21, utilise                                   | 
|                                 Voice |                                 getDefaultVoice()                              Returns a Voice instance that's the default voice for the default Text-to-speech language. | 
|                                 List<TextToSpeech.EngineInfo> |                                 getEngines()                              Gets a listing of all installed TTS engines. | 
|                                 Set<String> |                                 getFeatures(Locale locale)                                                                                                This method was deprecated       in API level 21.     Every bit of API level 21, please employ voices. In order to query features of the vox,  call                                   | 
|                                 Locale |                                 getLanguage()                                                                                                This method was deprecated       in API level 21.     As of API level 21, please use                                   | 
|                                 static                           int |                                 getMaxSpeechInputLength()                              Limit of length of input string passed to speak and synthesizeToFile. | 
|                                 Voice |                                 getVoice()                              Returns a Voice instance describing the vox currently beingness used for synthesis requests sent to the TextToSpeech engine. | 
|                                 Set<Voice> |                                 getVoices()                              Query the engine about the set up of available voices. | 
|                                 int |                                 isLanguageAvailable(Locale loc)                              Checks if the specified language equally represented past the Locale is available and supported. | 
|                                 boolean |                                 isSpeaking()                              Checks whether the TTS engine is busy speaking. | 
|                                 int |                                 playEarcon(String earcon, int queueMode, HashMap<String, String> params)                                                                                                This method was deprecated       in API level 21.     Equally of API level 21, replaced by                                   | 
|                                 int |                                 playEarcon(String earcon, int queueMode, Bundle params, Cord utteranceId)                              Plays the earcon using the specified queueing mode and parameters. | 
|                                 int |                                 playSilence(long durationInMs, int queueMode, HashMap<String, String> params)                                                                                                This method was deprecated       in API level 21.     As of API level 21, replaced past                                   | 
|                                 int |                                 playSilentUtterance(long durationInMs, int queueMode, String utteranceId)                              Plays silence for the specified amount of time using the specified queue way. | 
|                                 int |                                 setAudioAttributes(AudioAttributes audioAttributes)                              Sets the audio attributes to exist used when speaking text or playing back a file. | 
|                                 int |                                 setEngineByPackageName(Cord enginePackageName)                                                                                                This method was deprecated       in API level xv.     This doesn't inform callers when the TTS engine has been         initialized.                                   | 
|                                 int |                                 setLanguage(Locale loc)                              Sets the text-to-speech language. | 
|                                 int |                                 setOnUtteranceCompletedListener(TextToSpeech.OnUtteranceCompletedListener listener)                                                                                                This method was deprecated       in API level 15.     Use                                   | 
|                                 int |                                 setOnUtteranceProgressListener(UtteranceProgressListener listener)                              Sets the listener that will be notified of various events related to the synthesis of a given utterance. | 
|                                 int |                                 setPitch(float pitch)                              Sets the voice communication pitch for the TextToSpeech engine. | 
|                                 int |                                 setSpeechRate(float speechRate)                              Sets the speech communication rate. | 
|                                 int |                                 setVoice(Vocalisation voice)                              Sets the text-to-voice communication vocalisation. | 
|                                 void |                                 shutdown()                              Releases the resource used by the TextToSpeech engine. | 
|                                 int |                                 speak(CharSequence text, int queueMode, Bundle params, String utteranceId)                              Speaks the text using the specified queuing strategy and spoken language parameters, the text may be spanned with TtsSpans. | 
|                                 int |                                 speak(Cord text, int queueMode, HashMap<String, String> params)                                                                                                This method was deprecated       in API level 21.     As of API level 21, replaced by                                   | 
|                                 int |                                 stop()                              Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue. | 
|                                 int |                                 synthesizeToFile(CharSequence text, Bundle params, ParcelFileDescriptor fileDescriptor, Cord utteranceId)                              Synthesizes the given text to a ParcelFileDescriptor using the specified parameters. | 
|                                 int |                                 synthesizeToFile(CharSequence text, Bundle params, File file, String utteranceId)                              Synthesizes the given text to a file using the specified parameters. | 
|                                 int |                                 synthesizeToFile(String text, HashMap<Cord, Cord> params, String filename)                                                                                                This method was deprecated       in API level 21.     As of API level 21, replaced by                                   | 
| Inherited methods | |
|---|---|
Constants
ACTION_TTS_QUEUE_PROCESSING_COMPLETED
public static concluding Cord ACTION_TTS_QUEUE_PROCESSING_COMPLETED
Circulate 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 information. Audio playback might not have completed (or even started)  at this point. If you lot wish to be notified when this happens, encounter                          OnUtteranceCompletedListener.
Constant Value: "android.voice communication.tts.TTS_QUEUE_PROCESSING_COMPLETED"
ERROR
public static last int ERROR
Denotes a generic operation failure.
Abiding Value: -1 (0xffffffff)
ERROR_INVALID_REQUEST
public static terminal int ERROR_INVALID_REQUEST
Denotes a failure caused by an invalid asking.
Constant Value: -8 (0xfffffff8)
ERROR_NETWORK
public static last int ERROR_NETWORK
Denotes a failure acquired by a network connectivity bug.
Constant Value: -6 (0xfffffffa)
ERROR_NETWORK_TIMEOUT
public static final int ERROR_NETWORK_TIMEOUT
Denotes a failure caused by network timeout.
Constant Value: -seven (0xfffffff9)
ERROR_NOT_INSTALLED_YET
public static final int ERROR_NOT_INSTALLED_YET
Denotes a failure acquired by an unfinished download of the voice information.
Constant Value: -ix (0xfffffff7)
ERROR_OUTPUT
public static final int ERROR_OUTPUT
Denotes a failure related to the output (sound device or a file).
Constant Value: -5 (0xfffffffb)
ERROR_SERVICE
public static terminal int ERROR_SERVICE
Denotes a failure of a TTS service.
Constant Value: -4 (0xfffffffc)
ERROR_SYNTHESIS
public static final int ERROR_SYNTHESIS
Denotes a failure of a TTS engine to synthesize the given input.
Abiding Value: -iii (0xfffffffd)
LANG_AVAILABLE
public static terminal int LANG_AVAILABLE
Denotes the linguistic communication is available for the language by the locale, simply not the country and variant.
Constant Value: 0 (0x00000000)
LANG_COUNTRY_AVAILABLE
public static final int LANG_COUNTRY_AVAILABLE
Denotes the linguistic communication is bachelor for the language and country specified by the locale, simply non the variant.
Constant Value: 1 (0x00000001)
LANG_COUNTRY_VAR_AVAILABLE
public static terminal int LANG_COUNTRY_VAR_AVAILABLE
Denotes the language is available exactly equally specified by the locale.
Constant Value: 2 (0x00000002)
LANG_MISSING_DATA
public static concluding int LANG_MISSING_DATA
Denotes the language data is missing.
Constant Value: -one (0xffffffff)
LANG_NOT_SUPPORTED
public static concluding int LANG_NOT_SUPPORTED
Denotes the language is non supported.
Abiding Value: -2 (0xfffffffe)
QUEUE_ADD
public static final int QUEUE_ADD
Queue mode where the new entry is added at the stop of the playback queue.
Constant Value: 1 (0x00000001)
QUEUE_FLUSH
public static last int QUEUE_FLUSH
Queue mode where all entries in the playback queue (media to exist 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.
Constant Value: 0 (0x00000000)
STOPPED
public static concluding int STOPPED
Denotes a stop requested by a client. It's used only on the service side of the API, customer should never expect to run across this result lawmaking.
Constant Value: -2 (0xfffffffe)
SUCCESS
public static terminal int SUCCESS
Denotes a successful functioning.
Constant Value: 0 (0x00000000)
Public constructors
TextToSpeech
public TextToSpeech (Context context, TextToSpeech.OnInitListener listener)
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: TheTextToSpeech.OnInitListenerthat volition be called when the             TextToSpeech engine has initialized. In a example of a failure the listener             may exist called immediately, earlier TextToSpeech instance is fully constructed. | 
TextToSpeech
public TextToSpeech (Context context, TextToSpeech.OnInitListener listener, String engine)
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: TheTextToSpeech.OnInitListenerthat will be called when the             TextToSpeech engine has initialized. In a instance of a failure the listener             may be called immediately, before TextToSpeech case is fully constructed. | 
| engine | String: Parcel proper name of the TTS engine to employ. | 
Public methods
addEarcon
public int addEarcon (Cord earcon, String packagename, int resourceId)
Adds a mapping between a string of text and a sound resource in a parcel. Utilise this to add custom earcons.
| Parameters | |
|---|---|
| earcon | String: The name of the earcon.             Example:"[tick]" | 
| packagename | String: the bundle proper name of the application that contains the             resource. This tin can for example be the package proper name of your own application.             Example:                                "com.google.marvin.compass"The package proper noun can be found in the AndroidManifest.xml of the awarding containing the resource.                                    | 
| resourceId | int: Example:R.raw.tick_snd | 
| Returns | |
|---|---|
| int | Code indicating success or failure. See ERRORandSUCCESS. | 
addEarcon
public int addEarcon (String earcon, String filename)
                                                      This method was deprecated       in API level 21.                          
                          As of API level 21, replaced by                          addEarcon(java.lang.Cord, coffee.io.File).                        
Adds a mapping between a cord of text and a sound file. Use this to add custom earcons.
| Parameters | |
|---|---|
| earcon | String: The proper noun of the earcon.             Instance:"[tick]" | 
| filename | String: The total path to the sound file (for example:             "/sdcard/mysounds/tick.wav") | 
| Returns | |
|---|---|
| int | Code indicating success or failure. See ERRORandSUCCESS. | 
addEarcon
public int addEarcon (Cord earcon, File file)
Adds a mapping betwixt a cord of text and a sound file. Apply this to add custom earcons.
| Parameters | |
|---|---|
| earcon | Cord: The name of the earcon.             Case:"[tick]" | 
| file | File: File object pointing to the sound file. | 
| Returns | |
|---|---|
| int | Code indicating success or failure. See ERRORandSUCCESS. | 
addEarcon
public int addEarcon (String earcon, Uri uri)
Adds a mapping between a cord of text and a sound file. Use this to add custom earcons.
| Parameters | |
|---|---|
| earcon | Cord: The name of the earcon.             Example:"[tick]"This value cannot bezilch. | 
| uri | Uri: Uri object pointing to the audio file.   This value cannot benull. | 
| Returns | |
|---|---|
| int | Code indicating success or failure. See ERRORandSUCCESS. | 
addSpeech
public int addSpeech (CharSequence text, File file)
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. Later on a telephone call  to this method, subsequent calls to                          speak(coffee.lang.CharSequence, int, android.os.Bundle, java.lang.Cord)                          will play the specified audio resources if information technology is available, or synthesize the text it is  missing.
| Parameters | |
|---|---|
| text | CharSequence: The cord of text. Case:"south_south_east" | 
| file | File: File object pointing to the audio file. | 
| Returns | |
|---|---|
| int | Lawmaking indicating success or failure. See ERRORandSUCCESS. | 
addSpeech
public int addSpeech (String text, String packagename, int resourceId)
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.bone.Bundle, java.lang.String)                          volition play the specified sound resource  if it is available, or synthesize the text it is missing.
| Parameters | |
|---|---|
| text | String: The string of text. Case:"south_south_east" | 
| packagename | String: Pass the packagename of the application that contains the             resource. If the resource is in your ain awarding (this is             the well-nigh common example), and so put the packagename of your             application hither.Case: "com.google.marvin.compass" The packagename can be plant in the AndroidManifest.xml of your application.                                    | 
| resourceId | int: Example:R.raw.south_south_east | 
| Returns | |
|---|---|
| int | Code indicating success or failure. See ErrorandSUCCESS. | 
addSpeech
public int addSpeech (CharSequence text, String packagename, int resourceId)
Adds a mapping between a CharSequence (may be spanned with TtsSpans) of text  and a sound resource in a package. After a phone call to this method, subsequent calls to                          speak(java.lang.CharSequence, int, android.os.Parcel, java.lang.String)                          volition play the specified sound resource  if it is available, or synthesize the text it is missing.
| Parameters | |
|---|---|
| text | CharSequence: The cord of text. Case:"south_south_east" | 
| packagename | String: Laissez passer the packagename of the application that contains the             resource. If the resources 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 plant in the AndroidManifest.xml of your awarding.                                    | 
| resourceId | int: Example:R.raw.south_south_east | 
| Returns | |
|---|---|
| int | Code indicating success or failure. Encounter ErrorandSUCCESS. | 
addSpeech
public int addSpeech (String text, String filename)
Adds a mapping between a string of text and a sound file. Using this, it is possible to  add together custom pronounciations for a string of text. Later on a telephone call to this method, subsequent  calls to                          speak(java.lang.CharSequence, int, android.os.Bundle, java.lang.String)                          will play the specified sound  resources if it is available, or synthesize the text it is missing.
| Parameters | |
|---|---|
| text | String: The cord of text. Example:"south_south_east" | 
| filename | String: The full path to the sound file (for case:             "/sdcard/mysounds/hello.wav") | 
| Returns | |
|---|---|
| int | Code indicating success or failure. See ERRORandSUCCESS. | 
addSpeech
public int addSpeech (CharSequence text, Uri uri)
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, coffee.lang.String)                          volition play the specified sound resource if information technology is available, or synthesize the text it is  missing.
| Parameters | |
|---|---|
| text | CharSequence: The cord of text. Case:"south_south_east"This value cannot benull. | 
| uri | Uri: Uri object pointing to the sound file.   This value cannot benull. | 
| Returns | |
|---|---|
| int | Code indicating success or failure. See MistakeandSUCCESS. | 
areDefaultsEnforced
public boolean areDefaultsEnforced ()
Checks whether the user'south settings should override settings requested by the calling application. As of the Water ice cream sandwich release, user settings never forcibly override the app's settings.
| Returns | |
|---|---|
| boolean | |
getAvailableLanguages
public Ready<Locale> getAvailableLanguages ()
Query the engine about the set of available languages.
| Returns | |
|---|---|
| Set<Locale> | |
getDefaultEngine
public String getDefaultEngine ()
Gets the bundle name of the default speech synthesis engine.
| Returns | |
|---|---|
| String | Bundle proper noun of the TTS engine that the user has chosen equally their default. | 
getDefaultLanguage
public Locale getDefaultLanguage ()
                                                      This method was deprecated       in API level 21.                          
                          Equally of API level 21, utilize                          getDefaultVoice().getLocale()                          (getDefaultVoice())                        
Returns a Locale example describing the language currently being used as the default  Text-to-spoken communication linguistic communication.   The locale object returned by this method is NOT a valid 1. It has identical form to the  one in                          getLanguage(). Delight refer to                          getLanguage()                          for more than information.
| Returns | |
|---|---|
| Locale | linguistic communication, land (if whatever) and variant (if whatsoever) used by the client stored in a      Locale example, or nullon error. | 
getDefaultVoice
public Voice getDefaultVoice ()
Returns a Voice instance that'south the default voice for the default Text-to-speech language.
| Returns | |
|---|---|
| Vox | The default voice instance for the default linguistic communication, or nothingif not set or      on error. | 
getLanguage
public Locale getLanguage ()
                                                      This method was deprecated       in API level 21.                          
                          As of API level 21, please use                          getVoice().getLocale()                          (getVoice()).                        
Returns a Locale instance describing the linguistic communication currently being used for synthesis  requests sent to the TextToSpeech engine.   In Android four.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 past this or any other  client by a                          TextToSpeech#setLanguage                          telephone call to the same engine.   In Android versions later on iv.ii this office returns the language that is currently existence  used for the synthesis requests sent from this customer. That is the final linguistic communication set  by a                          TextToSpeech#setLanguage                          call on this example.   If a voice is set up (by                          setVoice(android.speech.tts.Voice)), getLanguage will render 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-two/T lawmaking (where a proper Locale would use  a two-letter ISO 639-i code), and the land field contains a iii-letter ISO 3166 country  code (where a proper Locale would use a ii-letter ISO 3166-1 code).
| Returns | |
|---|---|
| Locale | language, country (if any) and variant (if whatever) used past the customer stored in a      Locale instance, or nullon error. | 
getMaxSpeechInputLength
public static int getMaxSpeechInputLength ()
Limit of length of input string passed to speak and synthesizeToFile.
| Returns | |
|---|---|
| int | |
getVoice
public Phonation getVoice ()
Returns a Vocalism instance describing the vocalization currently existence used for synthesis requests sent to the TextToSpeech engine.
| Returns | |
|---|---|
| Vocalization | Vocalism instance used past the customer, or nullif not set or on error. | 
getVoices
public Set<Voice> getVoices ()
Query the engine about the set of available voices. Each TTS Engine tin can betrayal multiple voices for each locale, each with a different set of features.
| Returns | |
|---|---|
| Set<Voice> | |
isSpeaking
public boolean isSpeaking ()
Checks whether the TTS engine is decorated speaking. Annotation that a spoken communication 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 betwixt this point, and when the audio hardware completes playback.
| Returns | |
|---|---|
| boolean | trueif the TTS engine is speaking. | 
playEarcon
public int playEarcon (Cord earcon, int queueMode, HashMap<String, String> params)
                                                      This method was deprecated       in API level 21.                          
                          As of API level 21, replaced by                          playEarcon(coffee.lang.String, int, android.os.Bundle, java.lang.String).                        
Plays the earcon using the specified queueing fashion and parameters.  The earcon must already have been added with                          addEarcon(java.lang.String, coffee.lang.String)                          or                          addEarcon(java.lang.String, java.lang.Cord, int).  This method is asynchronous, i.e. the method just adds the request to the queue of TTS  requests and so returns. The synthesis might not accept finished (or even started!) at the  fourth dimension when this method returns. In order to reliably observe errors during synthesis,  nosotros recommend setting an utterance progress listener (see                          setOnUtteranceProgressListener(UtteranceProgressListener)) and using the                          Engine#KEY_PARAM_UTTERANCE_ID                          parameter.
| Parameters | |
|---|---|
| earcon | Cord: The earcon that should be played | 
| queueMode | int:QUEUE_ADDorQUEUE_FLUSH. | 
| params | HashMap: Parameters for the asking. Can be nil.             Supported parameter names:Engine#KEY_PARAM_STREAM,Engine#KEY_PARAM_UTTERANCE_ID.             Engine specific parameters may be passed in simply the parameter keys             must be prefixed by the proper noun of the engine they are intended for. For instance             the keys "com.svox.pico_foo" and "com.svox.pico:bar" volition be passed to the             engine named "com.svox.pico" if it is existence used. | 
| Returns | |
|---|---|
| int | FaultorSUCCESSof                                queuing                                the playEarcon operation. | 
playEarcon
public int playEarcon (String earcon, int queueMode, Parcel params, String utteranceId)
Plays the earcon using the specified queueing mode and parameters.  The earcon must already accept been added with                          addEarcon(java.lang.String, coffee.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 fifty-fifty started!) at the  time when this method returns. In social club to reliably detect errors during synthesis,  we recommend setting an utterance progress listener (see                          setOnUtteranceProgressListener(UtteranceProgressListener)) and using the                          Engine#KEY_PARAM_UTTERANCE_ID                          parameter.
| Parameters | |
|---|---|
| earcon | String: The earcon that should exist played | 
| queueMode | int:QUEUE_ADDorQUEUE_FLUSH. | 
| params | Bundle: Parameters for the request. Tin be null.             Supported parameter names:Engine#KEY_PARAM_STREAM,             Engine specific parameters may exist passed in but the parameter keys             must be prefixed by the proper name of the engine they are intended for. For example             the keys "com.svox.pico_foo" and "com.svox.pico:bar" volition be passed to the             engine named "com.svox.pico" if it is existence used. | 
| utteranceId | String | 
| Returns | |
|---|---|
| int | ERRORorSUCCESSof                                queuing                                the playEarcon operation. | 
playSilence
public int playSilence (long durationInMs, int queueMode, HashMap<String, String> params)
                                                      This method was deprecated       in API level 21.                          
                          As of API level 21, replaced by                          playSilentUtterance(long, int, java.lang.String).                        
Plays silence for the specified amount of fourth dimension using the specified  queue mode.  This method is asynchronous, i.eastward. the method merely adds the request to the queue of TTS  requests and then returns. The synthesis might not take finished (or even started!) at the  time when this method returns. In society to reliably detect errors during synthesis,  we recommend setting an utterance progress listener (see                          setOnUtteranceProgressListener(UtteranceProgressListener)) and using the                          Engine#KEY_PARAM_UTTERANCE_ID                          parameter.
| Parameters | |
|---|---|
| durationInMs | long: The duration of the silence. | 
| queueMode | int:QUEUE_ADDorQUEUE_FLUSH. | 
| params | HashMap: Parameters for the asking. Can be aught.             Supported parameter names:Engine#KEY_PARAM_UTTERANCE_ID.             Engine specific parameters may exist passed in simply the parameter keys             must be prefixed by the proper noun of the engine they are intended for. For case             the keys "com.svox.pico_foo" and "com.svox.pico:bar" volition be passed to the             engine named "com.svox.pico" if information technology is being used. | 
| Returns | |
|---|---|
| int | MistakeorSUCCESSof                                queuing                                the playSilence operation. | 
playSilentUtterance
public int playSilentUtterance (long durationInMs, int queueMode, String utteranceId)
Plays silence for the specified corporeality 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 so returns. The synthesis might not take finished (or even started!) at the  time when this method returns. In order to reliably find errors during synthesis,  we recommend setting an utterance progress listener (see                          setOnUtteranceProgressListener(UtteranceProgressListener)) and using the                          Engine#KEY_PARAM_UTTERANCE_ID                          parameter.
| Parameters | |
|---|---|
| durationInMs | long: The elapsing of the silence. | 
| queueMode | int:QUEUE_ADDorQUEUE_FLUSH. | 
| utteranceId | Cord: An unique identifier for this asking. | 
| Returns | |
|---|---|
| int | FaultorSUCCESSof                                queuing                                the playSilentUtterance operation. | 
setAudioAttributes
public int setAudioAttributes (AudioAttributes audioAttributes)
Sets the sound attributes to be used when speaking text or playing back a file.
| Parameters | |
|---|---|
| audioAttributes | AudioAttributes: Valid AudioAttributes case. | 
| Returns | |
|---|---|
| int | ErrororSUCCESS. | 
setEngineByPackageName
public int setEngineByPackageName (Cord enginePackageName)
                                                      This method was deprecated       in API level 15.                          
                          This doesn't inform callers when the TTS engine has been         initialized.                          TextToSpeech(android.content.Context, android.speech.tts.TextToSpeech.OnInitListener, java.lang.Cord)                          can be used with the advisable engine name. Too, at that place is no         guarantee that the engine specified will be loaded. If information technology isn't         installed or disabled, the user / organization broad defaults volition apply.                        
Sets the TTS engine to utilize.
| Parameters | |
|---|---|
| enginePackageName | Cord: The package name for the synthesis engine (e.thousand. "com.svox.pico") | 
| Returns | |
|---|---|
| int | ERRORorSUCCESS. | 
setPitch
public int setPitch (float pitch)
Sets the speech pitch for the TextToSpeech engine. This has no outcome on whatsoever pre-recorded speech.
| Parameters | |
|---|---|
| pitch | float: Speech pitch.one.0is the normal pitch,             lower values lower the tone of the synthesized voice,             greater values increment it. | 
| Returns | |
|---|---|
| int | ErrororSUCCESS. | 
setSpeechRate
public int setSpeechRate (float speechRate)
Sets the speech rate. This has no effect on whatsoever pre-recorded speech.
| Parameters | |
|---|---|
| speechRate | float: Spoken communication rate.ane.0is the normal speech rate,             lower values slow downwards the speech (0.5is one-half the normal spoken communication rate),             greater values advance information technology (ii.0is twice the normal speech rate). | 
| Returns | |
|---|---|
| int | MistakeorSUCCESS. | 
setVoice
public int setVoice (Vocalization vocalization)
Sets the text-to-speech voice.
| Parameters | |
|---|---|
| voice | Voice: Ane of objects returned bygetVoices(). | 
| Returns | |
|---|---|
| int | ERRORorSUCCESS. | 
shutdown
public void shutdown ()
Releases the resources used past the TextToSpeech engine. Information technology is good practice for instance to call this method in the onDestroy() method of an Activity so the TextToSpeech engine tin be cleanly stopped.
speak
public int speak (CharSequence text, int queueMode, Parcel params, String utteranceId)
Speaks the text using the specified queuing strategy and spoken language 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 so returns. The synthesis might not have finished (or fifty-fifty started!) at the  time when this method returns. In order to reliably discover errors during synthesis,  nosotros recommend setting an utterance progress listener (run across                          setOnUtteranceProgressListener(UtteranceProgressListener)) and using the                          Engine#KEY_PARAM_UTTERANCE_ID                          parameter.
| Parameters | |
|---|---|
| text | CharSequence: The cord of text to exist spoken. No longer thangetMaxSpeechInputLength()characters. | 
| queueMode | int: The queuing strategy to use,QUEUE_ADDorQUEUE_FLUSH. | 
| params | Bundle: Parameters for the asking. 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 only the parameter keys             must be prefixed past 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 | Cord: An unique identifier for this asking. | 
| Returns | |
|---|---|
| int | ERRORorSUCCESSof                                queuing                                the speak operation. | 
speak
public int speak (Cord text, int queueMode, HashMap<String, String> params)
                                                      This method was deprecated       in API level 21.                          
                          As of API level 21, replaced by                          speak(coffee.lang.CharSequence, int, android.os.Package, java.lang.String).                        
Speaks the string using the specified queuing strategy and spoken communication parameters.  This method is asynchronous, i.e. the method merely adds the asking to the queue of TTS  requests and and so 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,  nosotros recommend setting an utterance progress listener (see                          setOnUtteranceProgressListener(UtteranceProgressListener)) and using the                          Engine#KEY_PARAM_UTTERANCE_ID                          parameter.
| Parameters | |
|---|---|
| text | String: The string of text to be spoken. No longer thangetMaxSpeechInputLength()characters. | 
| queueMode | int: The queuing strategy to use,QUEUE_ADDorQUEUE_FLUSH. | 
| params | HashMap: 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 exist 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 exist passed to the             engine named "com.svox.pico" if it is being used. | 
| Returns | |
|---|---|
| int | ErrororSUCCESSof                                queuing                                the speak operation. | 
stop
public int stop ()
Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue.
| Returns | |
|---|---|
| int | ERRORorSUCCESS. | 
synthesizeToFile
public int synthesizeToFile (CharSequence text, Bundle params, ParcelFileDescriptor fileDescriptor, String utteranceId)
Synthesizes the given text to a ParcelFileDescriptor using the specified parameters.  This method is asynchronous, i.eastward. the method simply adds the request to the queue of TTS  requests and so returns. The synthesis might not have finished (or even started!) at the  fourth dimension when this method returns. In gild to reliably find errors during synthesis,  nosotros recommend setting an utterance progress listener (see                          setOnUtteranceProgressListener(UtteranceProgressListener)).
| Parameters | |
|---|---|
| text | CharSequence: The text that should exist synthesized. No longer thangetMaxSpeechInputLength()characters.  This value cannot existaught. | 
| params | Parcel: Parameters for the request.             Engine specific parameters may be passed in simply the parameter keys             must exist 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 existence used.  This value cannot benull. | 
| fileDescriptor | ParcelFileDescriptor: ParcelFileDescriptor to write the generated audio data to.  This value cannot becypher. | 
| utteranceId | String: An unique identifier for this request.  This value cannot benull. | 
| Returns | |
|---|---|
| int | ErrororSUCCESSof                                queuing                                the synthesizeToFile operation. | 
synthesizeToFile
public int synthesizeToFile (CharSequence text, Bundle params, File file, String utteranceId)
Synthesizes the given text to a file using the specified parameters.  This method is asynchronous, i.e. the method just adds the asking to the queue of TTS  requests so returns. The synthesis might non take finished (or fifty-fifty started!) at the  fourth dimension when this method returns. In order to reliably detect errors during synthesis,  we recommend setting an utterance progress listener (see                          setOnUtteranceProgressListener(UtteranceProgressListener)).
| Parameters | |
|---|---|
| text | CharSequence: The text that should be synthesized. No longer thangetMaxSpeechInputLength()characters. | 
| params | Bundle: Parameters for the asking. 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 exist passed to the             engine named "com.svox.pico" if it is being used. | 
| file | File: File to write the generated sound data to. | 
| utteranceId | Cord: An unique identifier for this request. | 
| Returns | |
|---|---|
| int | ERRORorSUCCESSof                                queuing                                the synthesizeToFile functioning. | 
synthesizeToFile
public int synthesizeToFile (Cord text, HashMap<String, String> params, String filename)
                                                      This method was deprecated       in API level 21.                          
                          Equally of API level 21, replaced by                          synthesizeToFile(java.lang.CharSequence, android.os.Packet, java.io.File, java.lang.String).                        
Synthesizes the given text to a file using the specified parameters.  This method is asynchronous, i.east. the method merely adds the request to the queue of TTS  requests and and so 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 (encounter                          setOnUtteranceProgressListener(UtteranceProgressListener)) and using the                          Engine#KEY_PARAM_UTTERANCE_ID                          parameter.
| Parameters | |
|---|---|
| text | String: The text that should be synthesized. No longer thangetMaxSpeechInputLength()characters. | 
| params | HashMap: 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" volition be passed to the             engine named "com.svox.pico" if it is beingness used. | 
| filename | String: Absolute file filename to write the generated audio data to.It should be             something like "/sdcard/myappsounds/mysound.wav". | 
| Returns | |
|---|---|
| int | MistakeorSUCCESSof                                queuing                                the synthesizeToFile performance. | 
Content and code samples on this page are subject area to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Concluding updated 2022-02-10 UTC.
Source: https://developer.android.com/reference/android/speech/tts/TextToSpeech
0 Response to "Read a Text File With Speech in Android Studio"
Post a Comment