Posted by Ouiam Koubaa – Product Supervisor and Yingzhe Li – Software program Engineer
At present, 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) expertise. The brand new text-to-speech engine on Put on OS makes use of smaller and extra environment friendly prosody ML fashions to carry quicker synthesis on Put on OS units.
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 way of the watch speaker or Bluetooth linked headphones. The engine is supposed for temporary interactions, so it shouldn’t be used for studying aloud a protracted article, or a protracted abstract of a podcast.
The best way to 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 units. 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 out there on units 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 about 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 attempt { // 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 essential 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 find yourself finished utilizing TTS, you possibly can launch the engine by calling tts.shutdown() in your exercise’s onDestroy() technique. This command also needs to be used when closing an app that TTS is used for.
Languages and Locales
By default, Put on OS TTS contains 7 pre-loaded languages within the system picture: English, Spanish, French, Italian, German, Japanese, and Mandarin Chinese language. OEMs might select to preload a distinct set of languages. You possibly can verify what languages can be found through the use of TextToSpeech#getAvailableLanguages(). Throughout watch setup, if the person selects a system language that’s not 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 might differ from the person’s system language. For instance, in a situation 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 instantly from the watch’s audio system or by way of Bluetooth linked headphones. Be taught extra about utilizing TTS.
We stay up for seeing how you employ Textual content-to-speech engine to create extra useful and interesting experiences to your customers on Put on OS!
Copyright 2023 Google LLC. SPDX-License-Identifier: Apache-2.0
Leave a Comment