live

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 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 (
	CHUNK_SIZE        = 1024 * 2
	TERMINATION_SLEEP = 100 * time.Millisecond
)

internal constants for retry, waits, back-off, etc.

View Source
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

View Source
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

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

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

func (c *Client) AttemptReconnect(retries int64) *websocket.Conn

AttemptReconnect does exactly that with "retries" number of retries. If "retries" is set to -1, then it will retry forever.

func (*Client) Connect

func (c *Client) Connect() *websocket.Conn

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

func (*Client) ConnectWithRetry

func (c *Client) ConnectWithRetry(retries int64) *websocket.Conn

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

func (c *Client) Stream(r io.Reader) error

Stream is a helper function to stream audio data from a io.Reader object to deepgram

func (*Client) Write

func (c *Client) 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)

func (*Client) WriteBinary

func (c *Client) WriteBinary(byData []byte) error

WriteBinary writes binary data to the websocket server

func (*Client) WriteJSON

func (c *Client) WriteJSON(payload interface{}) error

WriteJSON writes a JSON control payload to the websocket server. These are control messages for managing the live transcription session on the Deepgram server.

type InitLib

type InitLib struct {
	LogLevel      common.LogLevel
	DebugFilePath string
}

Initialization options for this SDK.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL