Categorygithub.com/zemags/golang-yandex-speech-kit
repositorypackage
1.0.2
Repository: https://github.com/zemags/golang-yandex-speech-kit.git
Documentation: pkg.go.dev

# README

Golang Yandex Speech Kit Test And Linter Go Report Card Coverage Status

Small simple SDK to convert text to audio by Yandex Speech Kit Service.

SDK uses only premium voices.

Get Yandex Cloud service account Api-Key: https://cloud.yandex.com/en/docs/speechkit/concepts/auth

Example usage:

package main

import (
    "log"
    "os"
    "github.com/pkg/errors"
    speechkit "https://github.com/zemags/golang-yandex-speech-kit"

)

func main() {
	if err := godotenv.Load(); err != nil {
		log.Println("Can't find .env file")
	}
	API_KEY, exist := os.LookupEnv("API_KEY")
	if !exist {
		error.New("Yandex cloud service account Api-Key not provided")
	}
	
	client := &http.Client{Timeout: 5 * time.Second}
	apiParams := speechkit.APIParams{APIKey: API_KEY, Client: client}

        // define folder for mp3 audio
        currentDir, _ := os.Getwd()
        pathToFiles := path.Join(currentDir, "temp_folder")

	speechParams := speechkit.SpeechParams{
        	Voice: "male",
		Speed: 1.0,
        	PathToFiles: pathToFiles,
        }

        client := speechkit.NewSpeechKitClient(apiParams, speechParams)

        exampleTextForAudio := "Lorem Ipsum is simply dummy."
        err := client.CreateAudio(exampleTextForAudio)
        if err != nil {
           	log.Println(err))
	}
}

Define Yandex Cloud service accout Api-Key:

ParamTypeDefenition
API_KEYstringhttps://cloud.yandex.com/en/docs/speechkit/concepts/auth

You can define SpeechParams by this table:

ParamTypeVariablesDefaultDefenition
Voicestring"male"
"female"
"male""male" provided voice 'filipp'
"female" provided voice 'alena'
Speedfloat32from 0.1 to 3.01.0speed of synthesized speech
PathToFilesstringNEED TO DEFINENEED TO DEFINEpath to synthesized audio mp3