Skip to content

Instantly share code, notes, and snippets.

@RudolfVonKrugstein
Created October 5, 2019 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RudolfVonKrugstein/3f9e13f63a3242968ed5b549a7dc8a3c to your computer and use it in GitHub Desktop.
Save RudolfVonKrugstein/3f9e13f63a3242968ed5b549a7dc8a3c to your computer and use it in GitHub Desktop.
second version
func readInput(c chan string) {
l, err := readline.New(" > ")
if err != nil {
panic(err)
}
defer l.Close()
for {
line, err := l.Readline()
if err != nil {
panic(err)
}
c <- line
}
}
func executeCommands(command PollyCommand) error {
sess, err := session.NewSessionWithOptions(session.Options{
Config: aws.Config{
Region: aws.String("eu-central-1"),
},
Profile: "wintercloud-test",
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
return err
}
client := polly.New(sess)
input := &polly.SynthesizeSpeechInput{
OutputFormat: aws.String("ogg_vorbis"),
Text: aws.String(command.speakText),
VoiceId: aws.String(command.voice),
SampleRate: aws.String("22050"),
}
result, err := client.SynthesizeSpeech(input)
if err != nil {
return err
}
defer result.AudioStream.Close()
bytes, _ := ioutil.ReadAll(result.AudioStream)
ioutil.WriteFile("/tmp/test.ogg", bytes, os.ModePerm)
cmd := exec.Command("mplayer", "/tmp/test.ogg")
cmd.Run()
return nil
}
func main() {
c := make(chan PollyCommand, 100)
go readInput(c)
for {
command := <- c
err := executeCommands(command)
if err != nil {
panic(err)
}
time.Sleep(1 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment