speech

package
Version: v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2021 License: MIT Imports: 9 Imported by: 3

Documentation

Overview

Package speech provides functionality for speech recognizers along with their related configuration and event objects

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoDetectSourceLanguageConfig

type AutoDetectSourceLanguageConfig struct {
	// contains filtered or unexported fields
}

AutoDetectSourceLanguageConfig defines auto detection source configuration

func NewAutoDetectSourceLanguageConfigFromLanguageConfigs

func NewAutoDetectSourceLanguageConfigFromLanguageConfigs(configs []*SourceLanguageConfig) (*AutoDetectSourceLanguageConfig, error)

NewAutoDetectSourceLanguageConfigFromLanguageConfigs creates an instance of the AutoDetectSourceLanguageConfig with a list of source language config

func NewAutoDetectSourceLanguageConfigFromLanguages

func NewAutoDetectSourceLanguageConfigFromLanguages(languages []string) (*AutoDetectSourceLanguageConfig, error)

NewAutoDetectSourceLanguageConfigFromLanguages creates an instance of the AutoDetectSourceLanguageConfig with source languages

func (AutoDetectSourceLanguageConfig) Close

func (config AutoDetectSourceLanguageConfig) Close()

Close performs cleanup of resources.

type KeywordRecognitionModel

type KeywordRecognitionModel struct {
	// contains filtered or unexported fields
}

KeywordRecognitionModel represents the keyword recognition model used with StartKeywordRecognitionAsync methods.

func NewKeywordRecognitionModelFromFile

func NewKeywordRecognitionModelFromFile(filename string) (*KeywordRecognitionModel, error)

/ NewKeywordRecognitionModelFromFile creates a keyword recognition model using the specified file.

func (KeywordRecognitionModel) Close

func (model KeywordRecognitionModel) Close()

Close disposes the associated resources.

func (KeywordRecognitionModel) GetHandle

func (model KeywordRecognitionModel) GetHandle() common.SPXHandle

GetHandle gets the handle to the resource (for internal use)

type RecognitionEventArgs

type RecognitionEventArgs struct {
	SessionEventArgs
	Offset uint64
}

RecognitionEventArgs represents the recognition event arguments.

func NewRecognitionEventArgsFromHandle

func NewRecognitionEventArgsFromHandle(handle common.SPXHandle) (*RecognitionEventArgs, error)

NewRecognitionEventArgsFromHandle creates the object from the handle (for internal use)

type RecognitionEventHandler

type RecognitionEventHandler func(event RecognitionEventArgs)

RecognitionEventHandler is the type of the event handler that receives RecognitionEventArgs

type SessionEventArgs

type SessionEventArgs struct {
	// SessionID Session identifier (a GUID in string format).
	SessionID string
}

SessionEventArgs represents the session event arguments.

func NewSessionEventArgsFromHandle

func NewSessionEventArgsFromHandle(handle common.SPXHandle) (*SessionEventArgs, error)

NewSessionEventArgsFromHandle creates the object from the handle (for internal use)

func (SessionEventArgs) Close

func (event SessionEventArgs) Close()

Close releases the underlying resources.

type SessionEventHandler

type SessionEventHandler func(event SessionEventArgs)

SessionEventHandler is the type of the event handler that receives SessionEventArgs

type SourceLanguageConfig

type SourceLanguageConfig struct {
	// contains filtered or unexported fields
}

SourceLanguageConfig defines source language configuration.

func NewSourceLanguageConfigFromLanguage

func NewSourceLanguageConfigFromLanguage(language string) (*SourceLanguageConfig, error)

NewSourceLanguageConfigFromLanguage creates an instance of the SourceLanguageConfig with source language

func NewSourceLanguageConfigFromLanguageAndEndpointId

func NewSourceLanguageConfigFromLanguageAndEndpointId(language string, endpointID string) (*SourceLanguageConfig, error)

NewSourceLanguageConfigFromLanguageAndEndpointId creates an instance of the SourceLanguageConfig with source language and custom endpoint id. A custom endpoint id corresponds to custom models.

func (SourceLanguageConfig) Close

func (config SourceLanguageConfig) Close()

Close performs cleanup of resources.

type SpeechConfig

type SpeechConfig struct {
	// contains filtered or unexported fields
}

SpeechConfig is the class that defines configurations for speech / intent recognition, or speech synthesis.

func NewSpeechConfigFromAuthorizationToken

func NewSpeechConfigFromAuthorizationToken(authorizationToken string, region string) (*SpeechConfig, error)

NewSpeechConfigFromAuthorizationToken creates an instance of the speech config with specified authorization token and 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.

func NewSpeechConfigFromEndpoint

func NewSpeechConfigFromEndpoint(endpoint string) (*SpeechConfig, error)

NewSpeechConfigFromEndpoint creates an instance of SpeechConfig with specified endpoint. This method is intended only for users who use a non-standard service endpoint. 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, use NewSpeechConfigFromEndpointWithSubscription 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.

func NewSpeechConfigFromEndpointWithSubscription

func NewSpeechConfigFromEndpointWithSubscription(endpoint string, subscriptionKey string) (*SpeechConfig, error)

NewSpeechConfigFromEndpointWithSubscription creates an instance of the speech config with specified endpoint and subscription. This method is intended only for users who use a non-standard service endpoint. 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: To use an authorization token with endoint, use FromEndpoint, / and then call SetAuthorizationToken() on the created SpeechConfig instance.

func NewSpeechConfigFromHandle

func NewSpeechConfigFromHandle(handle common.SPXHandle) (*SpeechConfig, error)

NewSpeechConfigFromHandle creates a SpeechConfig instance from a valid handle. This is for internal use only.

func NewSpeechConfigFromHost

func NewSpeechConfigFromHost(host string) (*SpeechConfig, error)

NewSpeechConfigFromHost Creates an instance of SpeechConfig 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 NewSpeechConfigFromHostWithSubscription 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.

func NewSpeechConfigFromHostWithSubscription

func NewSpeechConfigFromHostWithSubscription(host string, subscriptionKey string) (*SpeechConfig, error)

NewSpeechConfigFromHostWithSubscription creates an instance of the speech config with specified host and subscription. 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 host, use NewSpeechConfigFromHost, and then call SetAuthorizationToken() on the created SpeechConfig instance.

func NewSpeechConfigFromSubscription

func NewSpeechConfigFromSubscription(subscriptionKey string, region string) (*SpeechConfig, error)

NewSpeechConfigFromSubscription creates an instance of the speech config with specified subscription key and region.

func (*SpeechConfig) AuthorizationToken

func (config *SpeechConfig) AuthorizationToken() string

AuthorizationToken is the authorization token to connect to the service.

func (*SpeechConfig) Close

func (config *SpeechConfig) Close()

Close disposes the associated resources.

func (*SpeechConfig) EnableAudioLogging

func (config *SpeechConfig) EnableAudioLogging() error

EnableAudioLogging enables audio logging in service.

func (*SpeechConfig) EnableDictation

func (config *SpeechConfig) EnableDictation() error

EnableDictation enables dictation mode. Only supported in speech continuous recognition.

func (*SpeechConfig) EndpointID

func (config *SpeechConfig) EndpointID() string

EndpointID is the endpoint ID

func (*SpeechConfig) GetProperty

func (config *SpeechConfig) GetProperty(id common.PropertyID) string

GetProperty gets a property value by ID.

func (*SpeechConfig) GetPropertyByString

func (config *SpeechConfig) GetPropertyByString(name string) string

GetPropertyByString gets a property value by string.

func (*SpeechConfig) OutputFormat

func (config *SpeechConfig) OutputFormat() common.OutputFormat

OutputFormat is result output format.

func (*SpeechConfig) Region

func (config *SpeechConfig) Region() string

Region is the region key that used to create Speech Recognizer or Intent Recognizer or Translation Recognizer or Speech Synthesizer.

func (*SpeechConfig) RequestWordLevelTimestamps

func (config *SpeechConfig) RequestWordLevelTimestamps() error

RequestWordLevelTimestamps includes word-level timestamps in response result.

func (*SpeechConfig) SetAuthorizationToken

func (config *SpeechConfig) SetAuthorizationToken(authToken string) error

