Interface TextToSpeech


  • public interface TextToSpeech
    TextToSpeech: text to speech. One instance for one PageLoader.
    Since:
    5.21
    • Method Detail

      • with

        TextToSpeech with​(java.util.Locale locale,
                          java.util.ResourceBundle bundle,
                          boolean demoOnly)
        Set locale, resource bundle, demoOnly flag for the language to speak. The script and variant of the locale will be removed for TTS(Text to Speech) language.
        Parameters:
        locale - locale
        bundle - resource bundle
        demoOnly - whether to speak for demo only
        Returns:
        this TextToSpeech object for chaining method calls
      • setVoice

        void setVoice​(java.lang.String voice)
        Set voice. Default voice can be specified by system property "tts.voice".
        Parameters:
        voice - voice name. If the voice is not available, TTS will pick one voice.
      • setLevel

        void setLevel​(TextToSpeech.Level level)
        Set the minimum level for speech to go through. default is TextToSpeech.Level.INFO, or overridden by system property "tts.level".
        Parameters:
        level - minimum level.
      • isLevelEnabled

        boolean isLevelEnabled​(TextToSpeech.Level level)
        Is the level enabled for speech to go through?
        Parameters:
        level - the level to speak
        Returns:
        true if enabled, false otherwise
      • setCaptionOn

        void setCaptionOn​(boolean on)
        Turn on/off caption.
        Parameters:
        on - whether to generate caption on screen. default is true.
      • setVoiceOn

        void setVoiceOn​(boolean on)
        Turn on/off voice.
        Parameters:
        on - whether to generate voice. default is true.
      • speak

        void speak​(java.lang.String text,
                   java.lang.String language,
                   java.lang.String caption,
                   TextToSpeech.Level level)
        Speak the text of the specified language. If the level is not below the TTS minimum level getLevel(), the text will be spoken.
        Parameters:
        text - the text to speak. resource bundle is not used.
        language - the language of the text such as en, en-US, zh, zh-CN. If not null, override existing language setting.
        caption - if not null, override the caption that is the same as the text to speak by default
        level - the level to speak
      • speak

        void speak​(ParameterizedMessage message,
                   TextToSpeech.Level level)
        Speak the message at the level. If the level is not below the TTS minimum level getLevel(), the message will be spoken.
        Parameters:
        message - the message to speak
        level - the level to speak.
      • waitUntilQueueEmpty

        void waitUntilQueueEmpty()
        Wait until all queued messages(texts) of the latest TextToSpeech have been spoken. The latest TextToSpeech is the one that called one speak() method most recently.
      • showCaption

        void showCaption​(java.lang.String text)
        Show the caption text if caption is on.
        Parameters:
        text - the caption text
      • hideCaption

        void hideCaption()
        Hide caption.