Text2Speech in Golang sdk provided in IBM Watson.

Tuned Gopher.
package mainimport ("bytes"
"fmt"
"os"
"github.com/IBM/go-sdk-core/core"
"github.com/watson-developer-cloud/go-sdk/texttospeechv1"
)func main() {authenticator := &core.IamAuthenticator{ApiKey: "tF#######################ZD@@",}options := &texttospeechv1.TextToSpeechV1Options{Authenticator: authenticator,}textToSpeech,textToSpeechErr:= texttospeechv1.NewTextToSpeechV1(options)
if textToSpeechErr != nil {
panic(textToSpeechErr)
}
textToSpeech.SetServiceURL("https://api.eu-gb.text-to-speech.watson.cloud.ibm.com##############")result, response, responseErr := textToSpeech.Synthesize(&texttospeechv1.SynthesizeOptions{Text: core.StringPtr("Welcome to the world of Go"),
Accept: core.StringPtr("audio/wav"),
Voice: core.StringPtr(texttospeechv1.SynthesizeOptionsVoiceEnGbJamesv3voiceConst),
},
)
fmt.Println(response)
if responseErr != nil {
panic(responseErr)
}
if result != nil {
buff := new(bytes.Buffer)
buff.ReadFrom(result)
file, _ := os.Create("hello_world.wav")
file.Write(buff.Bytes())
file.Close()
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store