Documentation
¶
Index ¶
- Constants
- type APIError
- type APIRequest
- type Client
- func (client *Client) NewAPIRequest(resource string) *APIRequest
- func (client *Client) SetAuthTokens() error
- func (client *Client) SpeechToText(apiRequest *APIRequest) (*Recognition, error)
- func (client *Client) SpeechToTextCustom(apiRequest *APIRequest, grammar string, dictionary string) (*Recognition, error)
- func (client *Client) TextToSpeech(apiRequest *APIRequest) ([]byte, error)
- type Recognition
- type Token
Constants ¶
const ( // APIBase is the base URL for the ATT Speech API APIBase = "https://api.att.com" // STTResource is the speech to text resource STTResource = "/speech/v3/speechToText" // STTCResource is the speech to text custom resource STTCResource = "/speech/v3/speechToTextCustom" // TTSResource is the text to speech resource TTSResource = "/speech/v3/textToSpeech" // OauthResource is the oauth resource OauthResource = "/oauth/access_token" // UserAgent is the user agent use for the HTTP client UserAgent = "GoATTSpeechLib" // Version is the version of the ATT Speech API Version = "0.1" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
RequestError struct {
ServiceException struct {
MessageID string `json:"MessageId"`
Text string `json:"Text"`
Variables string `json:"Variables"`
} `json:"ServiceException"`
PolicyException struct {
MessageID string `json:"MessageId"`
Text string `json:"Text"`
Variables string `json:"Variables"`
} `json:"PolicyException"`
} `json:"RequestError"`
}
APIError represents an error from the AT&T Speech API
type APIRequest ¶
type APIRequest struct {
Accept string
Authorization string
ContentLanguage string
ContentLength string
ContentType string
Data *bytes.Buffer
Filename string
Tempo string
Text string
TransferEncoding string
VoiceName string
Volume string
UserAgent string
XArg string
XSpeechContext string
XSpeechSubContext string
}
APIRequest represents the parameters for a Text to Speech request
type Client ¶
type Client struct {
APIBase string
STTResource string
STTCResource string
TTSResource string
OauthResource string
ID string
Secret string
Tokens map[string]*Token
Scope [3]string
}
Client is an ATT Speech API client
func New ¶
New creates a new AttSpeechClient
client := attspeech.New("<id>", "<secret>", "")
client.SetAuthTokens()
func (*Client) NewAPIRequest ¶
func (client *Client) NewAPIRequest(resource string) *APIRequest
NewAPIRequest sets the common headers for TTS and STT
client := attspeech.New("<id>", "<secret>", "")
client.SetAuthTokens()
apiRequest := client.NewAPIRequest(TTSResource)
Note, when setting apiRequest.XArg, always append with '+=', unless you specifically intend to overwrite the defaults for ClientApp, ClientVersion, DeviceType and DeviceOs
func (*Client) SetAuthTokens ¶
SetAuthTokens sets the provided authorization tokens for the client
client := attspeech.New("<id>", "<secret>", "")
client.SetAuthTokens()
func (*Client) SpeechToText ¶
func (client *Client) SpeechToText(apiRequest *APIRequest) (*Recognition, error)
SpeechToText converts an audio file to text
client := attspeech.New("<id>", "<secret>", "")
client.SetAuthTokens()
apiRequest := client.NewAPIRequest(STTResource)
apiRequest.Data = data // where data is audio content as *bytes.Buffer
apiRequest.ContentType = "audio/wav"
result, apiError, err := client.SpeechToText(apiRequest)
More details available here:
http://developer.att.com/apis/speech/docs#resources-speech-to-text
func (*Client) SpeechToTextCustom ¶
func (client *Client) SpeechToTextCustom(apiRequest *APIRequest, grammar string, dictionary string) (*Recognition, error)
SpeechToTextCustom converts an audio file to text
client := attspeech.New("<id>", "<secret>", "")
client.SetAuthTokens()
apiRequest := client.NewAPIRequest(STTResource)
apiRequest.Data = data // where data is audio content as *bytes.Buffer
apiRequest.ContentType = "audio/wav"
apiRequest.Filename = "test.wav"
result, apiError, err := client.SpeechToTextCustom(apiRequest, "<some srgs XML>", "<some pls XML>")
More details available here:
http://developer.att.com/apis/speech/docs#resources-speech-to-text-custom
func (*Client) TextToSpeech ¶
func (client *Client) TextToSpeech(apiRequest *APIRequest) ([]byte, error)
TextToSpeech converts text to a speech file
client := attspeech.New("<id>", "<secret>", "")
client.SetAuthTokens()
apiRequest := client.NewAPIRequest(TTSResource)
apiRequest.Accept = "audio/x-wav",
apiRequest.VoiceName = "crystal",
apiRequest.Text = "I want to be an airborne ranger, I want to live the life of danger.",
data, err := client.TextToSpeech(apiRequest)
More details available here:
http://developer.att.com/apis/speech/docs#resources-text-to-speech
type Recognition ¶
type Recognition struct {
Recognition struct {
Status string `json:"Status"`
ResponseID string `json:"ResponseId"`
NBest []struct {
Hypothesis string `json:"Hypothesis"`
LanguageID string `json:"LanguageId"`
Confidence float32 `json:"Confidence"`
Grade string `json:"Grade"`
ResultText string `json:"ResultText"`
Words []string `json:"Words"`
WordScores []float32 `json:"WordScores"`
NluHypothesis struct {
OutComposite []struct {
Grammar string `json:"Grammar"`
Out string `json:"Out"`
} `json:"OutComposite"`
} `json:"NluHypothesis"`
} `json:"NBest"`
} `json:"Recognition"`
}
Recognition represents at AT&T recognition response