assistant

package
v0.0.0-...-8ca1572 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assistant

type Assistant struct {
	//The real deal
	GoogleAssistant gassist.EmbeddedAssistantClient
	Conversation    gassist.EmbeddedAssistant_AssistClient
	DialogState     *gassist.DialogStateIn

	//Assistant configuration
	AudioSettings *AudioSettings
	Device        *Device
	GCPAuth       *GCPAuthWrapper //Google Cloud Platform authentication wrapper
	LanguageCode  string

	//Connection stuff
	Canceler   context.CancelFunc
	Connection *grpc.ClientConn
	Context    context.Context
}

Assistant holds the Google Assistant and methods to interact with it

func NewAssistant

func NewAssistant(token *Token, oauthToken *oauth2.Token, callbackFunc TokenCallback, internalHost, languageCode string, device *Device, audioSettings *AudioSettings) (Assistant, error)

NewAssistant returns a new Google Assistant to operate on

func (*Assistant) Close

func (a *Assistant) Close()

Close closes the connection to the Assistant and cleans up all resources, except for conversations which must be handled by the caller

func (*Assistant) GetAuthURL

func (a *Assistant) GetAuthURL() string

GetAuthURL returns the Google authentication URL to sign into your Google account, only if you actually need to Also acts as a token refresh mechanism when running into auth issues

func (*Assistant) NewConversation

func (a *Assistant) NewConversation(timeout time.Duration) (*Conversation, error)

NewConversation starts a new conversation and returns it, it's the caller's job to close it

type AudioSettings

type AudioSettings struct {
	AudioInEncoding        gassist.AudioInConfig_Encoding
	AudioInSampleRateHertz int32

	AudioOutEncoding         gassist.AudioOutConfig_Encoding
	AudioOutSampleRateHertz  int32
	AudioOutVolumePercentage int32
}

AudioSettings holds the settings for an audio buffer

func NewAudioSettings

func NewAudioSettings(audioInEncoding gassist.AudioInConfig_Encoding, audioOutEncoding gassist.AudioOutConfig_Encoding, audioInSampleRateHertz, audioOutSampleRateHertz, audioOutVolumePercentage int32) *AudioSettings

NewAudioSettings returns a new audio settings object for configuring the Assistant AudioInConfig_Encoding enum: - 0: Encoding unspecified, Google will return result [google.rpc.Code.INVALID_ARGUMENT][] - 1: Signed 16-bit little-endian linear PCM - 2: FLAC, supports 16-bit and 24-bit samples and includes the FLAC stream header followed by audio data AudioOutConfig_Encoding enum: - 0: Encoding unspecified, Google will return result [google.rpc.Code.INVALID_ARGUMENT][] - 1: Signed 16-bit little-endian linear PCM - 2: MP3 audio encoding, sample rate is encoded in the payload - 3: Opus audio encoding wrapped in an OGG container, sample rate is encoded in the payload

type Conversation

type Conversation struct {
	Assistant    *Assistant //A pointer to the assistant, because we don't like high memory usage with multiple conversations now do we?
	AssistClient gassist.EmbeddedAssistant_AssistClient
	Running      bool
}

Conversation holds a Google Assistant conversation

func (*Conversation) Close

func (c *Conversation) Close()

Close closes the conversation

func (*Conversation) Refresh

func (c *Conversation) Refresh() error

Refresh initializes a new client stream, must be called before every query

func (*Conversation) RequestTransportAudio

func (c *Conversation) RequestTransportAudio() *TransportAudio

RequestTransportAudio returns an audio query transport, which must be used for the remainder of this conversation

func (*Conversation) RequestTransportText

func (c *Conversation) RequestTransportText() *TransportText

RequestTransportText returns a text query transport, which must be used for the remainder of this conversation

type Device

type Device struct {
	*gassist.DeviceConfig
}

Device holds a Google Assistant device

func NewDevice

func NewDevice(deviceID, deviceModelID string) *Device

NewDevice returns a new device object for configuring the Assistant

type GCPAuthWrapper

type GCPAuthWrapper struct {
	AuthURL        string
	CallbackFunc   TokenCallback
	Config         *oauth2.Config
	OauthSrv       *http.Server
	OauthToken     *oauth2.Token
	PermissionCode string

	AuthError error
}

GCPAuthWrapper handles Google authentication

func (*GCPAuthWrapper) Error

func (w *GCPAuthWrapper) Error() error

Error returns an authentication error

func (*GCPAuthWrapper) Initialize

func (w *GCPAuthWrapper) Initialize(credentials *Token, internalHost string, callbackFunc TokenCallback) error

Initialize initializes authentication to allow a user to sign in to the application

func (*GCPAuthWrapper) SetTokenSource

func (w *GCPAuthWrapper) SetTokenSource(permissionCode string) error

SetTokenSource is used to finish the authentication process, as well as calling any provided callback function

type Token

type Token struct {
	Installed struct {
		ClientID                string   `json:"client_id"`
		ProjectID               string   `json:"project_id"`
		AuthURI                 string   `json:"auth_uri"`
		TokenURI                string   `json:"token_uri"`
		AuthProviderX509CertURL string   `json:"auth_provider_x509_cert_url"`
		ClientSecret            string   `json:"client_secret"`
		RedirectUris            []string `json:"redirect_uris"`
	} `json:"installed"`
}

Token holds a Google OAuth2 token

type TokenCallback

type TokenCallback func(*oauth2.Token)

TokenCallback holds a callback function to return an OAuth2 token to, usually to cache for relogging in

type TransportAudio

type TransportAudio struct {
	SpeechRecognitionResult    string
	SpeechRecognitionStability float32
	Finished                   bool

	Conversation *Conversation
}

TransportAudio holds a request for an audio query

func (*TransportAudio) Read

func (r *TransportAudio) Read(p []byte) (n int, err error)

Read implements io.Reader and reads audio directly from Google, hanging until either audio is returned, an error is returned, or an EOF is returned upon the Assistant finishing the conversation

func (*TransportAudio) Start

func (r *TransportAudio) Start(finishedChan chan bool) error

Start starts the process and blocks until a response is returned, and optionally can send true over a channel once the request is closed by the Assistant

func (*TransportAudio) Transcript

func (r *TransportAudio) Transcript() (transcript string, stability float32)

Transcript returns a transcript of words that the user has spoken so far, as well as an estimate of the likelihood that the Assistant will not change its guess about this result (0.0 = unset, 0.1 = unstable, 1.0 = stable and final)

func (*TransportAudio) Write

func (r *TransportAudio) Write(p []byte) (n int, err error)

Write implements io.Writer and sends audio directly to Google, must be buffered at an unknown-required rate (32KB/s seems too slow but works in testing)

type TransportText

type TransportText struct {
	TextQuery    string
	TextResponse string

	Conversation *Conversation
}

TransportText holds a request for a text query

func (*TransportText) Query

func (r *TransportText) Query(textQuery string) (string, error)

Query returns the Assistant's response to a query as text

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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