Documentation ¶
Index ¶
- Constants
- func Listen(addr string, handler HandlerFunc) error
- type AGI
- func (a *AGI) Answer() error
- func (a *AGI) Close() (err error)
- func (a *AGI) Command(cmd ...string) (resp *Response)
- func (a *AGI) EAGI() io.Reader
- func (a *AGI) Exec(cmd ...string) (string, error)
- func (a *AGI) Get(key string) (string, error)
- func (a *AGI) GetData(name string, timeout int, maxdigits int) (digit string, err error)
- func (a *AGI) Hangup() error
- func (a *AGI) MRCPRecog(grammar string, opts string) (*RecognitionResult, error)
- func (a *AGI) MRCPSynth(prompt string, opts string) (res *SynthResult, err error)
- func (a *AGI) RecognitionConfidence(index int) (int, error)
- func (a *AGI) RecognitionGrammar(index int) (string, error)
- func (a *AGI) RecognitionInput(index int) (string, error)
- func (a *AGI) RecognitionInterpretation(index int) (ret *RecognitionInterpretation, err error)
- func (a *AGI) Record(name string, opts *RecordOptions) error
- func (a *AGI) SayAlpha(label string, escapeDigits string) (digit string, err error)
- func (a *AGI) SayDate(when time.Time, escapeDigits string) (digit string, err error)
- func (a *AGI) SayDateTime(when time.Time, escapeDigits string, format string) (digit string, err error)
- func (a *AGI) SayDigits(number string, escapeDigits string) (digit string, err error)
- func (a *AGI) SayNumber(number string, escapeDigits string) (digit string, err error)
- func (a *AGI) SayPhonetic(phrase string, escapeDigits string) (digit string, err error)
- func (a *AGI) SayTime(when time.Time, escapeDigits string) (digit string, err error)
- func (a *AGI) Set(key, val string) error
- func (a *AGI) SetLogger(l *log.Logger) error
- func (a *AGI) Status() (State, error)
- func (a *AGI) StreamFile(name string, escapeDigits string, offset int) (digit string, err error)
- func (a *AGI) SynthAndRecog(prompt string, grammar string, opts string) (*RecognitionResult, error)
- func (a *AGI) Verbose(msg string, level int) error
- func (a *AGI) Verbosef(format string, args ...interface{}) error
- func (a *AGI) WaitForDigit(timeout time.Duration) (digit string, err error)
- type HandlerFunc
- type RecognitionInterpretation
- type RecognitionResult
- type RecordOptions
- type Response
- type State
- type SynthResult
Constants ¶
const ( // StatusOK indicates the AGI command was // accepted. StatusOK = 200 // StatusInvalid indicates Asterisk did not // understand the command. StatusInvalid = 510 // StatusDeadChannel indicates that the command // cannot be performed on a dead (hungup) channel. StatusDeadChannel = 511 // StatusEndUsage indicates...TODO StatusEndUsage = 520 )
Variables ¶
This section is empty.
Functions ¶
func Listen ¶
func Listen(addr string, handler HandlerFunc) error
Listen binds an AGI HandlerFunc to the given TCP `host:port` address, creating a FastAGI service.
Types ¶
type AGI ¶
type AGI struct { // Variables stored the initial variables // transmitted from Asterisk at the start // of the AGI session. Variables map[string]string // contains filtered or unexported fields }
AGI represents an AGI session
func NewEAGI ¶
func NewEAGI() *AGI
NewEAGI returns a new AGI session to stdin, the EAGI stream (FD=3), and stdout.
func NewWithEAGI ¶
NewWithEAGI returns a new AGI session to the given `os.Stdin` `io.Reader`, EAGI `io.Reader`, and `os.Stdout` `io.Writer`. The initial variables will be read in.
func (*AGI) Command ¶
Command sends the given command line to stdout and returns the response. TODO: this does not handle multi-line responses properly
func (*AGI) MRCPRecog ¶ added in v0.2.0
func (a *AGI) MRCPRecog(grammar string, opts string) (*RecognitionResult, error)
MRCPRecog listens for speech and optionally plays a prompt. (requires UniMRCP app and resource to be compiled and loaded in Asterisk).
func (*AGI) MRCPSynth ¶ added in v0.2.0
func (a *AGI) MRCPSynth(prompt string, opts string) (res *SynthResult, err error)
MRCPSynth synthesizes speech for a prompt via MRCP. (requires UniMRCP app and resource to be compiled and loaded in Asterisk).
func (*AGI) RecognitionConfidence ¶ added in v0.2.0
RecognitionConfidence returns the confidence level (0-100 with 100 being best) from the last MRCP speech recognition process. The index is based on the set of results ordered by decreasing confidence. Thus index 0 is the best match.
func (*AGI) RecognitionGrammar ¶ added in v0.2.0
RecognitionGrammar returns the grammar which was matched from the last MRCP speech recognition process. The index is based on the set of result ordered by decreasing confidence. Thus index 0 is the best match.
func (*AGI) RecognitionInput ¶ added in v0.2.0
RecognitionInput returns the detected input from the last MRCP speech recognition process. The index is based on the set of results ordered by decreasing confidence. Thus index 0 is the best match.
func (*AGI) RecognitionInterpretation ¶ added in v0.2.0
func (a *AGI) RecognitionInterpretation(index int) (ret *RecognitionInterpretation, err error)
RecognitionInterpretation returns the speech interpretation from the last MRCP speech recognition process. The index is based on the set of results ordered by decreasing confidence. Thus index 0 is the best match.
func (*AGI) Record ¶
func (a *AGI) Record(name string, opts *RecordOptions) error
Record records audio to a file
func (*AGI) SayDateTime ¶
func (a *AGI) SayDateTime(when time.Time, escapeDigits string, format string) (digit string, err error)
SayDateTime plays a date using the given format. See `voicemail.conf` for the format syntax; defaults to `ABdY 'digits/at' IMp`.
func (*AGI) SayPhonetic ¶
SayPhonetic plays the given phrase phonetically
func (*AGI) StreamFile ¶
StreamFile plays the given file to the channel
func (*AGI) SynthAndRecog ¶ added in v0.2.0
SynthAndRecog plays a synthesized prompt and waits for speech to be recognized (requires UniMRCP app and resource to be compiled and loaded in Asterisk).
type HandlerFunc ¶
type HandlerFunc func(*AGI)
HandlerFunc is a function which accepts an AGI instance
type RecognitionInterpretation ¶ added in v0.2.0
type RecognitionInterpretation struct { // Confidence indicates how sure the MRCP server's engine was that the result was properly recognized. It is a value from 0-100, with the highest value indicating the most confidence. Confidence int // Input is the textual representation of the recognized speech Input string // Grammar indicates the grammar or recognition rule which was matched Grammar string }
RecognitionInterpretation describes a specific interpretation of speech input
type RecognitionResult ¶ added in v0.2.0
type RecognitionResult struct { // Status indicates the value of RECOG_STATUS, which is one of "OK", "ERROR", or "INTERRUPTED", which indicates whether the recognition process completed. // // "OK" - the recognition executed properly // // "ERROR" - the recognition failed to execute // // "INTERRUPTED" - the call ended before the recognition could complete its execution // Status string // Cause indicates the value of RECOG_COMPLETION_CAUSE, which indicates whether speech was recognized. // // Possible values are: // // 0 - Success; speech was recognized // // 1 - No Match; speech was detected but it did not match anything in the grammar // // 2 - No Input; no speech was detected // Cause int // Result is the value of RECOG_RESULT, which contains the NLSML result (unparsed string) received from the MRCP server. Result string }
RecognitionResult describes the result of an MRCP speech recognition action
type RecordOptions ¶
type RecordOptions struct { // Format is the format of the audio file to record; defaults to "wav". Format string // EscapeDigits is the set of digits on receipt of which will terminate the recording. Default is "#". This may not be blank. EscapeDigits string // Timeout is the maximum time to allow for the recording. Defaults to 5 minutes. Timeout time.Duration // Silence is the maximum amount of silence to allow before ending the recording. The finest resolution is to the second. 0=disabled, which is the default. Silence time.Duration // Beep controls whether a beep is played before starting the recording. Defaults to false. Beep bool // Offset is the number of samples in the recording to advance before storing to the file. This is means of clipping the beginning of a recording. Defaults to 0. Offset int }
RecordOptions describes the options available when recording
type Response ¶
type Response struct { Error error // Error received, if any Status int // HTTP-style status code received Result int // Result is the numerical return (if parseable) ResultString string // Result value as a string Value string // Value is the (optional) string value returned }
Response represents a response to an AGI request.
type State ¶
type State int
State describes the Asterisk channel state. There are mapped directly to the Asterisk enumerations.
const ( // StateDown indicates the channel is down and available StateDown State = iota // StateReserved indicates the channel is down but reserved StateReserved // StateOffhook indicates that the channel is offhook StateOffhook // StateDialing indicates that digits have been dialed StateDialing // StateRing indicates the channel is ringing StateRing // StateRinging indicates the channel's remote end is rining (the channel is receiving ringback) StateRinging // StateUp indicates the channel is up StateUp // StateBusy indicates the line is busy StateBusy // StateDialingOffHook indicates digits have been dialed while offhook StateDialingOffHook // StatePreRing indicates the channel has detected an incoming call and is waiting for ring StatePreRing )
type SynthResult ¶ added in v0.2.0
type SynthResult struct { // Status indicates whether the operation completed. // // Valid values are: // // - "OK" : the synthesis operation succeeded // // - "ERROR" : the synthesis operation failed // // - "INTERRUPTED" : the channel disappeared during the synthesis operation // Status string // Cause is a numeric code indicating the reason for the status // // Known values are: // // - 0 : Normal // // - 1 : Barge-In occurred // // - 2 : Parse failure // Cause int }
SynthResult describes the result of an MRCP Synthesis operation