Introducing a brand new Textual content-To-Speech engine on Put on OS



Posted by Ouiam Koubaa – Product Supervisor and Yingzhe Li – Software program Engineer

In the present day, 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 deliver quicker synthesis on Put on OS units.

Use instances for Put on OS’s text-to-speech can vary from accessibility companies, teaching cues for train apps, navigation cues, and studying aloud incoming alerts via the watch speaker or Bluetooth linked headphones. The engine is supposed for transient interactions, so it shouldn’t be used for studying aloud a protracted article, or a protracted abstract of a podcast.

Tips on how 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 consumer 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 instances 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




            strive {
                // Create a short lived 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 needed 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)
}

When you find yourself accomplished utilizing TTS, you possibly can launch the engine by calling tts.shutdown() in your exercise’s onDestroy() methodology. 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 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 through the use of TextToSpeech#getAvailableLanguages(). Throughout watch setup, if the consumer selects a system language that’s not a pre-loaded voice file, the watch routinely downloads the corresponding voice file the primary time the consumer connects to Wi-Fi whereas charging their watch.

There are restricted instances the place the speech output could differ from the consumer’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 consumer is in, not within the language the consumer 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 immediately from the watch’s audio system or via 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 interesting experiences to your customers on Put on OS!

Copyright 2023 Google LLC.
SPDX-License-Identifier: Apache-2.0

Recent Articles

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox