Sdílet prostřednictvím


SpeechConfig Class

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

Implements

java.lang.AutoCloseable

public class SpeechConfig
implements java.lang.AutoCloseable

Speech configuration. Note: close() must be called in order to release underlying resources held by the object. Changed in version 1.7.0

Field Summary

Modifier and Type Field and Description
static java.lang.Class<?> speechConfigClass

Accessor to load the native library.

Constructor Summary

Modifier Constructor Description
protected SpeechConfig(long handleValue)

Internal constructor for speech configuration object.

Method Summary

Modifier and Type Method and Description
void close()

Dispose of associated resources.

void enableAudioLogging()

Enable audio logging in service.

void enableDictation()

Enable dictation.

static SpeechConfig fromAuthorizationToken(String authorizationToken, String region)

Creates an instance of a speech config with specified authorization token and service region.

static SpeechConfig fromEndpoint(URI endpoint)

Creates an instance of the speech config with specified endpoint.

static SpeechConfig fromEndpoint(URI endpoint, String subscriptionKey)

Creates an instance of the speech config with specified endpoint and subscription key.

static SpeechConfig fromHost(URI host)

Creates an instance of the speech config with specified host.

static SpeechConfig fromHost(URI host, String subscriptionKey)

Creates an instance of the speech config with specified host and subscription key.

static SpeechConfig fromSubscription(String subscriptionKey, String region)

Creates an instance of a speech config with specified subscription key and service region.

java.lang.String getAuthorizationToken()

Gets the authorization token.

java.lang.String getEndpointId()

Gets the endpoint ID of a customized speech model that is used for speech recognition, or a custom voice model for speech synthesis.

SafeHandle getImpl()

Get the native handle to speech config object.

OutputFormat getOutputFormat()

Gets speech recognition output format (simple or detailed).

java.lang.String getProperty(PropertyId id)

Gets the property by propertyId.

java.lang.String getProperty(String name)

Gets a named property as value.

java.lang.String getSpeechRecognitionLanguage()

Gets the speech recognition language

java.lang.String getSpeechSynthesisLanguage()

Gets the speech synthesis language.

java.lang.String getSpeechSynthesisOutputFormat()

Gets the speech synthesis output format.

java.lang.String getSpeechSynthesisVoiceName()

Gets the speech synthesis voice name.

void requestWordLevelTimestamps()

Includes word-level timestamps.

void setAuthorizationToken(String value)

Sets the authorization token.

void setEndpointId(String value)

Sets the endpoint ID of a customized speech model that is used for speech recognition, or a custom voice model for speech synthesis.

void setOutputFormat(OutputFormat format)

Sets speech recognition output format (simple or detailed).

void setProfanity(ProfanityOption profanity)

Sets profanity option.

void setProperty(PropertyId id, String value)

Sets the property by propertyId.

void setProperty(String name, String value)

Sets a named property as value.

void setProxy(String proxyHostName, int proxyPort, String proxyUserName, String proxyPassword)

Sets proxy configuration Added in version 1.1.0.

void setServiceProperty(String name, String value, ServicePropertyChannel channel)

Sets a property value that will be passed to service using the specified channel.

void setSpeechRecognitionLanguage(String value)

Sets the speech recognition language

void setSpeechSynthesisLanguage(String value)

Sets the speech synthesis language.

void setSpeechSynthesisOutputFormat(SpeechSynthesisOutputFormat value)

Sets the speech synthesis output format.

void setSpeechSynthesisVoiceName(String value)

Sets the speech synthesis voice name.

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

speechConfigClass

public static Class speechConfigClass

Accessor to load the native library. Holds the class active so the class GC does not reclaim it (and the local variables!)

Constructor Details

SpeechConfig

protected SpeechConfig(long handleValue)

Internal constructor for speech configuration object.

Parameters:

handleValue - The native handle.

Method Details

close

public void close()

Dispose of associated resources.

enableAudioLogging

public void enableAudioLogging()

Enable audio logging in service. Audio and content logs are stored either in Microsoft-owned storage, or in your own storage account linked to your Cognitive Services subscription (Bring Your Own Storage (BYOS) enabled Speech resource). Added in version 1.5.0.

enableDictation

public void enableDictation()

Enable dictation. Only supported in speech continuous recognition. Added in version 1.5.0.

fromAuthorizationToken

public static SpeechConfig fromAuthorizationToken(String authorizationToken, String region)

Creates an instance of a speech config with specified authorization token and service region. 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. As configuration values are copied when creating a new recognizer, the new token value will not apply to recognizers that have already been created. For recognizers that have been created before, you need to set authorization token of the corresponding recognizer to refresh the token. Otherwise, the recognizers will encounter errors during recognition.

Parameters:

authorizationToken - The authorization token.
region - The region name (see the region page).

Returns:

A speech config instance.

fromEndpoint

public static SpeechConfig fromEndpoint(URI endpoint)

Creates an instance of the speech config with specified endpoint. This method is intended only for users who use a non-standard service endpoint or parameters. Note: The query parameters specified in the endpoint URI are not changed, even if they are set by any other APIs. For example, if the recognition language is defined in URI as query parameter "language=de-DE", and also set by setSpeechRecognitionLanguage("en-US"), the language setting in URI takes precedence, and the effective language is "de-DE". Only the parameters that are not specified in the endpoint URI can be set by other APIs. Note: if the endpoint requires a subscription key for authentication, please use fromEndpoint(java.net.URI, String) to pass the subscription key as parameter. To use an authorization token with fromEndpoint, use this method to create a SpeechConfig instance, and then call setAuthorizationToken() on the created SpeechConfig instance. Note: Added in version 1.5.0.

Parameters:

endpoint - The service endpoint to connect to.

Returns:

A speech config instance.

fromEndpoint

public static SpeechConfig fromEndpoint(URI endpoint, String subscriptionKey)

Creates an instance of the speech config with specified endpoint and subscription key. This method is intended only for users who use a non-standard service endpoint or parameters. Note: The query parameters specified in the endpoint URI are not changed, even if they are set by any other APIs. Whether a specific query parameter is supported or not, depends on the endpoint and scenario. For example, if the recognition language is defined in URI as query parameter "language=de-DE", and also set by setSpeechRecognitionLanguage("en-US"), the language setting in URI takes precedence, and the effective language is "de-DE". The example only applies when the endpoint and scenario combination supports language as a query parameter. Only the parameters that are not specified in the endpoint URI can be set by other APIs. Note: To use an authorization token with fromEndpoint, please use fromEndpoint(java.net.URI), and then call setAuthorizationToken() on the created SpeechConfig instance.

Parameters:

endpoint - The service endpoint to connect to.
subscriptionKey - The subscription key.

Returns:

A speech config instance.

fromHost

public static SpeechConfig fromHost(URI host)

Creates an instance of the speech config with specified host. This method is intended only for users who use a non-default service host. Standard resource path will be assumed. For services with a non-standard resource path or no path at all, use fromEndpoint instead. Note: Query parameters are not allowed in the host URI and must be set by other APIs. Note: If the host requires a subscription key for authentication, use fromHost(java.net.URI, String) to pass the subscription key as parameter. To use an authorization token with fromHost, use this method to create a SpeechConfig instance, and then call setAuthorizationToken() on the created SpeechConfig instance. Note: Added in version 1.8.0.

Parameters:

host - The service host to connect to. Format is "protocol://host:port" where ":port" is optional.

Returns:

A speech config instance.

fromHost

public static SpeechConfig fromHost(URI host, String subscriptionKey)

Creates an instance of the speech config with specified host and subscription key. This method is intended only for users who use a non-default service host. Standard resource path will be assumed. For services with a non-standard resource path or no path at all, use fromEndpoint instead. Note: Query parameters are not allowed in the host URI and must be set by other APIs. Note: To use an authorization token with fromHost, use fromHost(java.net.URI), and then call setAuthorizationToken() on the created SpeechConfig instance. Note: Added in version 1.8.0.

Parameters:

host - The service host to connect to. Format is "protocol://host:port" where ":port" is optional.
subscriptionKey - The subscription key.

Returns:

A speech config instance.

fromSubscription

public static SpeechConfig fromSubscription(String subscriptionKey, String region)

Creates an instance of a speech config with specified subscription key and service region.

Parameters:

subscriptionKey - The subscription key.
region - The region name (see the region page).

Returns:

A speech config instance.

getAuthorizationToken

public String getAuthorizationToken()

Gets the authorization token.

Returns:

The authorization token.

getEndpointId

public String getEndpointId()

Gets the endpoint ID of a customized speech model that is used for speech recognition, or a custom voice model for speech synthesis.

Returns:

The endpoint ID.

getImpl

public SafeHandle getImpl()

Get the native handle to speech config object.

Returns:

The native handle.

getOutputFormat

public OutputFormat getOutputFormat()

