Posted by Ouiam Koubaa – Product Supervisor and Yingzhe Li – Software program Engineer
At the moment, we’re excited to announce the discharge of a brand new Textual content-To-Speech (TTS) engine that’s performant and dependable. Textual content-to-speech turns textual content into natural-sounding speech throughout greater than 50 languages powered by Google’s machine studying (ML) know-how. The brand new text-to-speech engine on Put on OS makes use of decreased prosody ML fashions to deliver sooner synthesis on Put on OS gadgets.
Use circumstances for Put on OS’s text-to-speech can vary from accessibility providers, teaching cues for train apps, navigation cues, and studying aloud incoming alerts by means of the watch speaker or Bluetooth linked headphones. The engine is supposed for temporary interactions, so it shouldn’t be used for studying aloud an extended article, or an extended abstract of a podcast.
How you can use Put on OS’s TTS
Textual content-to-speech has lengthy been supported on Android. Put on OS’s new TTS has been tuned to be performant and dependable on low-memory gadgets. All of the Android APIs are nonetheless the identical, so builders use the identical course of to combine it right into a Put on OS app, for instance, TextToSpeech#converse can be utilized to talk particular textual content. That is accessible on gadgets that run Put on OS 4 or increased.
When the person interacts with the Put on OS TTS for the primary time following a tool boot, the synthesis engine is prepared in about 10 seconds. For particular circumstances the place builders need the watch to talk instantly after opening an app or launching an expertise, the next code can be utilized to pre-warm the TTS engine earlier than any synthesis requests are available in.
non-public enjoyable initTtsEngine() { // Callback when TextToSpeech connection is ready up val callback = TextToSpeech.OnInitListener { standing -> if (standing == TextToSpeech.SUCCESS) { Log.i(TAG, "tts Shopper Initialized efficiently") // Get default TTS locale val defaultVoice = tts.voice if (defaultVoice == null) { Log.w(TAG, "defaultVoice == null") return@OnInitListener } // Set TTS engine to use default locale tts.language = defaultVoice.locale strive { // Create a brief file to synthesize pattern textual content val tempFile = File.createTempFile("tmpsynthesize", null, applicationContext.cacheDir) // Synthesize pattern textual content to our file tts.synthesizeToFile( /* textual content= */ "1 2 3", // Some pattern textual content /* params= */ null, // No params vital for a pattern request /* file= */ tempFile, /* utteranceId= */ "sampletext" ) // And clear up the file tempFile.deleteOnExit() } catch (e: Exception) { Log.e(TAG, "Unhandled exception: ", e) } } } tts = TextToSpeech(applicationContext, callback) }
If you end up achieved utilizing TTS, you’ll be able to launch the engine by calling tts.shutdown() in your exercise’s onDestroy() technique. This command must also be used when closing an app that TTS is used for.
Languages and Locales
By default, Put on OS TTS consists of 7 pre-loaded languages within the system picture: English, Spanish, French, Italian, German, Japanese, and Mandarin Chinese language. OEMs could select to preload a distinct set of languages. You may verify what languages can be found by utilizing TextToSpeech#getAvailableLanguages(). Throughout watch setup, if the person selects a system language that isn’t a pre-loaded voice file, the watch routinely downloads the corresponding voice file the primary time the person connects to Wi-Fi whereas charging their watch.
There are restricted circumstances the place the speech output could differ from the person’s system language. For instance, in a state of affairs the place a security app makes use of TTS to name emergency responders, builders would possibly wish to synthesize speech within the language of the locale the person is in, not within the language the person has their watch set to. To synthesize textual content in a distinct language from system settings, use TextToSpeech#setLanguage(java.util.Locale)
Conclusion
Your Put on OS apps now have the facility to speak, both straight from the watch’s audio system or by means of Bluetooth linked headphones. Study extra about utilizing TTS.
We sit up for seeing how you utilize Textual content-to-speech engine to create extra useful and fascinating experiences to your customers on Put on OS!
Copyright 2023 Google LLC. SPDX-License-Identifier: Apache-2.0