Documentation ¶
Overview ¶
Package diatheke provides an interface to interact with Diatheke server using gRPC.
Index ¶
- func ReadASRAudio(stream *ASRStream, reader io.Reader, buffSize int) (*diathekepb.ASRResult, error)
- func ReadTranscribeAudio(stream *TranscribeStream, reader io.Reader, bytesBuffSize int, ...) error
- func WriteTTSAudio(stream *TTSStream, writer io.Writer) error
- type ASRStream
- type Client
- func (c *Client) AppendCallOptions(opts ...grpc.CallOption)
- func (c *Client) Close() error
- func (c *Client) CreateSession(ctx context.Context, model string) (*diathekepb.SessionOutput, error)
- func (c *Client) CreateSessionWithWakeWord(ctx context.Context, model, wakeword string) (*diathekepb.SessionOutput, error)
- func (c *Client) DeleteSession(ctx context.Context, token *diathekepb.TokenData) error
- func (c *Client) ListModels(ctx context.Context) (*diathekepb.ListModelsResponse, error)
- func (c *Client) NewSessionASRStream(ctx context.Context, token *diathekepb.TokenData) (*ASRStream, error)
- func (c *Client) NewTTSStream(ctx context.Context, reply *diathekepb.ReplyAction) (*TTSStream, error)
- func (c *Client) NewTranscribeStream(ctx context.Context, action *diathekepb.TranscribeAction) (*TranscribeStream, error)
- func (c *Client) ProcessASRResult(ctx context.Context, token *diathekepb.TokenData, result *diathekepb.ASRResult) (*diathekepb.SessionOutput, error)
- func (c *Client) ProcessCommandResult(ctx context.Context, token *diathekepb.TokenData, ...) (*diathekepb.SessionOutput, error)
- func (c *Client) ProcessText(ctx context.Context, token *diathekepb.TokenData, text string) (*diathekepb.SessionOutput, error)
- func (c *Client) SetCallOptions(opts ...grpc.CallOption)
- func (c *Client) SetStory(ctx context.Context, token *diathekepb.TokenData, storyID string, ...) (*diathekepb.SessionOutput, error)
- func (c *Client) Version(ctx context.Context) (*diathekepb.VersionResponse, error)
- type Option
- type TTSStream
- type TranscribeResultHandler
- type TranscribeStream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadASRAudio ¶
func ReadASRAudio( stream *ASRStream, reader io.Reader, buffSize int, ) (*diathekepb.ASRResult, error)
ReadASRAudio is a convenience function to send audio from the given reader to the stream until a result is returned. If an error is encountered no result will be returned.
func ReadTranscribeAudio ¶ added in v2.1.0
func ReadTranscribeAudio( stream *TranscribeStream, reader io.Reader, bytesBuffSize int, handler TranscribeResultHandler, ) error
ReadTranscribeAudio is a convenience function to send audio from the given reader to the stream. Results are processed by the given handler as they come. This function will block until the stream ends, either because the server closed it, or the reader returned io.EOF, or there was an error.
Types ¶
type ASRStream ¶
type ASRStream struct {
PBStream diathekepb.Diatheke_StreamASRClient
}
ASRStream represents a stream of data sent from the client to Diatheke for the purpose of speech recognition.
func (*ASRStream) Result ¶
func (asr *ASRStream) Result() (*diathekepb.ASRResult, error)
Result returns the result of speech recognition. This function may be called to end the audio stream early, which will force a transcription based on the audio received until this point, or in response to receiving an io.EOF error from PushAudio.
func (*ASRStream) SendAudio ¶
SendAudio to Diatheke for transcription. If the returned error is io.EOF, the stream has already been closed by the server and Result() should be called to get the final result.
func (*ASRStream) SendToken ¶
func (asr *ASRStream) SendToken(token *diathekepb.TokenData) error
SendToken passes the given session token to Diatheke to update the speech recognition context. The session token must first be sent on the ASR stream before any audio will be recognized. If the stream was created using client.NewSessionASRStream(), the first token was already sent.
If the returned error is io.EOF, the Result() function should be called to get the final ASR result.
type Client ¶
type Client struct { // The protobuf-defined client. Most users will not need to call this // directly, but is exposed as a convenience for advanced users who // wish to use gRPC functionality beyond what this interface provides. PBClient diathekepb.DiathekeClient // The list of gRPC call options that are used when the client // makes server requests. CallOpts []grpc.CallOption // contains filtered or unexported fields }
Client is an object for interacting with the Diatheke gRPC API.
All methods except Close may be called concurrently.
func NewClient ¶
NewClient creates a new Client that connects to a Diatheke Server listening on the provided address. Transport security is enabled by default. Use Options to override default settings if necessary.
func (*Client) AppendCallOptions ¶
func (c *Client) AppendCallOptions(opts ...grpc.CallOption)
AppendCallOptions adds the given gRPC call options to the current list of options to use when making server requests. It does not check to see if the options are unique in the final list.
func (*Client) Close ¶
Close closes the connection to the API service. The user should only invoke this when the client is no longer needed. Pending or in-progress calls to other methods may fail with an error if Close is called, and any subsequent calls with this client will also fail.
func (*Client) CreateSession ¶
func (c *Client) CreateSession( ctx context.Context, model string) (*diathekepb.SessionOutput, error)
CreateSession creates a new Diatheke session using the specified model.
func (*Client) CreateSessionWithWakeWord ¶ added in v2.1.0
func (c *Client) CreateSessionWithWakeWord( ctx context.Context, model, wakeword string) (*diathekepb.SessionOutput, error)
CreateSessionWithWakeWord creates a new Diatheke session with a custom wakeword.
func (*Client) DeleteSession ¶
DeleteSession cleans up the given token. Behavior is undefined if the given token is used again after calling this function.
func (*Client) ListModels ¶
func (c *Client) ListModels(ctx context.Context) (*diathekepb.ListModelsResponse, error)
ListModels returns a list of Diatheke models available to the server.
func (*Client) NewSessionASRStream ¶
func (c *Client) NewSessionASRStream( ctx context.Context, token *diathekepb.TokenData, ) (*ASRStream, error)
NewSessionASRStream creates a new stream to transcribe audio for the given session Token.
func (*Client) NewTTSStream ¶
func (c *Client) NewTTSStream( ctx context.Context, reply *diathekepb.ReplyAction, ) (*TTSStream, error)
NewTTSStream creates a new stream to receive TTS audio from Diatheke based on the given ReplyAction.
func (*Client) NewTranscribeStream ¶ added in v2.1.0
func (c *Client) NewTranscribeStream( ctx context.Context, action *diathekepb.TranscribeAction, ) (*TranscribeStream, error)
NewTranscribe stream creates a new stream for audio transcription unrelated to a session's state.
func (*Client) ProcessASRResult ¶
func (c *Client) ProcessASRResult( ctx context.Context, token *diathekepb.TokenData, result *diathekepb.ASRResult, ) (*diathekepb.SessionOutput, error)
ProcessASRResult sends the given ASR result to Diatheke and returns an updated session token.
func (*Client) ProcessCommandResult ¶
func (c *Client) ProcessCommandResult( ctx context.Context, token *diathekepb.TokenData, result *diathekepb.CommandResult, ) (*diathekepb.SessionOutput, error)
ProcessCommandResult sends the given command result to Diatheke and returns an updated session token. This function should be called in response to a command action Diatheke sent previously.
func (*Client) ProcessText ¶
func (c *Client) ProcessText( ctx context.Context, token *diathekepb.TokenData, text string, ) (*diathekepb.SessionOutput, error)
ProcessText sends the given text to Diatheke and returns an updated session token.
func (*Client) SetCallOptions ¶
func (c *Client) SetCallOptions(opts ...grpc.CallOption)
SetCallOptions replaces any current gRPC call options with the given set to use when making server requests.
func (*Client) SetStory ¶
func (c *Client) SetStory( ctx context.Context, token *diathekepb.TokenData, storyID string, params map[string]string, ) (*diathekepb.SessionOutput, error)
SetStory changes the current story for a Diatheke session. Returns and updated session token.
func (*Client) Version ¶
func (c *Client) Version(ctx context.Context) (*diathekepb.VersionResponse, error)
Version returns version information from the server.
type Option ¶
Option configures how we setup the connection with a server.
func WithClientCert ¶
WithClientCert returns an Option which sets up the given PEM certificate and key as the credentials presented by this Client when connecting to a server. Use this when setting up mutually authenticated TLS.
func WithInsecure ¶
func WithInsecure() Option
WithInsecure returns an Option which disables transport security for this Client. Use this when connecting to a non-TLS enabled diatheke server, such as during debugging.
func WithServerCert ¶
WithServerCert returns an Option which sets up the given PEM certificate as a root certificate that can validate the certificate presented by the server we are connecting to. Use this when connecting to an instance of diatheke server that is using a self-signed certificate.
type TTSStream ¶
type TTSStream struct {
PBStream diathekepb.Diatheke_StreamTTSClient
}
TTSStream represents a stream of audio data from Diatheke to the client containing synthesized speech.
func (*TTSStream) ReceiveAudio ¶
ReceiveAudio waits for the next chunk of audio data from the server. When the returned error is io.EOF, synthesis is complete and no more audio will be sent from Diatheke.
type TranscribeResultHandler ¶ added in v2.1.0
type TranscribeResultHandler func(*diathekepb.TranscribeResult)
type TranscribeStream ¶ added in v2.1.0
type TranscribeStream struct {
PBStream diathekepb.Diatheke_TranscribeClient
}
TranscribeStream represents a stream of data sent from the client to Diatheke for the purpose of transcribing speech.
func (*TranscribeStream) ReceiveResult ¶ added in v2.1.0
func (ts *TranscribeStream) ReceiveResult() (*diathekepb.TranscribeResult, error)
ReceiveResult waits for the next transcribe result from Diatheke. When the returned error is io.EOF, the stream has been closed and no more results will be sent from Diatheke.
func (*TranscribeStream) SendAction ¶ added in v2.1.0
func (ts *TranscribeStream) SendAction(action *diathekepb.TranscribeAction) error
SendAction passes the given transcribe action to Diatheke to use for speech recognition. The action must first be sent before any audio will be transcribed. If the stream was created using client.NewTranscribeStream(), the action was already sent.
func (*TranscribeStream) SendAudio ¶ added in v2.1.0
func (ts *TranscribeStream) SendAudio(audio []byte) error
SendAudio to Diatheke for transcription. If the returned error is io.EOF, the stream has already been closed by the server.
func (*TranscribeStream) SendFinished ¶ added in v2.1.0
func (ts *TranscribeStream) SendFinished() error
SendFinished informs the server that no more data will be sent over this stream. It is an error to call SendAudio() or SendAction() after calling this.