SetAuthorizationToken sets the authorization token to connect to 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. 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.

func (*SpeechConfig) SetEndpointID

func (config *SpeechConfig) SetEndpointID(endpointID string) error

SetEndpointID sets the endpoint ID

func (*SpeechConfig) SetOutputFormat

func (config *SpeechConfig) SetOutputFormat(outputFormat common.OutputFormat) error

SetOutputFormat sets output format.

func (*SpeechConfig) SetProfanity

func (config *SpeechConfig) SetProfanity(profanity common.ProfanityOption) error

SetProfanity sets profanity option.

func (*SpeechConfig) SetProperty

func (config *SpeechConfig) SetProperty(id common.PropertyID, value string) error

SetProperty sets a property value by ID.

func (*SpeechConfig) SetPropertyByString

func (config *SpeechConfig) SetPropertyByString(name string, value string) error

SetPropertyByString sets a property value by string.

func (*SpeechConfig) SetProxy

func (config *SpeechConfig) SetProxy(hostname string, port uint64) error

SetProxy sets proxy configuration

Note: Proxy functionality is not available on macOS. This function will have no effect on this platform.

func (*SpeechConfig) SetProxyWithUsernameAndPassword

func (config *SpeechConfig) SetProxyWithUsernameAndPassword(hostname string, port uint64, username string, password string) error

SetProxyWithUsernameAndPassword sets proxy configuration with username and password

Note: Proxy functionality is not available on macOS. This function will have no effect on this platform.

func (*SpeechConfig) SetServiceProperty

func (config *SpeechConfig) SetServiceProperty(name string, value string, channel common.ServicePropertyChannel) error

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

func (*SpeechConfig) SetSpeechRecognitionLanguage

func (config *SpeechConfig) SetSpeechRecognitionLanguage(language string) error

SetSpeechRecognitionLanguage sets the input language to the speech recognizer.

func (*SpeechConfig) SetSpeechSynthesisLanguage

func (config *SpeechConfig) SetSpeechSynthesisLanguage(language string) error

SetSpeechSynthesisLanguage sets the language of the speech synthesizer.

func (*SpeechConfig) SetSpeechSynthesisOutputFormat

func (config *SpeechConfig) SetSpeechSynthesisOutputFormat(format common.SpeechSynthesisOutputFormat) error

SetSpeechSynthesisOutputFormat sets the speech synthesis output format (e.g. Riff16Khz16BitMonoPcm).

func (*SpeechConfig) SetSpeechSynthesisVoiceName

func (config *SpeechConfig) SetSpeechSynthesisVoiceName(voiceName string) error

SetSpeechSynthesisVoiceName sets the voice of the speech synthesizer.

func (*SpeechConfig) SpeechRecognitionLanguage

func (config *SpeechConfig) SpeechRecognitionLanguage() string

SpeechRecognitionLanguage is the input language to the speech recognition. The language is specified in BCP-47 format.

func (*SpeechConfig) SpeechSynthesisLanguage

func (config *SpeechConfig) SpeechSynthesisLanguage() string

SpeechSynthesisLanguage is the language of the speech synthesizer.

func (*SpeechConfig) SpeechSynthesisOutputFormat

func (config *SpeechConfig) SpeechSynthesisOutputFormat() string

SpeechSynthesisOutputFormat is the speech synthesis output format.

func (*SpeechConfig) SpeechSynthesisVoiceName

func (config *SpeechConfig) SpeechSynthesisVoiceName() string

SpeechSynthesisVoiceName is the voice of the speech synthesizer.

func (*SpeechConfig) SubscriptionKey

func (config *SpeechConfig) SubscriptionKey() string

SubscriptionKey is the subscription key that is used to create Speech Recognizer or Intent Recognizer or Translation Recognizer or Speech Synthesizer

type SpeechRecognitionCanceledEventArgs

type SpeechRecognitionCanceledEventArgs struct {
	SpeechRecognitionEventArgs
	Reason       common.CancellationReason
	ErrorCode    common.CancellationErrorCode
	ErrorDetails string
}

SpeechRecognitionCanceledEventArgs represents speech recognition canceled event arguments.

