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
- type Client
- type WSCallback
- func New(ctx context.Context, apiKey string, cOptions *clientinterfaces.ClientOptions, ...) (*WSCallback, error)deprecated
- func NewForDemo(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions) (*WSCallback, error)deprecated
- func NewUsingCallback(ctx context.Context, apiKey string, cOptions *clientinterfaces.ClientOptions, ...) (*WSCallback, error)
- func NewUsingCallbackForDemo(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions) (*WSCallback, error)
- func NewUsingCallbackWithCancel(ctx context.Context, ctxCancel context.CancelFunc, apiKey string, ...) (*WSCallback, error)
- func NewUsingCallbackWithDefaults(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions, ...) (*WSCallback, error)
- func NewWithDefaults(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions, ...) (*WSCallback, error)deprecated
- func (c *WSCallback) AttemptReconnect(ctx context.Context, retries int64) bool
- func (c *WSCallback) AttemptReconnectWithCancel(ctx context.Context, ctxCancel context.CancelFunc, retries int64) bool
- func (c *WSCallback) Connect() bool
- func (c *WSCallback) ConnectWithCancel(ctx context.Context, ctxCancel context.CancelFunc, retryCnt int) bool
- func (c *WSCallback) Finalize() error
- func (c *WSCallback) Finish()
- func (c *WSCallback) GetCloseMsg() []byte
- func (c *WSCallback) GetURL(host string) (string, error)
- func (c *WSCallback) KeepAlive() error
- func (c *WSCallback) ProcessError(err error) error
- func (c *WSCallback) ProcessMessage(wsType int, byMsg []byte) error
- func (c *WSCallback) Start()
- func (c *WSCallback) Stream(r io.Reader) error
- func (c *WSCallback) Write(p []byte) (int, error)
- type WSChannel
- func NewUsingChan(ctx context.Context, apiKey string, cOptions *clientinterfaces.ClientOptions, ...) (*WSChannel, error)
- func NewUsingChanForDemo(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions) (*WSChannel, error)
- func NewUsingChanWithCancel(ctx context.Context, ctxCancel context.CancelFunc, apiKey string, ...) (*WSChannel, error)
- func NewUsingChanWithDefaults(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions, ...) (*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) Finalize() error
- 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" // MessageTypeFinalize flushes the transcription from the server MessageTypeFinalize string = "Finalize" )
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
WSCallback is a struct representing the websocket client connection using callbacks
func New
deprecated
func New(ctx context.Context, 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 - 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
func NewForDemo(ctx context.Context, options *clientinterfaces.LiveTranscriptionOptions) (*WSCallback, error)
********************************* 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
func NewUsingCallback(ctx context.Context, 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 - 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
func NewWithDefaults(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
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) 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
type WSChannel ¶ added in v1.6.0
WSChannel is a struct representing the websocket client connection using channels
func NewUsingChan ¶ added in v1.6.0
func NewUsingChan(ctx context.Context, 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 - 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
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
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
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
GetCloseMsg sends an application level message to Deepgram
func (*WSChannel) ProcessError ¶ added in v1.6.0
ProcessError processes the error and sends it to the callback
func (*WSChannel) ProcessMessage ¶ added in v1.6.0
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