Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement