client

package
v0.0.0-...-fd181a3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package client wraps the transcribe proto client and implements the interface transcribepb.TranscribeServiceClient that can use GRPC to receive results from Transcribe server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

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

func (*Client) Close

func (c *Client) Close() error

func (*Client) CompileContext

func (c *Client) CompileContext(ctx context.Context,
	modelID, token string, phrases []*transcribepb.ContextPhrase) (*transcribepb.CompiledContext, error)

CompileContext compiles recognition context information, such as a specialized list of words or phrases, into a compact, efficient form to send with subsequent `StreamingRecognize` requests to customize speech recognition. For example, a list of contact names may be compiled in a mobile app and sent with each recognition request so that the app user's contact names are more likely to be recognized than arbitrary names. This pre-compilation ensures that there is no added latency for the recognition request. It is important to note that in order to compile context for a model, that model has to support context in the first place, which can be verified by checking its `ModelAttributes.ContextInfo` obtained via the `ListModels` method. Also, the compiled data will be model specific; that is, the data compiled for one model will generally not be usable with a different model.

func (*Client) ListModels

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

ListModels retrieves a list of available speech recognition models.

func (*Client) StreamingRecognize

func (c *Client) StreamingRecognize(ctx context.Context,
	cfg *transcribepb.RecognitionConfig,
	audio io.Reader, handler RecognitionResponseHandler) error

StreamingRecognize wraps the bidirectional streaming API for performing speech recognition. It sets up recognition using the given cfg. Data is read from the given audio reader into a buffer and streamed to Transcribe server. As results are received from Transcribe server, they will be sent to the provided handlerFunc. If any error occurs while reading the audio or sending it to the server, this method will immediately exit, returning that error. This function returns only after all results have been passed to the resultHandler.

func (*Client) Versions

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

Versions queries the version of the server.

type Option

type Option func(*clientArgs) error

Option configures how we setup the connection with a server.

func WithContext

func WithContext(ctx context.Context) Option

WithContext returns an Option that sets up context.Context to use for GRPC client connection.

func WithInsecure

func WithInsecure() Option

WithInsecure returns an Option that sets up Client without using TLS enable.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger returns an Option that sets up Client logger.

func WithStreamingBufferSize

func WithStreamingBufferSize(n uint32) Option

WithStreamingBufferSize returns an Option that sets up the buffer size (bytes) of each message sent from the Client to the server during streaming GRPC calls. Use this only if Cobalt recommends you to do so. A value n>0 is required.

type RecognitionResponseHandler

type RecognitionResponseHandler func(*transcribepb.StreamingRecognizeResponse)

RecognitionResponseHandler is a type of callback function that will be called when the `StreamingRecognize` method is running. For each response received from transcribe server, this method will be called once. The provided RecognitionResponse is guaranteed to be non-nil. Since this function is executed as part of the streaming process, it should preferably return quickly and certainly not block.

Jump to

Keyboard shortcuts

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