Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jpadilla committed Sep 25, 2014
1 parent 0415cd4 commit f5a6ace
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 43 deletions.
58 changes: 16 additions & 42 deletions ivona.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package ivona

import (
"bytes"
"encoding/json"
// "fmt"
"fmt"
"github.com/bmizerany/aws4"
// "io"
// "log"
"net/http"
// "os"
// "strings"
"bytes"
"io/ioutil"
"net/http"
)

const (
IvonaAPI = "https://tts.eu-west-1.ivonacloud.com"
CreateSpeechAPI = IvonaAPI + "/CreateSpeech"
)
// ivonaAPI is the public API IVONA Speech Cloud URL.
const ivonaAPI = "https://tts.eu-west-1.ivonacloud.com"

// createSpeechAPI is the public API IVONA Speech Cloud URL for the CreateSpeech action.
const createSpeechAPI = ivonaAPI + "/CreateSpeech"

// Ivona is used to invoke API calls
type Ivona struct {
AccessKey string
SecretKey string
}

// New returns a new Ivona client.
func New(accessKey string, secretKey string) *Ivona {
return &Ivona{AccessKey: accessKey, SecretKey: secretKey}
}

// CreateSpeech performs a synthesis of the requested text and returns the audio stream containing the speech.
func (client *Ivona) CreateSpeech(options SpeechOptions) (*SpeechResponse, error) {
b, err := json.Marshal(options)

Expand Down Expand Up @@ -56,39 +56,13 @@ func (client *Ivona) CreateSpeech(options SpeechOptions) (*SpeechResponse, error
return nil, err
}

if resp.StatusCode != 200 {
return nil, fmt.Errorf("Got non 200 status code: %s %q", resp.Status, data)
}

return &SpeechResponse{
Audio: data,
RequestId: resp.Header["X-Amzn-Ivonattsrequestid"][0],
RequestID: resp.Header["X-Amzn-Ivonattsrequestid"][0],
ContentType: resp.Header["Content-Type"][0],
}, nil
}

// func main() {
// r, _ := http.NewRequest("POST", "https://tts.eu-west-1.ivonacloud.com/CreateSpeech", data)
// r.Header.Set("Content-Type", "application/json")

// Client := aws4.Client{Keys: &aws4.Keys{
// AccessKey: "GDNAI77EX24OLG2PG7XA",
// SecretKey: "zM9IBfwgyfleyy2QFT1mHR+W3SIuWHVZUii9iX4E",
// }}

// resp, err := Client.Do(r)
// if err != nil {
// log.Fatal(err)
// }

// defer resp.Body.Close()

// out, err := os.Create("voice.mp3")

// if err != nil {
// panic(err)
// }

// defer out.Close()

// fmt.Println(resp)
// fmt.Println(resp.Body)

// io.Copy(out, resp.Body)
// }
15 changes: 14 additions & 1 deletion model.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package ivona

// SpeechResponse is the resource representing response from CreateSpeech action.
type SpeechResponse struct {
Audio []byte
RequestId string
RequestID string
ContentType string
}

// SpeechOptions is the set of parameters that can be used on the CreateSpeech action.
// For more details see http://developer.ivona.com/en/speechcloud/api_ref_actions.html#CreateSpeech.
type SpeechOptions struct {
Input *Input
OutputFormat *OutputFormat
Parameters *Parameters
Voice *Voice
}

// NewSpeechOptions is the set of default parameters that can be used the CreateSpeech action.
// For more details see http://developer.ivona.com/en/speechcloud/api_ref_actions.html#CreateSpeech_DefaultValues.
func NewSpeechOptions(data string) SpeechOptions {
return SpeechOptions{
Input: &Input{
Expand All @@ -37,23 +42,31 @@ func NewSpeechOptions(data string) SpeechOptions {
}
}

// Input contains attributes describing the user input.
// For more details see http://developer.ivona.com/en/speechcloud/api_ref_data_types.html#DataTypes_Input.
type Input struct {
Data string
Type string
}

// OutputFormat contains attributes describing the audio compression and format in which the returned stream should be encoded.
// For more details see http://developer.ivona.com/en/speechcloud/api_ref_data_types.html#DataTypes_OutputFormat.
type OutputFormat struct {
Codec string
SampleRate int
}

// Parameters contains additional attributes affecting the generated speech.
// For more details see http://developer.ivona.com/en/speechcloud/api_ref_data_types.html#DataTypes_Parameters.
type Parameters struct {
Rate string
Volume string
SentenceBreak int
ParagraphBreak int
}

// Voice contains a filter for the voice selection that should be used for the speech synthesis.
// For more details see http://developer.ivona.com/en/speechcloud/api_ref_data_types.html#DataTypes_Voice.
type Voice struct {
Name string
Language string
Expand Down

0 comments on commit f5a6ace

Please sign in to comment.