Gets speech recognition output format (simple or detailed). Note: This output format is for speech recognition results, use com.microsoft.cognitiveservices.speech.SpeechConfig#setSpeechSynthesisOutputFormat to set synthesized audio output format.

Returns:

Returns the speech recognition output format.

getProperty

public String getProperty(PropertyId id)

Gets the property by propertyId. Added in version 1.3.0.

Parameters:

id - PropertyId of the property.

Returns:

The value.

getProperty

public String getProperty(String name)

Gets a named property as value.

Parameters:

name - the name of the property.

Returns:

The value.

getSpeechRecognitionLanguage

public String getSpeechRecognitionLanguage()

Gets the speech recognition language

Returns:

Returns the recognition language.

getSpeechSynthesisLanguage

public String getSpeechSynthesisLanguage()

Gets the speech synthesis language. Added in version 1.7.0

Returns:

Returns the synthesis language.

getSpeechSynthesisOutputFormat

public String getSpeechSynthesisOutputFormat()

Gets the speech synthesis output format. Added in version 1.7.0

Returns:

Returns the synthesis output format.

getSpeechSynthesisVoiceName

public String getSpeechSynthesisVoiceName()

Gets the speech synthesis voice name. Added in version 1.7.0

Returns:

Returns the synthesis voice name.

requestWordLevelTimestamps

public void requestWordLevelTimestamps()

Includes word-level timestamps. Added in version 1.5.0.

setAuthorizationToken

public void setAuthorizationToken(String value)

Sets the authorization token. 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. As configuration values are copied when creating a new recognizer, the new token value will not apply to recognizers that have already been created. For recognizers that have been created before, you need to set authorization token of the corresponding recognizer to refresh the token. Otherwise, the recognizers will encounter errors during recognition.

Parameters:

value - the authorization token.

setEndpointId

public void setEndpointId(String value)

Sets the endpoint ID of a customized speech model that is used for speech recognition, or a custom voice model for speech synthesis.

Parameters:

value - the endpoint ID.

setOutputFormat

public void setOutputFormat(OutputFormat format)

Sets speech recognition output format (simple or detailed). Note: This output format is for speech recognition results, use com.microsoft.cognitiveservices.speech.SpeechConfig#setSpeechSynthesisOutputFormat to set synthesized audio output format.

Parameters:

format - The speech recognition output format.

setProfanity

public void setProfanity(ProfanityOption profanity)

Sets profanity option. Added in version 1.5.0.

Parameters:

profanity - the property option to set.

setProperty

public void setProperty(PropertyId id, String value)

Sets the property by propertyId. Added in version 1.3.0.

Parameters:

id - PropertyId of the property.
value - The value.

setProperty

public void setProperty(String name, String value)

Sets a named property as value.

Parameters:

name - the name of the property.
value - the value.

setProxy

public void setProxy(String proxyHostName, int proxyPort, String proxyUserName, String proxyPassword)

Sets proxy configuration Added in version 1.1.0. Note: Proxy functionality is not available on macOS. This function will have no effect on this platform.

Parameters:

proxyHostName - the host name of the proxy server, without the protocol scheme (http://)
proxyPort - the port number of the proxy server.
proxyUserName - the user name of the proxy server. Use empty string if no user name is needed.
proxyPassword - the password of the proxy server. Use empty string if no user password is needed.

setServiceProperty

public void setServiceProperty(String name, String value, ServicePropertyChannel channel)

Sets a property value that will be passed to service using the specified channel. Added in version 1.5.0.

Parameters:

name - the property name.
value - the property value.
channel - the channel used to pass the specified property to service.

setSpeechRecognitionLanguage

public void setSpeechRecognitionLanguage(String value)

Sets the speech recognition language

Parameters:

value - the language identifier in BCP-47 format.

setSpeechSynthesisLanguage

public void setSpeechSynthesisLanguage(String value)

Sets the speech synthesis language. Added in version 1.7.0

Parameters:

value - the language identifier in BCP-47 format (e.g. en-US).

setSpeechSynthesisOutputFormat

public void setSpeechSynthesisOutputFormat(SpeechSynthesisOutputFormat value)

Sets the speech synthesis output format. Added in version 1.7.0

Parameters:

value - The synthesis output format ID (e.g. Riff16Khz16BitMonoPcm).

setSpeechSynthesisVoiceName

public void setSpeechSynthesisVoiceName(String value)

Sets the speech synthesis voice name. Added in version 1.7.0

Parameters:

value - The speech synthesis voice name.

Applies to