avs

package module
v0.0.0-...-51c8238 Latest Latest
Warning

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

Go to latest
Published: May 13, 2019 License: MIT Imports: 12 Imported by: 0

README

Alexa Voice Service for Go

GoDoc

A simple package for communicating with Amazon’s HTTP/2 API for AVS.

Requires Go 1.8 or later.

Example

package main

import (
  "fmt"
  "io/ioutil"
  "os"

  "github.com/fika-io/go-avs"
)

// Put your access token below.
const ACCESS_TOKEN = "YOUR ACCESS TOKEN"

func main() {
  // Record your request into request.wav.
  audio, _ := os.Open("./request.wav")
  response, err := avs.PostRecognize(ACCESS_TOKEN, "abc123", "abc123dialog", audio)
  if err != nil {
    fmt.Printf("Failed to call AVS: %v\n", err)
    return
  }
  // AVS might not return any directives in some cases.
  if len(response.Directives) == 0 {
    fmt.Println("Alexa had nothing to say.")
    return
  }
  // A response can have multiple directives in the response.
  for _, directive := range response.Directives {
    switch d := directive.Typed().(type) {
    case *avs.ExpectSpeech:
      fmt.Printf("Alexa wants you to speak within %s!\n", d.Timeout())
    case *avs.Play:
      // The Play directive can point to attached audio or remote streams.
      if cid := d.Payload.AudioItem.Stream.ContentId(); cid != "" {
        save(response, cid)
      } else {
        fmt.Println("Remote stream:", d.Payload.AudioItem.Stream.URL)
      }
    case *avs.Speak:
      // The Speak directive always points to attached audio.
      save(response, d.ContentId())
    default:
      fmt.Println("No code to handle directive:", d)
    }
  }
}

var savedFiles = 0

// Function that saves an audio file to disk.
func save(resp *avs.Response, cid string) {
  savedFiles++
  filename := fmt.Sprintf("./response%d.mp3", savedFiles)
  ioutil.WriteFile(filename, resp.Content[cid], 0666)
  fmt.Println("Saved Alexa’s response to", filename)
}

Downchannels

You can open a downchannel with the CreateDownchannel method. It's implemented as a read-only channel of Message pointers.

package main

import (
  "fmt"

  "github.com/fika-io/go-avs"
)

// Put your access token below.
const ACCESS_TOKEN = "YOUR ACCESS TOKEN"

func main() {
  directives, err := avs.CreateDownchannel(ACCESS_TOKEN)
  if err != nil {
    fmt.Printf("Failed to open downchannel: %v\n", err)
    return
  }
  // Wait for directives to come in on the downchannel.
  for directive := range directives {
    switch d := directive.Typed().(type) {
    case *avs.DeleteAlert:
      fmt.Println("Unset alert:", d.Payload.Token)
    case *avs.SetAlert:
      fmt.Printf("Set alert %s (%s) for %s\n", d.Payload.Token, d.Payload.Type, d.Payload.ScheduledTime)
    default:
      fmt.Println("No code to handle directive:", d)
    }
  }
  fmt.Println("Downchannel closed. Bye!")
}

Documentation

Overview

Package avs makes requests to Amazon's AVS API using HTTP/2 and also supports creating a downchannel which receives directives from AVS based on the user's speech and/or actions in the companion app.

To send a Recognize event to AVS, you can use the PostRecognize function:

audio, _ := os.Open("./request.wav")
response, err := avs.PostRecognize(ACCESS_TOKEN, "abc123",
                                   "abc123dialog", audio)

For simple events you can use the PostEvent function:

event := NewVolumeChanged("abc123", 100, false)
response, err := avs.PostEvent(ACCESS_TOKEN, event)

You can also make requests to AVS with the Client.Do method:

request := avs.NewRequest(ACCESS_TOKEN)
request.Event = avs.NewRecognize("abc123", "abc123dialog")
request.Audio, _ = os.Open("./request.wav")
response, err := avs.DefaultClient.Do(request)

A Response will contain a list of directives from AVS. The list contains untyped Message instances which hold the raw response data and headers, but it can be typed by calling the Typed method of Message:

for _, directive := range response.Directives {
	switch d := directive.Typed().(type) {
	case *avs.Speak:
		cid := d.ContentId()
		ioutil.WriteFile("./speak.mp3", response.Content[cid], 0666)
	default:
		fmt.Println("No code to handle directive:", d)
	}
}

To create a downchannel, a long-lived request for AVS to deliver directives, use the CreateDownchannel method of the Client type:

directives, _ := avs.CreateDownchannel(ACCESS_TOKEN)
for directive := range directives {
	switch d := directive.Typed().(type) {
	case *avs.DeleteAlert:
		fmt.Println("Delete alert:", d.Payload.Token)
	case *avs.SetAlert:
		fmt.Println("Set an alert for:", d.Payload.ScheduledTime)
	default:
		fmt.Println("No code to handle directive:", d)
	}
}

Index

Constants

View Source
const (
	// You can find the latest versioning information on the AVS API overview page:
	// https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/content/avs-api-overview
	Version        = "/v20160207"
	DirectivesPath = Version + "/directives"
	EventsPath     = Version + "/events"
	PingPath       = "/ping"
)

The different endpoints that are supported by the AVS API.

View Source
const (
	RecognizeProfileCloseTalk = RecognizeProfile("CLOSE_TALK")
	RecognizeProfileNearField = RecognizeProfile("NEAR_FIELD")
	RecognizeProfileFarField  = RecognizeProfile("FAR_FIELD")
)

Possible values for RecognizeProfile. Supports three distinct profiles optimized for speech at varying distances.

View Source
const (
	SettingLocaleUS = SettingLocale("en-US")
	SettingLocaleGB = SettingLocale("en-GB")
	SettingLocaleDE = SettingLocale("de-DE")
)

Possible values for SettingLocale.

View Source
const (
	// AlertTypeAlarm specifies the type for an alarm. Alarms are scheduled for
	// specific times (e.g., to wake the user up).
	AlertTypeAlarm = AlertType("ALARM")
	// AlertTypeTimer specifies the type for a timer. Timers count down a certain
	// amount of time (e.g., "timer for 5 minutes").
	AlertTypeTimer = AlertType("TIMER")
)

Possible values for AlertType, used by the SetAlert directive.

View Source
const (
	// ClearBehaviorClearAll clears all items in the queue, including the current
	// one.
	ClearBehaviorClearAll = ClearBehavior("CLEAR_ALL")
	// ClearBehaviorClearEnqueued clears all queued items in the queue (not
	// including the current one).
	ClearBehaviorClearEnqueued = ClearBehavior("CLEAR_ENQUEUED")
)

Possible values for ClearBehavior.

View Source
const (
	// ErrorTypeInternalError should be reported when none of the other error
	// types is applicable.
	ErrorTypeInternalError = ErrorType("INTERNAL_ERROR")
	// ErrorTypeUnexpectedInformation should be reported when the client is unable
	// to handle the received directive due to invalid format or data.
	ErrorTypeUnexpectedInformation = ErrorType("UNEXPECTED_INFORMATION_RECEIVED")
	// ErrorTypeUnsupportedOperation should be reported when the client is unable
	// to perform the operation specified by the directive.
	ErrorTypeUnsupportedOperation = ErrorType("UNSUPPORTED_OPERATION")
)

Possible values for ErrorType.

View Source
const (
	MediaErrorTypeInternalDeviceError = MediaErrorType("MEDIA_ERROR_INTERNAL_DEVICE_ERROR")
	MediaErrorTypeInternalServerError = MediaErrorType("MEDIA_ERROR_INTERNAL_SERVER_ERROR")
	MediaErrorTypeInvalidRequest      = MediaErrorType("MEDIA_ERROR_INVALID_REQUEST")
	MediaErrorTypeServiceUnavailable  = MediaErrorType("MEDIA_ERROR_SERVICE_UNAVAILABLE")
	MediaErrorTypeUnknown             = MediaErrorType("MEDIA_ERROR_UNKNOWN")
)
View Source
const (
	// PlayBehaviorEnqueue specifies that the audio should be played after current
	// queue of audio.
	PlayBehaviorEnqueue = PlayBehavior("ENQUEUE")
	// PlayBehaviorReplaceAll specifies that the audio should play immediately,
	// throwing away all queued audio.
	PlayBehaviorReplaceAll = PlayBehavior("REPLACE_ALL")
	// PlayBehaviorReplaceEnqueued specifies that the audio should play after the
	// currently playing audio, replacing all queued audio.
	PlayBehaviorReplaceEnqueued = PlayBehavior("REPLACE_ENQUEUED")
)

Possible values for PlayBehavior.

View Source
const (
	PlayerActivityBufferUnderrun = PlayerActivity("BUFFER_UNDERRUN")
	PlayerActivityIdle           = PlayerActivity("IDLE")
	PlayerActivityPaused         = PlayerActivity("PAUSED")
	PlayerActivityStopped        = PlayerActivity("STOPPED")
	PlayerActivityPlaying        = PlayerActivity("PLAYING")
	PlayerActivityFinished       = PlayerActivity("FINISHED")
)

Possible values for PlayerActivity.

Variables

View Source
var DefaultClient = &Client{

	EndpointURL: "https://avs-alexa-na.amazon.com",
}

DefaultClient is the default Client.

Functions

func CreateDownchannel

func CreateDownchannel(accessToken string) (<-chan *Message, error)

CreateDownchannel establishes a persistent connection with AVS and returns a read-only channel through which AVS will deliver directives.

CreateDownchannel is a wrapper around DefaultClient.CreateDownchannel.

func RandomUUIDString

func RandomUUIDString() string

Types

type AdjustVolume

type AdjustVolume struct {
	*Message
	Payload struct {
		Volume int `json:"volume"`
	} `json:"payload"`
}

The AdjustVolume directive.

type Alert

type Alert struct {
	Token         string    `json:"token"`
	Type          AlertType `json:"type"`
	ScheduledTime string    `json:"scheduledTime"`
}

Alert represents a single alarm or timer with a scheduled time.

type AlertEnteredBackground

type AlertEnteredBackground struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The AlertEnteredBackground event.

func NewAlertEnteredBackground

func NewAlertEnteredBackground(messageId, token string) *AlertEnteredBackground

type AlertEnteredForeground

type AlertEnteredForeground struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The AlertEnteredForeground event.

func NewAlertEnteredForeground

func NewAlertEnteredForeground(messageId, token string) *AlertEnteredForeground

type AlertStarted

type AlertStarted struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The AlertStarted event.

func NewAlertStarted

func NewAlertStarted(messageId, token string) *AlertStarted

type AlertStopped

type AlertStopped struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The AlertStopped event.

func NewAlertStopped

func NewAlertStopped(messageId, token string) *AlertStopped

type AlertType

type AlertType string

AlertType specifies the type of an alert.

type AlertsState

type AlertsState struct {
	*Message
	Payload struct {
		AllAlerts    []Alert `json:"allAlerts"`
		ActiveAlerts []Alert `json:"activeAlerts"`
	} `json:"payload"`
}

The AlertsState context.

func NewAlertsState

func NewAlertsState(allAlerts, activeAlerts []Alert) *AlertsState

type AudioItem

type AudioItem struct {
	AudioItemId string `json:"audioItemId"`
	Stream      Stream `json:"stream"`
}

AudioItem represents an attached or streamable audio item.

type ClearBehavior

type ClearBehavior string

ClearBehavior specifies how the play queue should be cleared.

type ClearQueue

type ClearQueue struct {
	*Message
	Payload struct {
		ClearBehavior ClearBehavior `json:"clearBehavior"`
	} `json:"payload"`
}

The ClearQueue directive.

type Client

type Client struct {
	EndpointURL string
}

Client enables making requests and creating downchannels to AVS.

func (*Client) CreateDownchannel

func (c *Client) CreateDownchannel(accessToken string) (<-chan *Message, error)

CreateDownchannel establishes a persistent connection with AVS and returns a read-only channel through which AVS will deliver directives.

func (*Client) Do

func (c *Client) Do(request *Request) (*Response, error)

Do posts a request to the AVS service's /events endpoint.

func (*Client) Ping

func (c *Client) Ping(accessToken string) error

Ping will ping AVS on behalf of a user to indicate that the connection is still alive.

type DeleteAlert

type DeleteAlert struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The DeleteAlert directive.

type DeleteAlertFailed

type DeleteAlertFailed struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The DeleteAlertFailed event.

func NewDeleteAlertFailed

func NewDeleteAlertFailed(messageId, token string) *DeleteAlertFailed

type DeleteAlertSucceeded

type DeleteAlertSucceeded struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The DeleteAlertSucceeded event.

func NewDeleteAlertSucceeded

func NewDeleteAlertSucceeded(messageId, token string) *DeleteAlertSucceeded

type ErrorType

type ErrorType string

ErrorType specifies the types of errors that the client may report to AVS.

type Exception

type Exception struct {
	*Message
	Payload struct {
		Code        string `json:"code"`
		Description string `json:"description"`
	} `json:"payload"`
}

The Exception message.

func (*Exception) Error

func (m *Exception) Error() string

Error returns the Exception formatted as a human readable string.

type ExceptionEncountered

type ExceptionEncountered struct {
	*Message
	Payload struct {
		UnparsedDirective string `json:"unparsedDirective"`
		Error             struct {
			Type    ErrorType `json:"type"`
			Message string    `json:"message"`
		} `json:"error"`
	} `json:"payload"`
}

The ExceptionEncountered event.

func NewExceptionEncountered

func NewExceptionEncountered(messageId, directive string, errorType ErrorType, errorMessage string) *ExceptionEncountered

type ExpectSpeech

type ExpectSpeech struct {
	*Message
	Payload struct {
		TimeoutInMilliseconds int `json:"timeoutInMilliseconds"`
	} `json:"payload"`
}

The ExpectSpeech directive.

func (*ExpectSpeech) Timeout

func (m *ExpectSpeech) Timeout() time.Duration

type ExpectSpeechTimedOut

type ExpectSpeechTimedOut struct {
	*Message
	Payload struct{} `json:"payload"`
}

The ExpectSpeechTimedOut event.

func NewExpectSpeechTimedOut

func NewExpectSpeechTimedOut(messageId string) *ExpectSpeechTimedOut

type MediaErrorType

type MediaErrorType string

type Message

type Message struct {
	Header  map[string]string `json:"header"`
	Payload json.RawMessage   `json:"payload,omitempty"`
}

Message is a general structure for contexts, events and directives.

func (*Message) GetMessage

func (m *Message) GetMessage() *Message

GetMessage returns a pointer to the underlying Message object.

func (*Message) String

func (m *Message) String() string

String returns the namespace and name as a single string.

func (*Message) Typed

func (m *Message) Typed() TypedMessage

Typed returns a more specific type for this message.

This only parses directives as they're the only type of message sent by AVS.

type MuteChanged

type MuteChanged struct {
	*Message
	Payload struct {
		Volume int  `json:"volume"`
		Muted  bool `json:"muted"`
	} `json:"payload"`
}

The MuteChanged event.

func NewMuteChanged

func NewMuteChanged(messageId string, volume int, muted bool) *MuteChanged

type NextCommandIssued

type NextCommandIssued struct {
	*Message
	Payload struct{} `json:"payload"`
}

The NextCommandIssued event.

func NewNextCommandIssued

func NewNextCommandIssued(messageId string) *NextCommandIssued

type PauseCommandIssued

type PauseCommandIssued struct {
	*Message
	Payload struct{} `json:"payload"`
}

The PauseCommandIssued event.

func NewPauseCommandIssued

func NewPauseCommandIssued(messageId string) *PauseCommandIssued

type Play

type Play struct {
	*Message
	Payload struct {
		AudioItem    AudioItem    `json:"audioItem"`
		PlayBehavior PlayBehavior `json:"playBehavior"`
	} `json:"payload"`
}

The Play directive.

type PlayBehavior

type PlayBehavior string

PlayBehavior specifies how an audio item should be inserted into the play queue.

type PlayCommandIssued

type PlayCommandIssued struct {
	*Message
	Payload struct{} `json:"payload"`
}

The PlayCommandIssued event.

func NewPlayCommandIssued

func NewPlayCommandIssued(messageId string) *PlayCommandIssued

type PlaybackFailed

type PlaybackFailed struct {
	*Message
	Payload struct {
		Token                string        `json:"token"`
		CurrentPlaybackState playbackState `json:"currentPlaybackState"`
		Error                struct {
			Type    MediaErrorType `json:"type"`
			Message string         `json:"message"`
		} `json:"error"`
	} `json:"payload"`
}

The PlaybackFailed event.

func NewPlaybackFailed

func NewPlaybackFailed(messageId, token string, errorType MediaErrorType, errorMessage string) *PlaybackFailed

type PlaybackFinished

type PlaybackFinished struct {
	*Message
	Payload struct {
		Token                string `json:"token"`
		OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
	} `json:"payload"`
}

The PlaybackFinished event.

func NewPlaybackFinished

func NewPlaybackFinished(messageId, token string, offset time.Duration) *PlaybackFinished

type PlaybackNearlyFinished

type PlaybackNearlyFinished struct {
	*Message
	Payload struct {
		Token                string `json:"token"`
		OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
	} `json:"payload"`
}

The PlaybackNearlyFinished event.

func NewPlaybackNearlyFinished

func NewPlaybackNearlyFinished(messageId, token string, offset time.Duration) *PlaybackNearlyFinished

type PlaybackPaused

type PlaybackPaused struct {
	*Message
	Payload struct {
		Token                string `json:"token"`
		OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
	} `json:"payload"`
}

The PlaybackPaused event.

func NewPlaybackPaused

func NewPlaybackPaused(messageId, token string, offset time.Duration) *PlaybackPaused

type PlaybackQueueCleared

type PlaybackQueueCleared struct {
	*Message
	Payload struct{} `json:"payload"`
}

The PlaybackQueueCleared event.

func NewPlaybackQueueCleared

func NewPlaybackQueueCleared(messageId string) *PlaybackQueueCleared

type PlaybackResumed

type PlaybackResumed struct {
	*Message
	Payload struct {
		Token                string `json:"token"`
		OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
	} `json:"payload"`
}

The PlaybackResumed event.

func NewPlaybackResumed

func NewPlaybackResumed(messageId, token string, offset time.Duration) *PlaybackResumed

type PlaybackStarted

type PlaybackStarted struct {
	*Message
	Payload struct {
		Token                string `json:"token"`
		OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
	} `json:"payload"`
}

The PlaybackStarted event.

func NewPlaybackStarted

func NewPlaybackStarted(messageId, token string, offset time.Duration) *PlaybackStarted

type PlaybackState

type PlaybackState struct {
	*Message
	Payload playbackState `json:"payload"`
}

The PlaybackState context.

func NewPlaybackState

func NewPlaybackState(token string, offset time.Duration, activity PlayerActivity) *PlaybackState

type PlaybackStopped

type PlaybackStopped struct {
	*Message
	Payload struct {
		Token                string `json:"token"`
		OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
	} `json:"payload"`
}

The PlaybackStopped event.

func NewPlaybackStopped

func NewPlaybackStopped(messageId, token string, offset time.Duration) *PlaybackStopped

type PlaybackStutterFinished

type PlaybackStutterFinished struct {
	*Message
	Payload struct {
		Token                         string `json:"token"`
		OffsetInMilliseconds          int    `json:"offsetInMilliseconds"`
		StutterDurationInMilliseconds int    `json:"stutterDurationInMilliseconds"`
	} `json:"payload"`
}

The PlaybackStutterFinished event.

func NewPlaybackStutterFinished

func NewPlaybackStutterFinished(messageId, token string, offset, stutterDuration time.Duration) *PlaybackStutterFinished

type PlaybackStutterStarted

type PlaybackStutterStarted struct {
	*Message
	Payload struct {
		Token                string `json:"token"`
		OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
	} `json:"payload"`
}

The PlaybackStutterStarted event.

func NewPlaybackStutterStarted

func NewPlaybackStutterStarted(messageId, token string, offset time.Duration) *PlaybackStutterStarted

type PlayerActivity

type PlayerActivity string

PlayerActivity specifies what state the audio player is in.

type PreviousCommandIssued

type PreviousCommandIssued struct {
	*Message
	Payload struct{} `json:"payload"`
}

The PreviousCommandIssued event.

func NewPreviousCommandIssued

func NewPreviousCommandIssued(messageId string) *PreviousCommandIssued

type ProgressReport

type ProgressReport struct {
	ProgressReportIntervalInMilliseconds float64 `json:"progressReportIntervalInMilliseconds"`
	ProgressReportDelayInMilliseconds    float64 `json:"progressReportDelayInMilliseconds"`
}

func (*ProgressReport) Delay

func (p *ProgressReport) Delay() time.Duration

func (*ProgressReport) Interval

func (p *ProgressReport) Interval() time.Duration

type ProgressReportDelayElapsed

type ProgressReportDelayElapsed struct {
	*Message
	Payload struct {
		Token                string `json:"token"`
		OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
	} `json:"payload"`
}

The ProgressReportDelayElapsed event.

func NewProgressReportDelayElapsed

func NewProgressReportDelayElapsed(messageId, token string, offset time.Duration) *ProgressReportDelayElapsed

type ProgressReportIntervalElapsed

type ProgressReportIntervalElapsed struct {
	*Message
	Payload struct {
		Token                string `json:"token"`
		OffsetInMilliseconds int    `json:"offsetInMilliseconds"`
	} `json:"payload"`
}

The ProgressReportIntervalElapsed event.

func NewProgressReportIntervalElapsed

func NewProgressReportIntervalElapsed(messageId, token string, offset time.Duration) *ProgressReportIntervalElapsed

type Recognize

type Recognize struct {
	*Message
	Payload struct {
		Profile RecognizeProfile `json:"profile"`
		Format  string           `json:"format"`
	} `json:"payload"`
}

The Recognize event.

func NewRecognize

func NewRecognize(messageId, dialogRequestId string) *Recognize

func NewRecognizeWithProfile

func NewRecognizeWithProfile(messageId, dialogRequestId string, profile RecognizeProfile) *Recognize

type RecognizeProfile

type RecognizeProfile string

RecognizeProfile identifies the ASR profile associated with your product.

type Request

type Request struct {
	// Access token for the user that this request should be made for.
	AccessToken string         `json:"-"`
	Audio       io.Reader      `json:"-"`
	Context     []TypedMessage `json:"context"`
	Event       TypedMessage   `json:"event"`
}

A Request represents an event and optional context to send to AVS.

func NewRequest

func NewRequest(accessToken string) *Request

NewRequest returns a new Request given an access token.

The Request is suitable for use with Client.Do.

func (*Request) AddContext

func (r *Request) AddContext(m TypedMessage)

AddContext adds a context Message to the Request.

type ResetUserInactivity

type ResetUserInactivity struct {
	*Message
	Payload struct{} `json:"payload"`
}

The ResetUserInactivity directive.

type Response

type Response struct {
	// The Amazon request id (for debugging purposes).
	RequestId string
	// All the directives in the response.
	Directives []*Message
	// Attachments (usually audio). Key is the Content-ID header value.
	Content map[string][]byte
}

Response represents a response from the AVS API.

func PostEvent

func PostEvent(accessToken string, event TypedMessage) (*Response, error)

PostEvent will post an event to AVS.

PostEvent is a wrapper around DefaultClient.Do.

func PostRecognize

func PostRecognize(accessToken, messageId, dialogRequestId string, audio io.Reader) (*Response, error)

PostRecognize will post a Recognize event to AVS.

PostRecognize is a wrapper around DefaultClient.Do.

func PostSynchronizeState

func PostSynchronizeState(accessToken, messageId string, context []TypedMessage) (*Response, error)

PostSynchronizeState will post a SynchronizeState event with the provided context to AVS.

PostSynchronizeState is a wrapper around DefaultClient.Do.

type SetAlert

type SetAlert struct {
	*Message
	Payload Alert `json:"payload"`
}

The SetAlert directive.

type SetAlertFailed

type SetAlertFailed struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The SetAlertFailed event.

func NewSetAlertFailed

func NewSetAlertFailed(messageId, token string) *SetAlertFailed

type SetAlertSucceeded

type SetAlertSucceeded struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The SetAlertSucceeded event.

func NewSetAlertSucceeded

func NewSetAlertSucceeded(messageId, token string) *SetAlertSucceeded

type SetEndpoint

type SetEndpoint struct {
	*Message
	Payload struct {
		Endpoint string `json:"endpoint"`
	} `json:"payload"`
}

The SetEndpoint directive.

type SetMute

type SetMute struct {
	*Message
	Payload struct {
		Mute bool `json:"mute"`
	} `json:"payload"`
}

The SetMute directive.

type SetVolume

type SetVolume struct {
	*Message
	Payload struct {
		Volume int `json:"volume"`
	} `json:"payload"`
}

The SetVolume directive.

type Setting

type Setting struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

The SettingsUpdated event.

type SettingLocale

type SettingLocale string

type SettingsUpdated

type SettingsUpdated struct {
	*Message
	Payload struct {
		Settings []Setting `json:"settings"`
	} `json:"payload"`
}

func NewLocaleSettingsUpdated

func NewLocaleSettingsUpdated(messageId string, locale SettingLocale) *SettingsUpdated

type Speak

type Speak struct {
	*Message
	Payload struct {
		Format string `json:"format"`
		URL    string `json:"url"`
		Token  string `json:"token"`
	} `json:"payload"`
}

The Speak directive.

func (*Speak) ContentId

func (m *Speak) ContentId() string

type SpeechFinished

type SpeechFinished struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The SpeechFinished event.

func NewSpeechFinished

func NewSpeechFinished(messageId, token string) *SpeechFinished

type SpeechStarted

type SpeechStarted struct {
	*Message
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

The SpeechStarted event.

func NewSpeechStarted

func NewSpeechStarted(messageId, token string) *SpeechStarted

type SpeechState

type SpeechState struct {
	*Message
	Payload struct {
		Token                string         `json:"token"`
		OffsetInMilliseconds int            `json:"offsetInMilliseconds"`
		PlayerActivity       PlayerActivity `json:"playerActivity"`
	} `json:"payload"`
}

The SpeechState context.

func NewSpeechState

func NewSpeechState(token string, offset time.Duration, playerActivity PlayerActivity) *SpeechState

type Stop

type Stop struct {
	*Message
	Payload struct{} `json:"payload"`
}

The Stop directive.

type StopCapture

type StopCapture struct {
	*Message
	Payload struct{} `json:"payload"`
}

The StopCapture directive.

type Stream

type Stream struct {
	ExpiryTime            string         `json:"expiryTime"`
	OffsetInMilliseconds  float64        `json:"offsetInMilliseconds"`
	ProgressReport        ProgressReport `json:"progressReport"`
	Token                 string         `json:"token"`
	ExpectedPreviousToken string         `json:"expectedPreviousToken"`
	URL                   string         `json:"url"`
}

An audio stream which can either be attached with the response or a remote URL.

func (*Stream) ContentId

func (s *Stream) ContentId() string

ContentId returns the content id of the audio, if it's attached with the response; otherwise, an empty string.

type StreamMetadataExtracted

type StreamMetadataExtracted struct {
	*Message
	Payload struct {
		Token    string                 `json:"token"`
		Metadata map[string]interface{} `json:"metadata"`
	} `json:"payload"`
}

The StreamMetadataExtracted event.

func NewStreamMetadataExtracted

func NewStreamMetadataExtracted(messageId, token string, metadata map[string]interface{}) *StreamMetadataExtracted

type SynchronizeState

type SynchronizeState struct {
	*Message
	Payload struct{} `json:"payload"`
}

The SynchronizeState event.

func NewSynchronizeState

func NewSynchronizeState(messageId string) *SynchronizeState

type TypedMessage

type TypedMessage interface {
	GetMessage() *Message
	Typed() TypedMessage
}

TypedMessage is an interface that represents both raw Message objects and more specifically typed ones. Usually, values of this interface are used with a type switch:

switch d := typedMessage.(type) {
case *Speak:
	fmt.Printf("We got a spoken response in format %s.\n", d.Payload.Format)
}

type UUID

type UUID []byte

UUID holds a 16 byte unique identifier.

func NewUUID

func NewUUID() (UUID, error)

NewUUID returns a randomly generated UUID.

func (UUID) String

func (uuid UUID) String() string

String returns a string representation of the UUID.

type UserInactivityReport

type UserInactivityReport struct {
	*Message
	Payload struct {
		InactiveTimeInSeconds int `json:"inactiveTimeInSeconds"`
	} `json:"payload"`
}

The UserInactivityReport event.

func NewUserInactivityReport

func NewUserInactivityReport(messageId string, inactiveTime time.Duration) *UserInactivityReport

type VolumeChanged

type VolumeChanged struct {
	*Message
	Payload struct {
		Volume int  `json:"volume"`
		Muted  bool `json:"muted"`
	} `json:"payload"`
}

The VolumeChanged event.

func NewVolumeChanged

func NewVolumeChanged(messageId string, volume int, muted bool) *VolumeChanged

type VolumeState

type VolumeState struct {
	*Message
	Payload struct {
		Volume int  `json:"volume"`
		Muted  bool `json:"muted"`
	} `json:"payload"`
}

The VolumeState context.

func NewVolumeState

func NewVolumeState(volume int, muted bool) *VolumeState

Jump to

Keyboard shortcuts

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