Documentation ¶
Overview ¶
This package provides the speak/streaming client implementation for the Deepgram API
This package provides the live/streaming client implementation for the Deepgram API
This package provides the speak/streaming client implementation for the Deepgram API
Index ¶
- Constants
- type Client
- type TextSource
- type WSCallback
- func NewUsingCallback(ctx context.Context, apiKey string, cOptions *clientinterfaces.ClientOptions, ...) (*WSCallback, error)
- func NewUsingCallbackForDemo(ctx context.Context, options *clientinterfaces.WSSpeakOptions) (*WSCallback, error)
- func NewUsingCallbackWithCancel(ctx context.Context, ctxCancel context.CancelFunc, apiKey string, ...) (*WSCallback, error)
- func NewUsingCallbackWithDefaults(ctx context.Context, options *clientinterfaces.WSSpeakOptions, ...) (*WSCallback, error)
- 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) Finish()
- func (c *WSCallback) Flush() error
- func (c *WSCallback) GetCloseMsg() []byte
- func (c *WSCallback) GetURL(host string) (string, error)
- func (c *WSCallback) ProcessError(err error) error
- func (c *WSCallback) ProcessMessage(wsType int, byMsg []byte) error
- func (c *WSCallback) Reset() error
- func (c *WSCallback) Speak(text string) error
- func (c *WSCallback) SpeakWithText(text string) error
- func (c *WSCallback) Start()
- func (c *WSCallback) WriteJSON(playload controlMessage) error
- type WSChannel
- func NewUsingChan(ctx context.Context, apiKey string, cOptions *clientinterfaces.ClientOptions, ...) (*WSChannel, error)
- func NewUsingChanForDemo(ctx context.Context, options *clientinterfaces.WSSpeakOptions) (*WSChannel, error)
- func NewUsingChanWithCancel(ctx context.Context, ctxCancel context.CancelFunc, apiKey string, ...) (*WSChannel, error)
- func NewUsingChanWithDefaults(ctx context.Context, options *clientinterfaces.WSSpeakOptions, ...) (*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) Flush() error
- func (c *WSChannel) GetCloseMsg() []byte
- func (c *WSChannel) GetURL(host string) (string, error)
- func (c *WSChannel) ProcessError(err error) error
- func (c *WSChannel) ProcessMessage(wsType int, byMsg []byte) error
- func (c *WSChannel) Reset() error
- func (c *WSChannel) Speak(text string) error
- func (c *WSChannel) SpeakWithText(text string) error
- func (c *WSChannel) Start()
- func (c *WSChannel) WriteJSON(playload controlMessage) error
Constants ¶
const ( DefaultConnectRetry int64 = 3 ChunkSize = 1024 * 2 TerminationSleep = 100 * time.Millisecond )
external constants
const ( // MessageTypeFlush flushes the audio from the server MessageTypeSpeak string = "Speak" // MessageTypeFlush flushes the audio from the server MessageTypeFlush string = "Flush" // MessageTypeReset resets the text buffer MessageTypeReset string = "Reset" // MessageTypeClose closes the stream MessageTypeClose string = "Close" )
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 TextSource ¶
external structs
type WSCallback ¶
WSCallback is a struct representing the websocket client connection using callbacks
func NewUsingCallback ¶
func NewUsingCallback(ctx context.Context, apiKey string, cOptions *clientinterfaces.ClientOptions, sOptions *clientinterfaces.WSSpeakOptions, callback msginterfaces.SpeakMessageCallback) (*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. - sOptions: SpeakOptions which allows overriding things like model, etc. - callback: SpeakMessageCallback is a callback which lets you perform actions based on platform messages
Notes:
- If apiKey is an empty string, the Deepgram API KEY is read from the environment variable DEEPGRAM_API_KEY
- The callback handler is set to the default handler
func NewUsingCallbackForDemo ¶
func NewUsingCallbackForDemo(ctx context.Context, options *clientinterfaces.WSSpeakOptions) (*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 ¶
func NewUsingCallbackWithCancel(ctx context.Context, ctxCancel context.CancelFunc, apiKey string, cOptions *clientinterfaces.ClientOptions, sOptions *clientinterfaces.WSSpeakOptions, callback msginterfaces.SpeakMessageCallback) (*WSCallback, error)
NewWithCancel 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. - sOptions: SpeakOptions which allows overriding things like model, etc. - callback: SpeakMessageCallback is a callback which lets you perform actions based on platform messages
Notes:
- If apiKey is an empty string, the Deepgram API KEY is read from the environment variable DEEPGRAM_API_KEY
- The callback handler is set to the default handler
func NewUsingCallbackWithDefaults ¶
func NewUsingCallbackWithDefaults(ctx context.Context, options *clientinterfaces.WSSpeakOptions, callback msginterfaces.SpeakMessageCallback) (*WSCallback, error)
NewWithDefaults creates a new websocket connection with all default options
Notes:
- The callback handler is set to the default handler
func (*WSCallback) AttemptReconnect ¶
func (c *WSCallback) AttemptReconnect(ctx context.Context, retries int64) bool
AttemptReconnect performs a reconnect after failing retries
func (*WSCallback) AttemptReconnectWithCancel ¶
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 ¶
func (c *WSCallback) Connect() bool
Connect performs a websocket connection with "DefaultConnectRetry" number of retries.
func (*WSCallback) ConnectWithCancel ¶
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) Flush ¶
func (c *WSCallback) Flush() error
Flush will instruct the server to flush the current text buffer
func (*WSCallback) GetCloseMsg ¶
func (c *WSCallback) GetCloseMsg() []byte
GetCloseMsg sends an application level message to Deepgram
func (*WSCallback) GetURL ¶
func (c *WSCallback) GetURL(host string) (string, error)
GetURL returns the websocket URL
func (*WSCallback) ProcessError ¶
func (c *WSCallback) ProcessError(err error) error
ProcessError sends an error message to the callback handler
func (*WSCallback) ProcessMessage ¶
func (c *WSCallback) ProcessMessage(wsType int, byMsg []byte) error
ProcessMessage processes the incoming message
func (*WSCallback) Reset ¶
func (c *WSCallback) Reset() error
Reset will instruct the server to reset the current buffer
func (*WSCallback) Speak ¶
func (c *WSCallback) Speak(text string) error
Speak is an alias function for SpeakWithText
func (*WSCallback) SpeakWithText ¶
func (c *WSCallback) SpeakWithText(text string) error
SpeakWithText writes text to the websocket server to obtain corresponding audio
This function will automatically wrap the text in the appropriate JSON structure and send it to the server
Args:
text: string containing the text to be spoken
Return:
error: if successful, returns nil otherwise an error object
func (*WSCallback) WriteJSON ¶
func (c *WSCallback) WriteJSON(playload controlMessage) error
WriteJSON writes a JSON message to the websocket
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, sOptions *clientinterfaces.WSSpeakOptions, chans msginterfaces.SpeakMessageChan) (*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 ¶
func NewUsingChanForDemo(ctx context.Context, options *clientinterfaces.WSSpeakOptions) (*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, sOptions *clientinterfaces.WSSpeakOptions, chans msginterfaces.SpeakMessageChan) (*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 ¶
func NewUsingChanWithDefaults(ctx context.Context, options *clientinterfaces.WSSpeakOptions, chans msginterfaces.SpeakMessageChan) (*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
func (*WSChannel) SpeakWithText ¶
SpeakWithText writes text to the websocket server to obtain corresponding audio
This function will automatically wrap the text in the appropriate JSON structure and send it to the server
Args:
text: string containing the text to be spoken
Return:
error: if successful, returns nil otherwise an error object