Tuesday, May 14, 2024

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

Right now, 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 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 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 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 greater.

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 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.

personal 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 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’re performed 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 might select to preload a distinct set of languages. You’ll be able to test what languages can be found by utilizing TextToSpeech#getAvailableLanguages(). Throughout watch setup, if the person selects a system language that’s not a pre-loaded voice file, the watch mechanically downloads the corresponding voice file the primary time the person connects to Wi-Fi whereas charging their watch.

There are restricted instances the place the speech output might 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 instantly from the watch’s audio system or by means of Bluetooth linked headphones. Be taught extra about utilizing TTS.

We sit up for seeing how you employ Textual content-to-speech engine to create extra useful and interesting experiences in your customers on Put on OS!

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

Related Articles

3 COMMENTS

  1. voluptatem consequatur libero ab adipisci reprehenderit ut qui ut molestias veritatis eaque quia inventore qui velit distinctio sit quidem. laudantium et numquam aperiam dolor laborum blanditiis eaque

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles