websocketv1

package
v1.7.0-dev.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

This package provides the live/streaming client implementation for the Deepgram API

This package provides the live/streaming client implementation for the Deepgram API

Index

Constants

View Source
const (
	DefaultConnectRetry int64 = 3

	ChunkSize        = 1024 * 2
	TerminationSleep = 100 * time.Millisecond
)

external constants

View Source
const (
	// MessageTypeKeepAlive keep the connection alive
	MessageTypeKeepAlive string = "KeepAlive"

	// MessageTypeFinalize flushes the transcription from the server
	MessageTypeFinalize string = "Finalize"
)
View Source
const (
	PackageVersion string = "v1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client = WSCallback

Client is an alias for WSCallback Deprecated: use WSCallback instead

type WSCallback added in v1.6.0

type WSCallback struct {
	*common.WSClient
	// contains filtered or unexported fields
}

WSCallback is a struct representing the websocket client connection using callbacks

func New deprecated

New creates a new websocket connection with the specified options

Input parameters: - ctx: context.Context object - apiKey: string containing the Deepgram API key - cOptions: ClientOptions which allows overriding things like hostname, version of the API, etc. - tOptions: LiveTranscriptionOptions which allows overriding things like language, model, etc. - callback: LiveMessageCallback which is a callback that allows you to perform actions based on the transcription

Deprecated: Use NewUsingCallback instead

func NewForDemo deprecated

********************************* Deprecated functions *********************************

NewForDemo creates a new websocket connection with all default options

Notes:

  • The Deepgram API KEY is read from the environment variable DEEPGRAM_API_KEY

Deprecated: Use NewUsingCallbackForDemo instead

func NewUsingCallback added in v1.6.0

New creates a new websocket connection with the specified options

Input parameters: - ctx: context.Context object - apiKey: string containing the Deepgram API key - cOptions: ClientOptions which allows overriding things like hostname, version of the API, etc. - tOptions: LiveTranscriptionOptions which allows overriding things like language, model, etc. - callback: LiveMessageCallback which is a callback that allows you to perform actions based on the transcription

func NewUsingCallbackForDemo added in v1.6.0

func NewUsingCallbackForDemo(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions) (*WSCallback, error)

NewForDemo creates a new websocket connection with all default options

Notes:

  • The Deepgram API KEY is read from the environment variable DEEPGRAM_API_KEY

func NewUsingCallbackWithCancel added in v1.6.0

func NewUsingCallbackWithCancel(ctx context.Context, ctxCancel context.CancelFunc, apiKey string, cOptions *clientinterfaces.ClientOptions, tOptions *clientinterfaces.LiveTranscriptionOptions, callback msginterfaces.LiveMessageCallback) (*WSCallback, error)

New creates a new websocket connection with the specified options

Input parameters: - ctx: context.Context object - ctxCancel: allow passing in own cancel - apiKey: string containing the Deepgram API key - cOptions: ClientOptions which allows overriding things like hostname, version of the API, etc. - tOptions: LiveTranscriptionOptions which allows overriding things like language, model, etc. - callback: LiveMessageCallback which is a callback that allows you to perform actions based on the transcription

func NewUsingCallbackWithDefaults added in v1.6.0

func NewUsingCallbackWithDefaults(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions, callback msginterfaces.LiveMessageCallback) (*WSCallback, error)

NewWithDefaults creates a new websocket connection with all default options

Notes:

  • The Deepgram API KEY is read from the environment variable DEEPGRAM_API_KEY
  • The callback handler is set to the default handler which just prints all messages to the console

func NewWithDefaults deprecated

NewWithDefaults creates a new websocket connection with all default options

Notes:

  • The Deepgram API KEY is read from the environment variable DEEPGRAM_API_KEY
  • The callback handler is set to the default handler which just prints all messages to the console

Deprecated: Use NewUsingCallbackWithDefaults instead

func (*WSCallback) AttemptReconnect added in v1.6.0

func (c *WSCallback) AttemptReconnect(ctx context.Context, retries int64) bool

AttemptReconnect performs a reconnect after failing retries

func (*WSCallback) AttemptReconnectWithCancel added in v1.6.0

func (c *WSCallback) AttemptReconnectWithCancel(ctx context.Context, ctxCancel context.CancelFunc, retries int64) bool

AttemptReconnect performs a reconnect after failing retries and providing a cancel function

func (*WSCallback) Connect added in v1.6.0

func (c *WSCallback) Connect() bool

Connect performs a websocket connection with "DefaultConnectRetry" number of retries.

func (*WSCallback) ConnectWithCancel added in v1.6.0

func (c *WSCallback) ConnectWithCancel(ctx context.Context, ctxCancel context.CancelFunc, retryCnt int) bool

ConnectWithCancel performs a websocket connection with specified number of retries and providing a cancel function to stop the connection

func (*WSCallback) Finalize added in v1.6.0

func (c *WSCallback) Finalize() error

Finalize the live transcription utterance/sentence/fragment

func (*WSCallback) Finish added in v1.6.0

func (c *WSCallback) Finish()

Finish the callback

func (*WSCallback) GetCloseMsg added in v1.6.0

func (c *WSCallback) GetCloseMsg() []byte

GetCloseMsg sends an application level message to Deepgram

func (*WSCallback) GetURL added in v1.6.0

func (c *WSCallback) GetURL(host string) (string, error)

GetURL returns the websocket URL

func (*WSCallback) KeepAlive added in v1.6.0

func (c *WSCallback) KeepAlive() error

Kick off the keepalive message to the server

func (*WSCallback) ProcessError added in v1.6.0

func (c *WSCallback) ProcessError(err error) error

ProcessError processes the error

func (*WSCallback) ProcessMessage added in v1.6.0

func (c *WSCallback) ProcessMessage(wsType int, byMsg []byte) error

ProcessMessage processes the incoming message

func (*WSCallback) Start added in v1.6.0

func (c *WSCallback) Start()

Start the callback

func (*WSCallback) Stream added in v1.6.0

func (c *WSCallback) Stream(r io.Reader) error

Stream is a helper function to stream audio data from a io.Reader object to deepgram

func (*WSCallback) Write added in v1.6.0

func (c *WSCallback) Write(p []byte) (int, error)

Write performs the lower level websocket write operation. This is needed to implement the io.Writer interface. (aka the streaming interface)

type WSChannel added in v1.6.0

type WSChannel struct {
	*common.WSClient
	// contains filtered or unexported fields
}

WSChannel is a struct representing the websocket client connection using channels

func NewUsingChan added in v1.6.0

New creates a new websocket connection with the specified options

Input parameters: - ctx: context.Context object - apiKey: string containing the Deepgram API key - cOptions: ClientOptions which allows overriding things like hostname, version of the API, etc. - tOptions: LiveTranscriptionOptions which allows overriding things like language, model, etc. - chans: LiveMessageCallback which is a chans that allows you to perform actions based on the transcription

func NewUsingChanForDemo added in v1.6.0

func NewUsingChanForDemo(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions) (*WSChannel, error)

NewForDemo creates a new websocket connection with all default options

Notes:

  • The Deepgram API KEY is read from the environment variable DEEPGRAM_API_KEY

func NewUsingChanWithCancel added in v1.6.0

func NewUsingChanWithCancel(ctx context.Context, ctxCancel context.CancelFunc, apiKey string, cOptions *clientinterfaces.ClientOptions, tOptions *clientinterfaces.LiveTranscriptionOptions, chans msginterfaces.LiveMessageChan) (*WSChannel, error)

New creates a new websocket connection with the specified options

Input parameters: - ctx: context.Context object - ctxCancel: allow passing in own cancel - apiKey: string containing the Deepgram API key - cOptions: ClientOptions which allows overriding things like hostname, version of the API, etc. - tOptions: LiveTranscriptionOptions which allows overriding things like language, model, etc. - chans: LiveMessageCallback which is a chans that allows you to perform actions based on the transcription

func NewUsingChanWithDefaults added in v1.6.0

func NewUsingChanWithDefaults(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions, chans msginterfaces.LiveMessageChan) (*WSChannel, error)

NewWithDefaults creates a new websocket connection with all default options

Notes:

  • The Deepgram API KEY is read from the environment variable DEEPGRAM_API_KEY
  • The chans handler is set to the default handler which just prints all messages to the console

func (*WSChannel) AttemptReconnect added in v1.6.0

func (c *WSChannel) AttemptReconnect(ctx context.Context, retries int64) bool

AttemptReconnect performs a reconnect after failing retries

func (*WSChannel) AttemptReconnectWithCancel added in v1.6.0

func (c *WSChannel) AttemptReconnectWithCancel(ctx context.Context, ctxCancel context.CancelFunc, retries int64) bool

AttemptReconnect performs a reconnect after failing retries and providing a cancel function

func (*WSChannel) Connect added in v1.6.0

func (c *WSChannel) Connect() bool

Connect performs a websocket connection with "DefaultConnectRetry" number of retries.

func (*WSChannel) ConnectWithCancel added in v1.6.0

func (c *WSChannel) ConnectWithCancel(ctx context.Context, ctxCancel context.CancelFunc, retryCnt int) bool

ConnectWithCancel performs a websocket connection with specified number of retries and providing a cancel function to stop the connection

func (*WSChannel) Finalize added in v1.6.0

func (c *WSChannel) Finalize() error

Finalize the live transcription utterance/sentence/fragment

func (*WSChannel) Finish added in v1.6.0

func (c *WSChannel) Finish()

Finish the websocket connection

func (*WSChannel) GetCloseMsg added in v1.6.0

func (c *WSChannel) GetCloseMsg() []byte

GetCloseMsg sends an application level message to Deepgram

func (*WSChannel) GetURL added in v1.6.0

func (c *WSChannel) GetURL(host string) (string, error)

GetURL returns the websocket URL

func (*WSChannel) KeepAlive added in v1.6.0

func (c *WSChannel) KeepAlive() error

Kick off the keepalive message to the server

func (*WSChannel) ProcessError added in v1.6.0

func (c *WSChannel) ProcessError(err error) error

ProcessError processes the error and sends it to the callback

func (*WSChannel) ProcessMessage added in v1.6.0

func (c *WSChannel) ProcessMessage(wsType int, byMsg []byte) error

ProcessMessage processes the message and sends it to the callback

func (*WSChannel) Start added in v1.6.0

func (c *WSChannel) Start()

Start the keepalive and flush threads

func (*WSChannel) Stream added in v1.6.0

func (c *WSChannel) Stream(r io.Reader) error

Stream is a helper function to stream audio data from a io.Reader object to deepgram

func (*WSChannel) Write added in v1.6.0

func (c *WSChannel) Write(p []byte) (int, error)

Write performs the lower level websocket write operation. This is needed to implement the io.Writer interface. (aka the streaming interface)

Jump to

Keyboard shortcuts

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