Sdílet prostřednictvím


SpeechSynthesizer Class

  • java.lang.Object
    • com.microsoft.cognitiveservices.speech.SpeechSynthesizer

Implements

java.lang.AutoCloseable

public class SpeechSynthesizer
implements java.lang.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

Field Summary

Modifier and Type Field and Description
final EventHandlerImpl<SpeechSynthesisBookmarkEventArgs> BookmarkReached

Defines event handler for bookmark reached event.

final EventHandlerImpl<SpeechSynthesisEventArgs> SynthesisCanceled

Defines event handler for synthesis canceled event.

final EventHandlerImpl<SpeechSynthesisEventArgs> SynthesisCompleted

Defines event handler for synthesis completed event.

final EventHandlerImpl<SpeechSynthesisEventArgs> SynthesisStarted

Defines event handler for synthesis started event.

final EventHandlerImpl<SpeechSynthesisEventArgs> Synthesizing

Defines event handler for synthesizing event.

final EventHandlerImpl<SpeechSynthesisVisemeEventArgs> VisemeReceived

Defines event handler for viseme received event.

final EventHandlerImpl<SpeechSynthesisWordBoundaryEventArgs> WordBoundary

Defines event handler for word boundary event.

Constructor Summary

Constructor Description
SpeechSynthesizer(EmbeddedSpeechConfig embeddedSpeechConfig)

Creates a new instance of Speech Synthesizer for embedded speech synthesis.

SpeechSynthesizer(EmbeddedSpeechConfig embeddedSpeechConfig, AudioConfig audioConfig)

Creates a new instance of Speech Synthesizer for embedded speech synthesis.

SpeechSynthesizer(HybridSpeechConfig hybridSpeechConfig)

Creates a new instance of Speech Synthesizer for hybrid speech synthesis.

SpeechSynthesizer(HybridSpeechConfig hybridSpeechConfig, AudioConfig audioConfig)

Creates a new instance of Speech Synthesizer for hybrid speech synthesis.

SpeechSynthesizer(SpeechConfig speechConfig)

Creates a new instance of Speech Synthesizer.

SpeechSynthesizer(SpeechConfig speechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig, AudioConfig audioConfig)

Creates a new instance of Speech Synthesizer.

SpeechSynthesizer(SpeechConfig speechConfig, AudioConfig audioConfig)

Creates a new instance of Speech Synthesizer.

Method Summary

Modifier and Type Method and Description
SpeechSynthesisResult SpeakSsml(String ssml)

Execute the speech synthesis on SSML, synchronously.

java.util.concurrent.Future<SpeechSynthesisResult> SpeakSsmlAsync(String ssml)

Execute the speech synthesis on SSML, asynchronously.

SpeechSynthesisResult SpeakText(String text)

Execute the speech synthesis on plain text, synchronously.

java.util.concurrent.Future<SpeechSynthesisResult> SpeakTextAsync(String text)

Execute the speech synthesis on plain text, asynchronously.

SpeechSynthesisResult StartSpeakingSsml(String ssml)

Start the speech synthesis on SSML, synchronously.

java.util.concurrent.Future<SpeechSynthesisResult> StartSpeakingSsmlAsync(String ssml)

Start the speech synthesis on SSML, asynchronously.

SpeechSynthesisResult StartSpeakingText(String text)

Start the speech synthesis on plain text, synchronously.

java.util.concurrent.Future<SpeechSynthesisResult> StartSpeakingTextAsync(String text)

Start the speech synthesis on plain text, asynchronously.

java.util.concurrent.Future<java.lang.Void> StopSpeakingAsync()

Stop the synthesis, asynchronously.

void close()

Dispose of associated resources.

java.lang.String getAuthorizationToken()

Gets the authorization token used to communicate with the service.

SafeHandle getImpl()

INTERNAL

PropertyCollection getProperties()

The collection of properties and their values defined for this SpeechSynthesizer.

java.util.concurrent.Future<SynthesisVoicesResult> getVoicesAsync()

Get the available voices, asynchronously.

java.util.concurrent.Future<SynthesisVoicesResult> getVoicesAsync(String locale)

Get the available voices, asynchronously.

void setAuthorizationToken(String token)

Sets the authorization token used to communicate with the service.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

BookmarkReached

public final EventHandlerImpl BookmarkReached

Defines event handler for bookmark reached event. Added in version 1.16.0

SynthesisCanceled

public final EventHandlerImpl SynthesisCanceled

Defines event handler for synthesis canceled event.

SynthesisCompleted

public final EventHandlerImpl SynthesisCompleted

Defines event handler for synthesis completed event.

SynthesisStarted

public final EventHandlerImpl SynthesisStarted

Defines event handler for synthesis started event.

Synthesizing

public final EventHandlerImpl Synthesizing

Defines event handler for synthesizing event.

VisemeReceived

public final EventHandlerImpl VisemeReceived

Defines event handler for viseme received event. Added in version 1.16.0

WordBoundary

public final EventHandlerImpl WordBoundary

Defines event handler for word boundary event.

Constructor Details

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(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)

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

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

Method Details

SpeakSsml

public SpeechSynthesisResult SpeakSsml(String ssml)

Execute the speech synthesis on SSML, synchronously.

Parameters:

ssml - The SSML for synthesis.

Returns:

The synthesis result.

SpeakSsmlAsync

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

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.

SpeakTextAsync

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

StartSpeakingSsml

public SpeechSynthesisResult StartSpeakingSsml(String ssml)

Start the speech synthesis on SSML, synchronously.

Parameters:

ssml - The SSML for synthesis.

Returns:

The synthesis result.

StartSpeakingSsmlAsync

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

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.

StartSpeakingTextAsync

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

StopSpeakingAsync

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

close

public void close()

Dispose of associated resources.

getAuthorizationToken

public String getAuthorizationToken()

Gets the authorization token used to communicate with the service.

Returns:

Authorization token.

getImpl

public SafeHandle getImpl()

INTERNAL

Returns:

SafeHandle to SpeechSynthesizer

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.

getVoicesAsync

public Future getVoicesAsync()

Get the available voices, asynchronously. Added in version 1.16.0

Returns:

A task representing the asynchronous operation that gets the voices.

getVoicesAsync

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

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.

Applies to