Created
October 5, 2019 13:14
-
-
Save RudolfVonKrugstein/ace250bd83cb957b8881c99b0bd64b59 to your computer and use it in GitHub Desktop.
First version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/polly" | |
"github.com/chzyer/readline" | |
"io/ioutil" | |
"os" | |
"os/exec" | |
) | |
func main() { | |
// Create readline instance | |
l, err := readline.New(" > ") | |
if err != nil { | |
panic(err) | |
} | |
defer l.Close() | |
// Create amazon polly client | |
sess, err := session.NewSessionWithOptions(session.Options{ | |
Config: aws.Config{ | |
Region: aws.String("eu-central-1"), | |
}, | |
Profile: "amazon-polly-profile", | |
SharedConfigState: session.SharedConfigEnable, | |
}) | |
if err != nil { | |
panic(err) | |
} | |
client := polly.New(sess) | |
// Do forever | |
for { | |
// Read a line from the user | |
line, err := l.Readline() | |
if err != nil { | |
panic(err) | |
} | |
// Use amazon polly to synthesize speach | |
input := &polly.SynthesizeSpeechInput{ | |
OutputFormat: aws.String("ogg_vorbis"), | |
Text: aws.String(line), | |
VoiceId: aws.String("Marlene"), | |
} | |
result, err := client.SynthesizeSpeech(input) | |
if err != nil { | |
panic(err) | |
} | |
defer result.AudioStream.Close() | |
// Write the resulting ogg to /tmp/test.ogg | |
bytes, _ := ioutil.ReadAll(result.AudioStream) | |
ioutil.WriteFile("/tmp/test.ogg", bytes, os.ModePerm) | |
// Play the ogg using mplayer | |
cmd := exec.Command("mplayer", "/tmp/test.ogg") | |
cmd.Run() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment