示例#1
0
文件: tts.go 项目: goleh/tts
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()
}
示例#2
0
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)
	}
}
示例#3
0
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)
	}
}
示例#4
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)
}
示例#5
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)
	}
}