Exemple #1
0
func ExampleIvona_CreateSpeech() {
	client := ivona.New("IVONA_ACCESS_KEY", "IVONA_SECRET_KEY")
	options := ivona.NewSpeechOptions("Hello World")
	r, err := client.CreateSpeech(options)

	if err != nil {
		log.Fatal(err)
	}

	log.Printf("%v\n", len(r.Audio))
	log.Printf("%v\n", r.ContentType)
	log.Printf("%v\n", r.RequestID)
}
Exemple #2
0
func GetTTS(text, voice string) (resp []byte, err error) {
	log.Println("--- GetTTS", text, voice)

	v, ok := voicesMap[voice]
	if !ok {
		err = errors.New("Invalid voice name")
		return
	}
	options := ivonago.NewSpeechOptions(text)
	options.Voice = &v //set voice options
	options.OutputFormat.Codec = "OGG"

	r, err := client.CreateSpeech(options)
	if err != nil {
		log.Println("Error getting response from Ivona: text:", err)
		return
	}

	return r.Audio, err
}
Exemple #3
0
func TestIvona_CreateSpeech(t *testing.T) {
	client := ivona.New(ivonaAccessKey, ivonaSecretKey)
	options := ivona.NewSpeechOptions(testText)
	r, err := client.CreateSpeech(options)

	if err != nil {
		t.Error(err)
	}

	audioLength := len(r.Audio)
	expectedAudioLength := 6314
	expectedContentType := "audio/mpeg"

	if r.ContentType != expectedContentType {
		t.Errorf("ContentType %v does not match", r.ContentType)
	}

	if audioLength != expectedAudioLength {
		t.Errorf("Audio length %v does not match", audioLength)
	}
}