SpeechSynthesizer Class
- java.
lang. Object - com.
microsoft. cognitiveservices. speech. SpeechSynthesizer
- com.
Implements
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 |
---|---|
protected static final java.lang.String |
AUTH_TOKEN_ERROR_PROPERTY
Property name for the last authentication token error. |
protected static final java.lang.String |
AUTH_TOKEN_EXPIRY_PROPERTY
Property name for the token expiration time in milliseconds. |
protected static final java.lang.String |
AUTH_TOKEN_REFRESH_INTERVAL_MS_PROPERTY
Property name for the token refresh interval in milliseconds. |
final
Event |
BookmarkReached
Defines event handler for bookmark reached event. |
final
Event |
SynthesisCanceled
Defines event handler for synthesis canceled event. |
final
Event |
SynthesisCompleted
Defines event handler for synthesis completed event. |
final
Event |
SynthesisStarted
Defines event handler for synthesis started event. |
final
Event |
Synthesizing
Defines event handler for synthesizing event. |
final
Event |
VisemeReceived
Defines event handler for viseme received event. |
final
Event |
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 |
---|---|
void |
close()
Dispose of associated resources. |
java.lang.String |
getAuthorizationToken()
Gets the authorization token used to communicate with the service. |
Safe |
getImpl()
INTERNAL |
Property |
getProperties()
The collection of properties and their values defined for this Speech |
java.util.concurrent.Future<Synthesis |
getVoicesAsync()
Get the available voices, asynchronously. |
java.util.concurrent.Future<Synthesis |
getVoicesAsync(String locale)
Get the available voices, asynchronously. |
void |
setAuthorizationToken(String token)
Sets the authorization token used to communicate with the service. |
protected void |
setUpTokenRefreshCallback(PropertyCollection property)
Sets up a callback for the token refresh event. |
Speech |
SpeakSsml(String ssml)
Execute the speech synthesis on SSML, synchronously. |
java.util.concurrent.Future<Speech |
SpeakSsmlAsync(String ssml)
Execute the speech synthesis on SSML, asynchronously. |
Speech |
SpeakText(String text)
Execute the speech synthesis on plain text, synchronously. |
java.util.concurrent.Future<Speech |
SpeakTextAsync(String text)
Execute the speech synthesis on plain text, asynchronously. |
Speech |
StartSpeakingSsml(String ssml)
Start the speech synthesis on SSML, synchronously. |
java.util.concurrent.Future<Speech |
StartSpeakingSsmlAsync(String ssml)
Start the speech synthesis on SSML, asynchronously. |
Speech |
StartSpeakingText(String text)
Start the speech synthesis on plain text, synchronously. |
java.util.concurrent.Future<Speech |
StartSpeakingTextAsync(String text)
Start the speech synthesis on plain text, asynchronously. |
java.util.concurrent.Future<java.lang.Void> |
StopSpeakingAsync()
Stop the synthesis, asynchronously. |
protected void |
updateAuthToken(PropertyCollection property)
Updates the authentication token in the given Property |
Methods inherited from java.lang.Object
Field Details
AUTH_TOKEN_ERROR_PROPERTY
protected static final String AUTH_TOKEN_ERROR_PROPERTY
Property name for the last authentication token error.
AUTH_TOKEN_EXPIRY_PROPERTY
protected static final String AUTH_TOKEN_EXPIRY_PROPERTY
Property name for the token expiration time in milliseconds.
AUTH_TOKEN_REFRESH_INTERVAL_MS_PROPERTY
protected static final String AUTH_TOKEN_REFRESH_INTERVAL_MS_PROPERTY
Property name for the token refresh interval in milliseconds.
BookmarkReached
public final EventHandlerImpl<SpeechSynthesisBookmarkEventArgs> BookmarkReached
Defines event handler for bookmark reached event. Added in version 1.16.0
SynthesisCanceled
public final EventHandlerImpl<SpeechSynthesisEventArgs> SynthesisCanceled
Defines event handler for synthesis canceled event.
SynthesisCompleted
public final EventHandlerImpl<SpeechSynthesisEventArgs> SynthesisCompleted
Defines event handler for synthesis completed event.
SynthesisStarted
public final EventHandlerImpl<SpeechSynthesisEventArgs> SynthesisStarted
Defines event handler for synthesis started event.
Synthesizing
public final EventHandlerImpl<SpeechSynthesisEventArgs> Synthesizing
Defines event handler for synthesizing event.
VisemeReceived
public final EventHandlerImpl<SpeechSynthesisVisemeEventArgs> VisemeReceived
Defines event handler for viseme received event. Added in version 1.16.0
WordBoundary
public final EventHandlerImpl<SpeechSynthesisWordBoundaryEventArgs> 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:
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:
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:
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:
SpeechSynthesizer
public SpeechSynthesizer(SpeechConfig speechConfig)
Creates a new instance of Speech Synthesizer. Uses the default speaker on the system for audio output.
Parameters:
SpeechSynthesizer
public SpeechSynthesizer(SpeechConfig speechConfig, AutoDetectSourceLanguageConfig autoDetectSourceLangConfig, AudioConfig audioConfig)
Creates a new instance of Speech Synthesizer.
Parameters:
SpeechSynthesizer
public SpeechSynthesizer(SpeechConfig speechConfig, AudioConfig audioConfig)
Creates a new instance of Speech Synthesizer. If audioConfig is null, there is no audio output.
Parameters:
Method Details
close
public void close()
Dispose of associated resources.
getAuthorizationToken
public String getAuthorizationToken()
Gets the authorization token used to communicate with the service.
Returns:
getImpl
getProperties
public PropertyCollection getProperties()
The collection of properties and their values defined for this SpeechSynthesizer.
Returns:
getVoicesAsync
public Future<SynthesisVoicesResult> getVoicesAsync()
Get the available voices, asynchronously. Added in version 1.16.0
Returns:
getVoicesAsync
public Future<SynthesisVoicesResult> getVoicesAsync(String locale)
Get the available voices, asynchronously. Added in version 1.16.0
Parameters:
Returns:
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:
setUpTokenRefreshCallback
protected void setUpTokenRefreshCallback(PropertyCollection property)
Sets up a callback for the token refresh event.
Parameters:
SpeakSsml
public SpeechSynthesisResult SpeakSsml(String ssml)
Execute the speech synthesis on SSML, synchronously.
Parameters:
Returns:
SpeakSsmlAsync
public Future<SpeechSynthesisResult> SpeakSsmlAsync(String ssml)
Execute the speech synthesis on SSML, asynchronously.
Parameters:
Returns:
SpeakText
public SpeechSynthesisResult SpeakText(String text)
Execute the speech synthesis on plain text, synchronously.
Parameters:
Returns:
SpeakTextAsync
public Future<SpeechSynthesisResult> SpeakTextAsync(String text)
Execute the speech synthesis on plain text, asynchronously.
Parameters:
Returns:
StartSpeakingSsml
public SpeechSynthesisResult StartSpeakingSsml(String ssml)
Start the speech synthesis on SSML, synchronously.
Parameters:
Returns:
StartSpeakingSsmlAsync
public Future<SpeechSynthesisResult> StartSpeakingSsmlAsync(String ssml)
Start the speech synthesis on SSML, asynchronously.
Parameters:
Returns:
StartSpeakingText
public SpeechSynthesisResult StartSpeakingText(String text)
Start the speech synthesis on plain text, synchronously.
Parameters:
Returns:
StartSpeakingTextAsync
public Future<SpeechSynthesisResult> StartSpeakingTextAsync(String text)
Start the speech synthesis on plain text, asynchronously.
Parameters:
Returns:
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:
updateAuthToken
protected void updateAuthToken(PropertyCollection property)
Updates the authentication token in the given PropertyCollection.
Parameters: