Documentation ¶
Index ¶
- type AudioContext
- func (c *AudioContext) AddEntity(segmentID int32, e Entity) error
- func (c *AudioContext) AddTranscript(segmentID int32, t Transcript) error
- func (c AudioContext) CheckID(id string) error
- func (c *AudioContext) Finalise() error
- func (c *AudioContext) FinaliseSegment(segmentID int32) error
- func (c *AudioContext) SetID(id string) error
- func (c *AudioContext) SetIntent(segmentID int32, i Intent) error
- type AudioContextHandler
- type AudioSource
- type Client
- type Config
- type Entities
- type Entity
- type EntityIndex
- type EntityIndexList
- type Intent
- type RecogniseStream
- type Segment
- type Segments
- type Transcript
- type Transcripts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AudioContext ¶
type AudioContext struct { ID uuid.UUID `json:"id"` Segments Segments `json:"segments"` IsFinalised bool `json:"is_finalised"` }
AudioContext represents a single SLU audio context, which can have multiple segments. See Speechly documentation for more information about audio contexts.
func NewAudioContext ¶
func NewAudioContext() AudioContext
NewAudioContext returns a new AudioContext.
func (*AudioContext) AddEntity ¶
func (c *AudioContext) AddEntity(segmentID int32, e Entity) error
AddEntity adds an entity to the specific segment of the context.
func (*AudioContext) AddTranscript ¶
func (c *AudioContext) AddTranscript(segmentID int32, t Transcript) error
AddTranscript adds a transcript to the specific segment of the context.
func (AudioContext) CheckID ¶
func (c AudioContext) CheckID(id string) error
CheckID checks if provided id matches current context.
func (*AudioContext) Finalise ¶
func (c *AudioContext) Finalise() error
Finalise finalises the audio context by finalising all segments in it.
func (*AudioContext) FinaliseSegment ¶
func (c *AudioContext) FinaliseSegment(segmentID int32) error
FinaliseSegment finalises specific segment in the context.
func (*AudioContext) SetID ¶
func (c *AudioContext) SetID(id string) error
SetID sets the ID to the context.
type AudioContextHandler ¶
type AudioContextHandler interface { // Read reads the next AudioContext state from the handler. // If the context has been stopped, this will return io.EOF. // If any error has happened while handling the context, this will return it. Read() (AudioContext, error) // Close closes the handler by signalling it to send the StopContext event and exit the loop. Close() error }
AudioContextHandler is a handler for a single AudioContext stream. It handles the sending of audio data by starting a new audio context, sending audio data and stopping the context. It handles the receiving of SLU responses by processing them into an AudioContext state and exposing an API to access the snapshots of that state.
An example of such state progression is something like this:
* First state:
{ "id": "ae275a56-66b6-49a3-addb-90df03edb946", "segments": [], "is_finalised": false }
* Second state:
{ "id": "ae275a56-66b6-49a3-addb-90df03edb946", "segments": [ { "id": 0, "is_finalised": false, "transcripts": [ { "word": "TURN", "index": 2, "start_time": 480, "end_time": 720, "is_finalised": false } ], "entities": [], "intent": { "value": "", "is_finalised": false } } ], "is_finalised": false }
* Third state:
{ "id": "ae275a56-66b6-49a3-addb-90df03edb946", "segments": [ { "id": 0, "is_finalised": false, "transcripts": [ { "word": "TURN", "index": 2, "start_time": 480, "end_time": 900, "is_finalised": false }, { "word": "OFF", "index": 3, "start_time": 900, "end_time": 1020, "is_finalised": false } ], "entities": [], "intent": { "value": "turn_off", "is_finalised": true } } ], "is_finalised": false }
And so forth, until eventually the context is finalised by the API.
type AudioSource ¶
AudioSource is the interface that represents the audio data source that is sent to SLU API within a particular audio context.
type Client ¶
Client is a client for Speechly SLU API.
func NewClient ¶
NewClient returns a new Client that will access provided URL with provided access token.
func (*Client) StreamingRecognise ¶
StreamingRecognise starts a new SLU recognition stream with specified Config.
type Config ¶
Config is the configuration of an SLU recognition stream. It is used by the client to send Config requests when starting new streams. For more information, check the Speechly SLU API documentation.
type Entities ¶ added in v1.0.2
type Entities map[EntityIndex]Entity
Entities is a map of SLU entities.
func NewEntities ¶ added in v1.0.2
NewEntities returns new Entities constructed from e.
func (Entities) MarshalJSON ¶ added in v1.0.2
MarshalJSON implements json.Marshaler.
type Entity ¶
type Entity struct { Type string `json:"type"` Value string `json:"value"` StartIndex int32 `json:"start_index"` EndIndex int32 `json:"end_index"` IsFinalised bool `json:"is_finalised"` }
Entity is the entity detected by SLU API.
type EntityIndex ¶ added in v1.0.2
type EntityIndex struct {
StartIndex, EndIndex int32
}
EntityIndex is a struct used for indexing entities.
type EntityIndexList ¶ added in v1.0.4
type EntityIndexList []EntityIndex
EntityIndexList is a list of entity indices. It implements the sort.Interface, so it can be used for obtaining sorted list of entity indices.
func SortedEntityIndexList ¶ added in v1.0.4
func SortedEntityIndexList(e Entities) EntityIndexList
SortedEntityIndexList returns a sorted version of EntityIndexList constructed from Entities.
func (EntityIndexList) Len ¶ added in v1.0.4
func (e EntityIndexList) Len() int
func (EntityIndexList) Less ¶ added in v1.0.4
func (e EntityIndexList) Less(i, j int) bool
func (EntityIndexList) Swap ¶ added in v1.0.4
func (e EntityIndexList) Swap(i, j int)
type RecogniseStream ¶
type RecogniseStream interface { // NewAudioContext starts a new audio context by sending a START even to SLU API. // If there is already an audio context running, // this will block until the running context is stopped, or the stream closed. NewAudioContext(context.Context, AudioSource, int) (AudioContextHandler, error) // Close closes the stream by closing the sending part of gRPC stream. // It will wait for current audio context (if any) to be stopped, before closing the stream. Close() error }
RecogniseStream is a single SLU recognition stream, which maps to a gRPC stream. Since one stream can have multiple contexts RecogniseStream provides an API for launching these. However, only a single audio context can be active at a time, which is controlled and guaranteed by the stream.
type Segment ¶
type Segment struct { ID int32 `json:"id"` IsFinalised bool `json:"is_finalised"` Transcripts Transcripts `json:"transcripts"` Entities Entities `json:"entities"` Intent Intent `json:"intent"` }
Segment represents a single SLU segment, which is bounded by a single SLU intent. See Speechly documentation for more information about segments.
func NewSegment ¶
NewSegment returns a new Segment with specified ID.
func (*Segment) AddTranscript ¶
func (s *Segment) AddTranscript(t Transcript) error
AddTranscript adds a transcript to a segment. This cannot be called after segment was finalised.
type Segments ¶ added in v1.0.2
Segments is a map of SLU segments.
func NewSegments ¶ added in v1.0.2
NewSegments returns a new Segments constructed from s.
func (Segments) Get ¶ added in v1.0.2
Get retrieves a Segment by id. If a Segment with given id is not present, it will instead be added to s and returned.
func (Segments) MarshalJSON ¶ added in v1.0.2
MarshalJSON implements json.Marshaler.
type Transcript ¶
type Transcript struct { Word string `json:"word"` Index int32 `json:"index"` StartTime int32 `json:"start_time"` EndTime int32 `json:"end_time"` IsFinalised bool `json:"is_finalised"` }
Transcript is a transcript of a word, detected by Speechly SLU API.
func (*Transcript) Parse ¶
func (t *Transcript) Parse(v *sluv1.SLUTranscript, isTentative bool) error
Parse parses response from API into Transcript.
type Transcripts ¶ added in v1.0.2
type Transcripts map[int32]Transcript
Transcripts is a map of SLU transcripts.
func NewTranscripts ¶ added in v1.0.2
func NewTranscripts(t []Transcript) Transcripts
NewTranscripts returns a new Transcripts constructed from t.
func (Transcripts) MarshalJSON ¶ added in v1.0.2
func (t Transcripts) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.