Class SpeechSynthesizer

  • All Implemented Interfaces:
    AutoCloseable

    public class SpeechSynthesizer
    extends Object
    implements AutoCloseable
    Performs speech synthesis to speaker, file, or other audio output streams, and gets synthesized audio as result. Note: close() must be called in order to release underlying resources held by the object. Updated in version 1.16.0
    • Constructor Detail

      • SpeechSynthesizer

        public SpeechSynthesizer​(SpeechConfig speechConfig)
        Creates a new instance of Speech Synthesizer. Uses the default speaker on the system for audio output.
        Parameters:
        speechConfig - speech configuration.
      • SpeechSynthesizer

        public SpeechSynthesizer​(SpeechConfig speechConfig,
                                 AudioConfig audioConfig)
        Creates a new instance of Speech Synthesizer. If audioConfig is null, there is no audio output.
        Parameters:
        speechConfig - speech configuration.
        audioConfig - audio configuration.
      • SpeechSynthesizer

        public SpeechSynthesizer​(SpeechConfig speechConfig,
                                 AutoDetectSourceLanguageConfig autoDetectSourceLangConfig,
                                 AudioConfig audioConfig)
        Creates a new instance of Speech Synthesizer.
        Parameters:
        speechConfig - speech configuration.
        autoDetectSourceLangConfig - the configuration for auto detecting source language
        audioConfig - audio configuration.
      • SpeechSynthesizer

        public SpeechSynthesizer​(EmbeddedSpeechConfig embeddedSpeechConfig)
        Creates a new instance of Speech Synthesizer for embedded speech synthesis. Uses the default speaker on the system for audio output. Added in version 1.19.0
        Parameters:
        embeddedSpeechConfig - embedded speech configuration.
      • SpeechSynthesizer

        public SpeechSynthesizer​(HybridSpeechConfig hybridSpeechConfig)
        Creates a new instance of Speech Synthesizer for hybrid speech synthesis. Uses the default speaker on the system for audio output.
        Parameters:
        hybridSpeechConfig - hybrid speech configuration.
      • SpeechSynthesizer

        public SpeechSynthesizer​(EmbeddedSpeechConfig embeddedSpeechConfig,
                                 AudioConfig audioConfig)
        Creates a new instance of Speech Synthesizer for embedded speech synthesis. If audioConfig is null, there is no audio output. Added in version 1.19.0
        Parameters:
        embeddedSpeechConfig - embedded speech configuration.
        audioConfig - audio configuration.
      • SpeechSynthesizer

        public SpeechSynthesizer​(HybridSpeechConfig hybridSpeechConfig,
                                 AudioConfig audioConfig)
        Creates a new instance of Speech Synthesizer for hybrid speech synthesis. If audioConfig is null, there is no audio output.
        Parameters:
        hybridSpeechConfig - hybrid speech configuration.
        audioConfig - audio configuration.
    • Method Detail

      • SpeakText

        public SpeechSynthesisResult SpeakText​(String text)
        Execute the speech synthesis on plain text, synchronously.
        Parameters:
        text - The plain text for synthesis.
        Returns:
        The synthesis result.
      • SpeakSsml

        public SpeechSynthesisResult SpeakSsml​(String ssml)
        Execute the speech synthesis on SSML, synchronously.
        Parameters:
        ssml - The SSML for synthesis.
        Returns:
        The synthesis result.
      • SpeakTextAsync

        public Future<SpeechSynthesisResult> SpeakTextAsync​(String text)
        Execute the speech synthesis on plain text, asynchronously.
        Parameters:
        text - The plain text for synthesis.
        Returns:
        A task representing the synthesis operation. The task returns a value of SpeechSynthesisResult.
      • SpeakSsmlAsync

        public Future<SpeechSynthesisResult> SpeakSsmlAsync​(String ssml)
        Execute the speech synthesis on SSML, asynchronously.
        Parameters:
        ssml - The SSML for synthesis.
        Returns:
        A task representing the synthesis operation. The task returns a value of SpeechSynthesisResult.
      • StartSpeakingText

        public SpeechSynthesisResult StartSpeakingText​(String text)
        Start the speech synthesis on plain text, synchronously.
        Parameters:
        text - The plain text for synthesis.
        Returns:
        The synthesis result.
      • StartSpeakingSsml

        public SpeechSynthesisResult StartSpeakingSsml​(String ssml)
        Start the speech synthesis on SSML, synchronously.
        Parameters:
        ssml - The SSML for synthesis.
        Returns:
        The synthesis result.
      • StartSpeakingTextAsync

        public Future<SpeechSynthesisResult> StartSpeakingTextAsync​(String text)
        Start the speech synthesis on plain text, asynchronously.
        Parameters:
        text - The plain text for synthesis.
        Returns:
        A task representing the synthesis operation. The task returns a value of SpeechSynthesisResult.
      • StartSpeakingSsmlAsync

        public Future<SpeechSynthesisResult> StartSpeakingSsmlAsync​(String ssml)
        Start the speech synthesis on SSML, asynchronously.
        Parameters:
        ssml - The SSML for synthesis.
        Returns:
        A task representing the synthesis operation. The task returns a value of SpeechSynthesisResult.
      • StopSpeakingAsync

        public Future<Void> StopSpeakingAsync()
        Stop the synthesis, asynchronously. This method will stop the playback and clear the unread data in PullAudioOutputStream. Added in version 1.14.0
        Returns:
        A task representing the asynchronous operation that stops the synthesis.
      • getVoicesAsync

        public Future<SynthesisVoicesResult> getVoicesAsync​(String locale)
        Get the available voices, asynchronously. Added in version 1.16.0
        Parameters:
        locale - Specify the locale of voices, in BCP-47 format; or leave it empty to get all available voices.
        Returns:
        A task representing the asynchronous operation that gets the voices.
      • getVoicesAsync

        public Future<SynthesisVoicesResult> getVoicesAsync()
        Get the available voices, asynchronously. Added in version 1.16.0
        Returns:
        A task representing the asynchronous operation that gets the voices.
      • getProperties

        public PropertyCollection getProperties()
        The collection of properties and their values defined for this SpeechSynthesizer.
        Returns:
        The collection of properties and their values defined for this SpeechSynthesizer.
      • setAuthorizationToken

        public void setAuthorizationToken​(String token)
        Sets the authorization token used to communicate with the service. Note: The caller needs to ensure that the authorization token is valid. Before the authorization token expires, the caller needs to refresh it by calling this setter with a new valid token. Otherwise, the synthesizer will encounter errors while speech synthesis.
        Parameters:
        token - Authorization token.
      • getAuthorizationToken

        public String getAuthorizationToken()
        Gets the authorization token used to communicate with the service.
        Returns:
        Authorization token.
      • close

        public void close()
        Dispose of associated resources.
        Specified by:
        close in interface AutoCloseable