Documentation
¶
Overview ¶
This package provides the live/streaming client implementation for the Deepgram API
Index ¶
- Constants
- Variables
- func Init(init InitLib)
- func InitWithDefault()
- type Client
- func New(ctx context.Context, apiKey string, cOptions interfaces.ClientOptions, ...) (*Client, error)
- func NewForDemo(ctx context.Context, options interfaces.LiveTranscriptionOptions) (*Client, error)
- func NewWithDefaults(ctx context.Context, options interfaces.LiveTranscriptionOptions, ...) (*Client, error)
- func (c *Client) AttemptReconnect(retries int64) *websocket.Conn
- func (c *Client) Connect() *websocket.Conn
- func (c *Client) ConnectWithRetry(retries int64) *websocket.Conn
- func (c *Client) Stop()
- func (c *Client) Stream(r io.Reader) error
- func (c *Client) Write(p []byte) (int, error)
- func (c *Client) WriteBinary(byData []byte) error
- func (c *Client) WriteJSON(payload interface{}) error
- type InitLib
Constants ¶
const ( CHUNK_SIZE = 1024 * 2 TERMINATION_SLEEP = 100 * time.Millisecond )
internal constants for retry, waits, back-off, etc.
const ( LogLevelDefault = common.LogLevelDefault LogLevelErrorOnly = common.LogLevelErrorOnly LogLevelStandard = common.LogLevelStandard LogLevelElevated = common.LogLevelElevated LogLevelFull = common.LogLevelFull LogLevelDebug = common.LogLevelDebug LogLevelTrace = common.LogLevelTrace LogLevelVerbose = common.LogLevelVerbose )
please see pkg/common/init.go for more information
Variables ¶
var ( // ErrInvalidConnection connection is not valid ErrInvalidConnection = errors.New("connection is not valid") )
errors
Functions ¶
func Init ¶
func Init(init InitLib)
The SDK Init function for this library. Allows you to set the logging level and use of a log file. Default is output to the stdout.
func InitWithDefault ¶
func InitWithDefault()
InitWithDefault is the SDK Init function for this library using default values.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a struct representing the websocket client connection
func New ¶
func New(ctx context.Context, apiKey string, cOptions interfaces.ClientOptions, tOptions interfaces.LiveTranscriptionOptions, callback msginterfaces.LiveMessageCallback) (*Client, 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 NewForDemo ¶
func NewForDemo(ctx context.Context, options interfaces.LiveTranscriptionOptions) (*Client, 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 NewWithDefaults ¶
func NewWithDefaults(ctx context.Context, options interfaces.LiveTranscriptionOptions, callback msginterfaces.LiveMessageCallback) (*Client, 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 (*Client) AttemptReconnect ¶
AttemptReconnect does exactly that with "retries" number of retries. If "retries" is set to -1, then it will retry forever.
func (*Client) Connect ¶
Connect performs a websocket connection with "defaultConnectRetry" number of retries.
func (*Client) ConnectWithRetry ¶
ConnectWithRetry is a function to explicitly do a connection with "retries" number of retries.
func (*Client) Stop ¶
func (c *Client) Stop()
Stop will send close message and shutdown websocket connection
func (*Client) Stream ¶
Stream is a helper function to stream audio data from a io.Reader object to deepgram
func (*Client) Write ¶
Write performs the lower level websocket write operation. This is needed to implement the io.Writer interface. (aka the streaming interface)
func (*Client) WriteBinary ¶
WriteBinary writes binary data to the websocket server