voice

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultAudioLenMs is the number of milliseconds of audio we send for connection checks
	DefaultAudioLenMs = 6000
	// DefaultChunkMs is the default value for how often audio is sent to the cloud
	DefaultChunkMs = 120
	// SampleRate defines how many samples per second should be sent
	SampleRate = 16000
	// SampleBits defines how many bits each sample should contain
	SampleBits = 16
	// DefaultTimeout is the length of time before the process will cancel a voice request
	DefaultTimeout = 9 * time.Second
)

Variables

This section is empty.

Functions

func NewMemPipe

func NewMemPipe() (MsgIO, *Receiver)

NewMemPipe returns a connected pair of a MsgIO and a Receiver that directly transmit data over channels; the Receiver should be passed in to the cloud process to get data from the MsgIO

func SetVerbose

func SetVerbose(value bool)

SetVerbose enables or disables verbose logging

Types

type ChanMsgSender

type ChanMsgSender struct {
	Ch chan *cloud.Message
}

func (*ChanMsgSender) Send

func (c *ChanMsgSender) Send(msg *cloud.Message) error

type Handler

type Handler = pb.IntentService

Handler aliases the IntentService field from our protobuf that determines which backend service (Google, MS, etc) should handle this request

const (
	// HandlerDefault represents the default backend service chosen by chipper
	HandlerDefault Handler = pb.IntentService_DEFAULT
	// HandlerGoogle will have Google's DialogFlow service handle requests
	HandlerGoogle Handler = pb.IntentService_DIALOGFLOW
	// HandlerMicrosoft will have Microsoft's Bing/LUIS speech service handle requests
	HandlerMicrosoft Handler = pb.IntentService_BING_LUIS
	// HandlerAmazon will have Amazon's Lex service handle requests
	HandlerAmazon Handler = pb.IntentService_LEX
)

type IPCMsgSender

type IPCMsgSender struct {
	Conn ipc.Conn
}

func (*IPCMsgSender) Send

func (s *IPCMsgSender) Send(msg *cloud.Message) error

type MsgIO

type MsgIO interface {
	MsgSender
	MsgReader
}

MsgIO defines the API for sending audio data from an external source into the cloud process (and potentially receiving info back)

func NewIpcIO

func NewIpcIO(conn ipc.Conn) MsgIO

NewIpcIO returns a MsgIO that uses the given IPC connection to send audio data to the cloud process

type MsgReader

type MsgReader interface {
	Read() (*cloud.Message, error)
}

type MsgSender

type MsgSender interface {
	Send(*cloud.Message) error
}

type Option

type Option func(o *options)

Option defines an option that can be set on the cloud process

func WithChunkMs

func WithChunkMs(value uint) Option

WithChunkMs determines how often the cloud process will stream data to the cloud

func WithCompression

func WithCompression(value bool) Option

WithCompression sets whether compression will be performed on audio before uploading (and returns the same Options struct to allow method chaining)

func WithErrorListener

func WithErrorListener(value util.ErrorListener) Option

WithErrorListener specifies that the given ErrorListener should be passed errors that result from voice requests

func WithHandler

func WithHandler(value Handler) Option

WithHandler sets the intent service (MS, Google, etc) that should handle this request on the server, if one is desired

func WithRequireToken

func WithRequireToken() Option

WithRequireToken specifies that a failure to obtain an access token from the TMS should be treated as a fatal error for requests (temporary - eventually TMS tokens will be required)

func WithSaveAudio

func WithSaveAudio(value bool) Option

WithSaveAudio sets whether the chipper server should save the audio we send to it

func WithTokener

func WithTokener(value token.Accessor) Option

WithTokener sets the accessor that should be used to obtain tokens

type Process

type Process struct {
	// contains filtered or unexported fields
}

Process contains the data associated with an instance of the cloud process, and can have receivers and callbacks associated with it before ultimately being started with Run()

func (*Process) AddIntentWriter

func (p *Process) AddIntentWriter(s MsgSender)

AddIntentWriter adds the given Writer to the list of writers that will receive intents from the cloud

func (*Process) AddReceiver

func (p *Process) AddReceiver(r *Receiver)

AddReceiver adds the given Receiver to the list of sources the cloud process will listen to for data

func (*Process) AddTestReceiver

func (p *Process) AddTestReceiver(r *Receiver)

AddTestReceiver adds the given Receiver to the list of sources the cloud process will listen to for data. Additionally, it will be marked as a test receiver, which means that data sent on this receiver will send a message to the mic requesting it notify the AI of a hotword event on our behalf.

func (*Process) ChunkSamples

func (p *Process) ChunkSamples() int

ChunkSamples is the number of samples that should be in each chunk

func (*Process) Run

func (p *Process) Run(ctx context.Context, options ...Option)

Run starts the cloud process, which will run until stopped on the given channel

func (*Process) StreamSize

func (p *Process) StreamSize() int

StreamSize is the size in bytes of each chunk

type Receiver

type Receiver struct {
	// contains filtered or unexported fields
}

Receiver is an object that should be passed in to the cloud process and determines how it will receive audio data from external sources

func NewIpcReceiver

func NewIpcReceiver(conn ipc.Conn, kill <-chan struct{}) *Receiver

NewIpcReceiver constructs a Receiver that receives audio data and hotword signals over the given IPC connection

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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