websocketv1

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

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"
)
View Source
const (
	PackageVersion string = "v1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FunctionCallResponse

type FunctionCallResponse msginterface.FunctionCallResponse

type InjectAgentMessage

type InjectAgentMessage msginterface.InjectAgentMessage

type KeepAlive

type KeepAlive msginterface.KeepAlive

type SettingsConfigurationOptions

type SettingsConfigurationOptions interfaces.SettingsConfigurationOptions

client messages

type UpdateInstructions

type UpdateInstructions msginterface.UpdateInstructions

type UpdateSpeak

type UpdateSpeak msginterface.UpdateSpeak

type WSChannel

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

WSChannel is a struct representing the websocket client connection using channels

func NewUsingChan

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: SettingsConfigurationOptions which allows overriding things like language, model, etc. - chans: AgentMessageChan which is a chans that allows you to perform actions based on the transcription

func NewUsingChanForDemo

func NewUsingChanForDemo(ctx context.Context, options *clientinterfaces.SettingsConfigurationOptions) (*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

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: SettingsConfigurationOptions which allows overriding things like language, model, etc. - chans: AgentMessageChan which is a chans that allows you to perform actions based on the transcription

func NewUsingChanWithDefaults

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

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

AttemptReconnect performs a reconnect after failing retries

func (*WSChannel) AttemptReconnectWithCancel

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

func (c *WSChannel) Connect() bool

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

func (*WSChannel) ConnectWithCancel

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

func (c *WSChannel) Finish()

Finish the websocket connection

func (*WSChannel) GetCloseMsg

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

GetCloseMsg sends an application level message to Deepgram

func (*WSChannel) GetURL

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

GetURL returns the websocket URL

func (*WSChannel) KeepAlive

func (c *WSChannel) KeepAlive() error

Kick off the keepalive message to the server

func (*WSChannel) ProcessError

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

ProcessError processes the error and sends it to the callback

func (*WSChannel) ProcessMessage

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

ProcessMessage processes the message and sends it to the callback

func (*WSChannel) Start

func (c *WSChannel) Start()

Start the keepalive and flush threads

func (*WSChannel) Stream

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

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