📜 ⬆️ ⬇️

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

We specify in the script the path to the book in txt - at the output we get a folder with voice acting by a good synthesis.

I like to consume content with my ears - at this time you can play sports or rest your eyes. I'm used to the fact that any normal book has an audio version, at worst an amateur version, but this is not always the case. Today, I spent a few hours sorting through various online services and Android programs for pronouncing Russian text - from only Pocket who liked, which uses Google TTS and Google Books with the same engine, but with a different voice quality. Also interesting is SpeechKit from Yandex . But it seems like the best synthesis from Ivona - this company was bought by Amazon in 2013. Githab found about a dozen scripts for pulling the finished sound, but there was no complete solution for the dubbing of the whole book. Using an unofficial Go-library for IVONA Speech Cloud API, I wrote a script for several hours - for the first time I use Go, it’s convenient that all dependencies are in one file, even the library from GitHub pulls up automatically.

The script creates one ogg file per paragraph - I had a book in plaintext, of course it would be more logical to break into chapters, but the whole book feed did not work - there is a limit on the input number of characters, about ten minutes of voice acting at normal speed. The output format can be changed to mp3. File names are normally sorted in order. When the script is running, the current paragraph sent to the voice acting is shown in the console.


')
For the script to work, you need the access key and secret key - I left my own ones here, but if it stops working, you can get new keys for free here .

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 = "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/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 character on which the file is split and specifying English instead of Russian), run the script - in about ten minutes we get about a hundred pages of finished tts:
 go run ivona-tts.go 

This is my first go code, welcome your criticism.

PS: First of all, it is better to look for a version of the book already voiced by man.

Source: https://habr.com/ru/post/275587/


All Articles