diatheke

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: Apache-2.0 Imports: 7 Imported by: 4

Documentation

Overview

Package diatheke provides an interface to interact with Diatheke server using gRPC.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ASRStream

type ASRStream struct {
	PBStream diathekepb.Diatheke_StreamASRClient
}

ASRStream is a bi-directional stream that allows audio data to be pushed to the server, while transcription results are streamed back to the client. Audio pushed to an ASRStream does not contribute to any currently running sessions and their dialogs. It is mainly useful for cases where the client only wants a transcription without any other interactions with Diatheke.

func (*ASRStream) AudioFinished

func (asr *ASRStream) AudioFinished() error

AudioFinished notifies Diatheke that no more audio is coming from the client.

func (*ASRStream) Receive

func (asr *ASRStream) Receive() (*diathekepb.ASRResponse, error)

Receive waits for a transcript from the server.

func (*ASRStream) Write

func (asr *ASRStream) Write(p []byte) (n int, err error)

Write the given audio data to the stream.

type AudioInputStream

type AudioInputStream struct {
	PBStream diathekepb.Diatheke_StreamAudioInputClient
}

AudioInputStream allows audio to be pushed to the server for a session. The audio pushed to this stream will contribute to the session's current dialog. Transcriptions are returned as Recognize events on the session's event stream.

func (*AudioInputStream) Finish

func (ais *AudioInputStream) Finish() error

Finish notifies Diatheke that no more audio is coming from the client.

func (*AudioInputStream) Write

func (ais *AudioInputStream) Write(p []byte) (n int, err error)

Write the given audio data to the stream.

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

func NewClient(addr string, opts ...Option) (*Client, error)

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

func (c *Client) Close() error

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

func (c *Client) CommandFinished(ctx context.Context, commandStatus *diathekepb.CommandStatus) error

CommandFinished notifies the server that a command has completed. This should be called after receiving a command event in the session's event stream, as required by the Diatheke model.

func (*Client) DiathekeVersion

func (c *Client) DiathekeVersion(ctx context.Context) (string, error)

DiathekeVersion queries the Diatheke server for its version.

func (*Client) EndSession

func (c *Client) EndSession(ctx context.Context, sessionID string) error

EndSession ends an existing session.

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context) ([]string, error)

ListModels queries the server for the list of currently loaded Diatheke models.

func (*Client) NewSession

func (c *Client) NewSession(ctx context.Context, model string) (string, error)

NewSession creates a new session and returns the session id.

func (*Client) PushText

func (c *Client) PushText(ctx context.Context, sessionID, text string) error

PushText sends the given text to Diatheke as part of a conversation for the given session.

func (*Client) SessionEventStream

func (c *Client) SessionEventStream(ctx context.Context, sessionID string) (diathekepb.Diatheke_SessionEventStreamClient, error)

SessionEventStream returns a new event stream for the given session ID.

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

func (c *Client) StreamASR(ctx context.Context, model string) (*ASRStream, error)

StreamASR runs streaming speech recognition unrelated to a session, using the specified ASR model.

func (*Client) StreamAudioInput

func (c *Client) StreamAudioInput(ctx context.Context, sessionID string) (*AudioInputStream, error)

StreamAudioInput returns a stream object that may be used to push audio data to the Diatheke server for the given session. Only one stream per session should be running concurrently.

func (*Client) StreamAudioReplies

func (c *Client) StreamAudioReplies(ctx context.Context, sessionID string) (diathekepb.Diatheke_StreamAudioRepliesClient, error)

StreamAudioReplies returns a stream object that receives output audio from Diatheke specifically for the given session. The stream will include start and end messages to indicate when a section of audio for a group of text begins and ends.

func (*Client) StreamTTS

func (c *Client) StreamTTS(ctx context.Context, model, text string) (diathekepb.Diatheke_StreamTTSClient, error)

StreamTTS runs streaming text-to-speech unrelated to a session. It synthesizes speech for the given text, using the specified TTS model. To create a stream that can be cancelled by the client, use the context.WithCancel() function to create a new context and context.CancelFunc. Pass the new context to this function, and the stream will end when the corresponding CancelFunc is called.

type Option

type Option func(*Client) error

Option configures how we setup the connection with a server.

func WithClientCert

func WithClientCert(certPem []byte, keyPem []byte) Option

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

func WithServerCert(cert []byte) Option

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 Session

type Session struct {
	ID     string
	Parent *Client
}

Session represents a Diatheke session. It is a wrapper around diatheke.Client, provided as a convenience for working with methods that require a session ID.

func (*Session) CommandFinished

func (sess *Session) CommandFinished(ctx context.Context, status *diathekepb.CommandStatus) error

CommandFinished notifies the server that a command has completed. This should be called after receiving a command event in the session's event stream, as required by the Diatheke model.

func (*Session) EndSession

func (sess *Session) EndSession(ctx context.Context) error

EndSession ends this session.

func (*Session) EventStream

EventStream returns a new event stream for this session.

func (*Session) PushText

func (sess *Session) PushText(ctx context.Context, text string) error

PushText sends the given text to Diatheke as part of a conversation for this session.

func (*Session) StreamAudioInput

func (sess *Session) StreamAudioInput(ctx context.Context) (*AudioInputStream, error)

StreamAudioInput returns a stream object that may be used to push audio data to the Diatheke server for this session. Only one stream per session should be running concurrently.

func (*Session) StreamAudioReplies

func (sess *Session) StreamAudioReplies(ctx context.Context) (diathekepb.Diatheke_StreamAudioRepliesClient, error)

StreamAudioReplies returns a stream object that receives output audio from Diatheke specifically for this session. The stream will include start and end messages to indicate when a section of audio for a group of text begins and ends.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL