Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. func readInput(c chan string) {
  2. l, err := readline.New(" > ")
  3. if err != nil {
  4. panic(err)
  5. }
  6. defer l.Close()
  7. for {
  8. line, err := l.Readline()
  9. if err != nil {
  10. panic(err)
  11. }
  12. c <- line
  13. }
  14. }
  15.  
  16. func executeCommands(command PollyCommand) error {
  17. sess, err := session.NewSessionWithOptions(session.Options{
  18. Config: aws.Config{
  19. Region: aws.String("eu-central-1"),
  20. },
  21. Profile: "wintercloud-test",
  22. SharedConfigState: session.SharedConfigEnable,
  23. })
  24. if err != nil {
  25. return err
  26. }
  27. client := polly.New(sess)
  28.  
  29. input := &polly.SynthesizeSpeechInput{
  30. OutputFormat: aws.String("ogg_vorbis"),
  31. Text: aws.String(command.speakText),
  32. VoiceId: aws.String(command.voice),
  33. SampleRate: aws.String("22050"),
  34. }
  35. result, err := client.SynthesizeSpeech(input)
  36.  
  37. if err != nil {
  38. return err
  39. }
  40. defer result.AudioStream.Close()
  41.  
  42. bytes, _ := ioutil.ReadAll(result.AudioStream)
  43. ioutil.WriteFile("/tmp/test.ogg", bytes, os.ModePerm)
  44.  
  45. cmd := exec.Command("mplayer", "/tmp/test.ogg")
  46. cmd.Run()
  47.  
  48. return nil
  49. }
  50.  
  51.  
  52. func main() {
  53.  
  54. c := make(chan PollyCommand, 100)
  55. go readInput(c)
  56. for {
  57. command := <- c
  58. err := executeCommands(command)
  59. if err != nil {
  60. panic(err)
  61. }
  62. time.Sleep(1 * time.Second)
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement