func (v *voice) Say(r io.Reader, w io.Writer) error { if v == nil { return errors.New("Invalid voice") } client := ivona.New(Key, Secret) scanner := bufio.NewScanner(r) for scanner.Scan() { paragraph := strings.TrimSpace(scanner.Text()) if paragraph == "" { continue } options := ivona.NewSpeechOptions(paragraph) options.Voice.Language = v.Language options.Voice.Name = v.Name options.Voice.Gender = v.Gender options.OutputFormat.Codec = Codec r, err := client.CreateSpeech(options) if err != nil { return err } if _, err := w.Write(r.Audio); err != nil { return err } } return scanner.Err() }
func main() { client := ivona.New("", "") text, err := ioutil.ReadFile("/home/aliaksandr/work/ivona/audiobook/book.txt") if err != nil { log.Fatal(err) } arrayOfParagraphs := strings.Split(string(text), "\n") i := 0 for _, paragraph := range arrayOfParagraphs { if len(paragraph) < 4 { // against empty lines continue } log.Printf("%v\n", paragraph) options := ivona.NewSpeechOptions(paragraph) options.Voice.Language = "ru-RU" options.Voice.Name = "Maxim" options.Voice.Gender = "Male" options.OutputFormat.Codec = "OGG" r, err := client.CreateSpeech(options) if err != nil { log.Fatal(err) } i++ file := fmt.Sprintf("/home/aliaksandr/work/ivona/output/tts%04d.ogg", i) // files like 0001.ogg ioutil.WriteFile(file, r.Audio, 0644) } }
func main() { client := ivona.New("GDNAICTDMLSLU5426OAA", "2qUFTF8ZF9wqy7xoGBY+YXLEu+M2Qqalf/pSrd9m") text, err := ioutil.ReadFile("/home/vitaly/Desktop/article.txt") if err != nil { log.Fatal(err) } arrayOfParagraphs := strings.Split(string(text), "\n\n") i := 0 for _, paragraph := range arrayOfParagraphs { paragraph = strings.TrimSpace(paragraph) if len(paragraph) < 1 { // against empty lines continue } log.Printf("%s", paragraph) options := ivona.NewSpeechOptions(paragraph) options.Voice.Language = "ru-RU" options.Voice.Name = "Maxim" options.Voice.Gender = "Male" options.OutputFormat.Codec = "OGG" r, err := client.CreateSpeech(options) if err != nil { log.Fatal(err) } i++ file := fmt.Sprintf("/home/vitaly/Desktop/ivona-article/tts%04d.ogg", i) // files like 0001.ogg ioutil.WriteFile(file, r.Audio, 0644) } }
func ExampleIvona_ListVoices() { client := ivona.New("IVONA_ACCESS_KEY", "IVONA_SECRET_KEY") r, err := client.ListVoices(ivona.Voice{}) if err != nil { log.Fatal(err) } log.Printf("%v\n", len(r.Voices)) }
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) }
func TestIvona_ListVoices(t *testing.T) { client := ivona.New(ivonaAccessKey, ivonaSecretKey) r, err := client.ListVoices(ivona.Voice{}) if err != nil { t.Error(err) } voicesLength := len(r.Voices) expectedVoicesLength := 51 expectedContentType := "application/json" if voicesLength != expectedVoicesLength { t.Errorf("Voices length %v does not match", len(r.Voices)) } if r.ContentType != expectedContentType { t.Errorf("ContentType %v does not match", r.ContentType) } }
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) } }