go-a script which makes an audiobook from a text file using one of the best speech synthesizers — from Ivona Amazon

Specify the script path to the book in txt file — the output folder with the voice acting good synthesis.

Love to consume content by the ears in this time, you can do sports and to give rest to your eyes. I used what any normal book has an audio version, in the worst case, the Amateur, however, this is not always the case. Today I several hours through various online services and Android-software for pronunciation of the Russian text — from vending only Pocket which uses the Google TTS and Google Books with the same engine, but why is another voice quality. Also interesting Yandex SpeechKit. But it seems the best synthesis Ivona this company in 2013 was bought by Amazon. Github found a dozen scripts ready for jerking sound, but ready solutions for the voice-the whole book was not. Using informal Go-library for IVONA Speech Cloud API a few hours wrote the script for the first time use Go, because all the dependencies in a single file, even a library with Github tightens automatically.

Script makes one ogg file on a paragraph — I had the book in plaintext, of course it would be logical to split by chapters, and entire book to feed did not work — there is a limit on the input number of characters, about ten minutes of voice at normal speed. The output format can be changed to mp3. File names are normally sorted by order. When the script console shows the current paragraph is sent to the voice acting.



For the script to work you need access key and secret key — I left here, but if you stop working — you can free to get new keys here.

the
package main
import (
"log"
"fmt"
"io/ioutil"
"strings"
ivona "github.com/jpadilla/ivona-go"
)
func main() {
client := ivona.New("GDNAICTDMLSLU5426OAA", "2qUFTF8ZF9wqy7xoGBY+YXLEu+M2Qqalf/pSrd9m")
text, err := ioutil.ReadFile("/home/vitaly/Desktop/test.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("%v\n", paragraph)
options := ivona.NewSpeechOptions(paragraph)
options.Voice.Language = "EN-us"
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/tts%04d.ogg", i) // files like 0001.ogg
ioutil.WriteFile(file, r.Audio, 0644)
}
}


After replacing the path to the book and the path to the output folder (and possibly replacing the symbol which is the split file as well as putting English instead of Russian) run the script ten minutes get about a hundred pages ready tts:
the
go run ivona tts.go

This is my first go code, I welcome your criticism.

PS: the First thing is better to look for the already announced man version of the book.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Fresh hay from the cow, or 3000 icons submitted!

Knowledge base. Part 2. Freebase: make requests to the Google Knowledge Graph

Group edit the resources (documents) using MIGXDB