Documentation
¶
Overview ¶
This package provides the live/streaming client implementation for the Deepgram API
Index ¶
- Constants
- type FunctionCallResponse
- type InjectAgentMessage
- type KeepAlive
- type SettingsConfigurationOptions
- type UpdateInstructions
- type UpdateSpeak
- type WSChannel
- func NewUsingChan(ctx context.Context, apiKey string, cOptions *clientinterfaces.ClientOptions, ...) (*WSChannel, error)
- func NewUsingChanForDemo(ctx context.Context, options *clientinterfaces.SettingsConfigurationOptions) (*WSChannel, error)
- func NewUsingChanWithCancel(ctx context.Context, ctxCancel context.CancelFunc, apiKey string, ...) (*WSChannel, error)
- func NewUsingChanWithDefaults(ctx context.Context, options *clientinterfaces.SettingsConfigurationOptions, ...) (*WSChannel, error)
- func (c *WSChannel) AttemptReconnect(ctx context.Context, retries int64) bool
- func (c *WSChannel) AttemptReconnectWithCancel(ctx context.Context, ctxCancel context.CancelFunc, retries int64) bool
- func (c *WSChannel) Connect() bool
- func (c *WSChannel) ConnectWithCancel(ctx context.Context, ctxCancel context.CancelFunc, retryCnt int) bool
- func (c *WSChannel) Finish()
- func (c *WSChannel) GetCloseMsg() []byte
- func (c *WSChannel) GetURL(host string) (string, error)
- func (c *WSChannel) KeepAlive() error
- func (c *WSChannel) ProcessError(err error) error
- func (c *WSChannel) ProcessMessage(wsType int, byMsg []byte) error
- func (c *WSChannel) Start()
- func (c *WSChannel) Stream(r io.Reader) error
- func (c *WSChannel) Write(p []byte) (int, error)
Constants ¶
const ( DefaultConnectRetry int64 = 3 ChunkSize = 1024 * 2 TerminationSleep = 100 * time.Millisecond )
external constants
const ( // MessageTypeKeepAlive keep the connection alive MessageTypeKeepAlive string = "KeepAlive" )
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 ¶
WSChannel is a struct representing the websocket client connection using channels
func NewUsingChan ¶
func NewUsingChan(ctx context.Context, apiKey string, cOptions *clientinterfaces.ClientOptions, tOptions *clientinterfaces.SettingsConfigurationOptions, chans msginterfaces.AgentMessageChan) (*WSChannel, error)
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 ¶
func NewUsingChanWithCancel(ctx context.Context, ctxCancel context.CancelFunc, apiKey string, cOptions *clientinterfaces.ClientOptions, tOptions *clientinterfaces.SettingsConfigurationOptions, chans msginterfaces.AgentMessageChan) (*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: 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 ¶
func NewUsingChanWithDefaults(ctx context.Context, options *clientinterfaces.SettingsConfigurationOptions, chans msginterfaces.AgentMessageChan) (*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 ¶
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 ¶
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) GetCloseMsg ¶
GetCloseMsg sends an application level message to Deepgram
func (*WSChannel) ProcessError ¶
ProcessError processes the error and sends it to the callback
func (*WSChannel) ProcessMessage ¶
ProcessMessage processes the message and sends it to the callback