func NewSpeechRecognitionCanceledEventArgsFromHandle

func NewSpeechRecognitionCanceledEventArgsFromHandle(handle common.SPXHandle) (*SpeechRecognitionCanceledEventArgs, error)

NewSpeechRecognitionCanceledEventArgsFromHandle creates the object from the handle (for internal use)

type SpeechRecognitionCanceledEventHandler

type SpeechRecognitionCanceledEventHandler func(event SpeechRecognitionCanceledEventArgs)

SpeechRecognitionCanceledEventHandler is the type of the event handler that receives SpeechRecognitionCanceledEventArgs

type SpeechRecognitionEventArgs

type SpeechRecognitionEventArgs struct {
	RecognitionEventArgs

	Result SpeechRecognitionResult
	// contains filtered or unexported fields
}

SpeechRecognitionEventArgs represents the speech recognition event arguments.

func NewSpeechRecognitionEventArgsFromHandle

func NewSpeechRecognitionEventArgsFromHandle(handle common.SPXHandle) (*SpeechRecognitionEventArgs, error)

NewSpeechRecognitionEventArgsFromHandle creates the object from the handle (for internal use)

func (SpeechRecognitionEventArgs) Close

func (event SpeechRecognitionEventArgs) Close()

Close releases the underlying resources

type SpeechRecognitionEventHandler

type SpeechRecognitionEventHandler func(event SpeechRecognitionEventArgs)

SpeechRecognitionEventHandler is the type of the event handler that receives SpeechRecognitionEventArgs

type SpeechRecognitionOutcome

type SpeechRecognitionOutcome struct {
	common.OperationOutcome

	// Result is the result of the operation
	Result *SpeechRecognitionResult
}

SpeechRecognitionOutcome is a wrapper type to be returned by operations returning SpeechRecognitionResult and error

func (SpeechRecognitionOutcome) Close

func (outcome SpeechRecognitionOutcome) Close()

Close releases the underlying resources

type SpeechRecognitionResult

type SpeechRecognitionResult struct {

	// ResultID specifies the result identifier.
	ResultID string

	// Reason specifies status of speech recognition result.
	Reason common.ResultReason

	// Text presents the recognized text in the result.
	Text string

	// Duration of the recognized speech.
	Duration time.Duration

	// Offset of the recognized speech in ticks.
	Offset time.Duration

	// Collection of additional RecognitionResult properties.
	Properties common.PropertyCollection
	// contains filtered or unexported fields
}

SpeechRecognitionResult contains detailed information about result of a recognition operation.

func NewSpeechRecognitionResultFromHandle

func NewSpeechRecognitionResultFromHandle(handle common.SPXHandle) (*SpeechRecognitionResult, error)

NewSpeechRecognitionResultFromHandle creates a SpeechRecognitionResult from a handle (for internal use)

func (SpeechRecognitionResult) Close

func (result SpeechRecognitionResult) Close()

Close releases the underlying resources

type SpeechRecognizer

type SpeechRecognizer struct {
	Properties common.PropertyCollection
	// contains filtered or unexported fields
}

SpeechRecognizer is the class for speech recognizers.

func NewSpeechRecognizerFomAutoDetectSourceLangConfig

func NewSpeechRecognizerFomAutoDetectSourceLangConfig(config *SpeechConfig, langConfig *AutoDetectSourceLanguageConfig, audioConfig *audio.AudioConfig) (*SpeechRecognizer, error)

NewSpeechRecognizerFomAutoDetectSourceLangConfig creates a speech recognizer from a speech config, auto detection source language config and audio config

func NewSpeechRecognizerFromConfig

func NewSpeechRecognizerFromConfig(config *SpeechConfig, audioConfig *audio.AudioConfig) (*SpeechRecognizer, error)

NewSpeechRecognizerFromConfig creates a speech recognizer from a speech config and audio config.

func NewSpeechRecognizerFromSourceLanguage

func NewSpeechRecognizerFromSourceLanguage(config *SpeechConfig, sourceLanguage string, audioConfig *audio.AudioConfig) (*SpeechRecognizer, error)

NewSpeechRecognizerFromSourceLanguage creates a speech recognizer from a speech config, source language and audio config

func NewSpeechRecognizerFromSourceLanguageConfig

func NewSpeechRecognizerFromSourceLanguageConfig(config *SpeechConfig, sourceLanguageConfig *SourceLanguageConfig, audioConfig *audio.AudioConfig) (*SpeechRecognizer, error)

NewSpeechRecognizerFromSourceLanguageConfig creates a speech recognizer from a speech config, source language config and audio config

func (SpeechRecognizer) AuthorizationToken

func (recognizer SpeechRecognizer) AuthorizationToken() string

AuthorizationToken is the authorization token.

func (SpeechRecognizer) Canceled

func (recognizer SpeechRecognizer) Canceled(handler SpeechRecognitionCanceledEventHandler)

Canceled signals for events containing canceled recognition results (indicating a recognition attempt that was canceled as a result or a direct cancellation request or, alternatively, a transport or protocol failure).

func (SpeechRecognizer) Close

func (recognizer SpeechRecognizer) Close()

Close disposes the associated resources.

func (SpeechRecognizer) GetEndpointID

func (recognizer SpeechRecognizer) GetEndpointID() string

GetEndpointID gets the endpoint ID of a customized speech model that is used for speech recognition.

func (SpeechRecognizer) RecognizeOnceAsync

func (recognizer SpeechRecognizer) RecognizeOnceAsync() chan SpeechRecognitionOutcome

RecognizeOnceAsync starts speech recognition, and returns after a single utterance is recognized. The end of a single utterance is determined by listening for silence at the end or until a maximum of 15 seconds of audio is processed. The task returns the recognition text as result. Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single shot recognition like command or query. For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.

func (SpeechRecognizer) Recognized

func (recognizer SpeechRecognizer) Recognized(handler SpeechRecognitionEventHandler)

Recognized signals for events containing final recognition results. (indicating a successful recognition attempt).

func (SpeechRecognizer) Recognizing

func (recognizer SpeechRecognizer) Recognizing(handler SpeechRecognitionEventHandler)

Recognizing signals for events containing intermediate recognition results.

func (SpeechRecognizer) SessionStarted

func (recognizer SpeechRecognizer) SessionStarted(handler SessionEventHandler)

SessionStarted signals events indicating the start of a recognition session (operation).

func (SpeechRecognizer) SessionStopped

func (recognizer SpeechRecognizer) SessionStopped(handler SessionEventHandler)

SessionStopped signals events indicating the end of a recognition session (operation).

func (SpeechRecognizer) SetAuthorizationToken

func (recognizer SpeechRecognizer) SetAuthorizationToken(token string) error

SetAuthorizationToken sets the authorization token that will be used for connecting to 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 recognizer will encounter errors during recognition.

func (SpeechRecognizer) SpeechEndDetected

func (recognizer SpeechRecognizer) SpeechEndDetected(handler RecognitionEventHandler)

SpeechEndDetected signals for events indicating the end of speech.

func (SpeechRecognizer) SpeechStartDetected

func (recognizer SpeechRecognizer) SpeechStartDetected(handler RecognitionEventHandler)

SpeechStartDetected signals for events indicating the start of speech.

func (SpeechRecognizer) StartContinuousRecognitionAsync

func (recognizer SpeechRecognizer) StartContinuousRecognitionAsync() chan error

StartContinuousRecognitionAsync asynchronously initiates continuous speech recognition operation.

func (SpeechRecognizer) StartKeywordRecognitionAsync

func (recognizer SpeechRecognizer) StartKeywordRecognitionAsync(model KeywordRecognitionModel) chan error

StartKeywordRecognitionAsync asynchronously initiates keyword recognition operation.

func (SpeechRecognizer) StopContinuousRecognitionAsync

func (recognizer SpeechRecognizer) StopContinuousRecognitionAsync() chan error

StopContinuousRecognitionAsync asynchronously terminates ongoing continuous speech recognition operation.

func (SpeechRecognizer) StopKeywordRecognitionAsync

func (recognizer SpeechRecognizer) StopKeywordRecognitionAsync() chan error

StopKeywordRecognitionAsync asynchronously terminates keyword recognition operation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL