Skip to content

Commit

Permalink
init speakers only once
Browse files Browse the repository at this point in the history
  • Loading branch information
AkselsLedins committed Jan 23, 2019
1 parent a58d64d commit cfc24b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 12 additions & 10 deletions howl/audio.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
package howl

import (
"fmt"
"io"
"time"
"log"

"github.com/faiface/beep"
"github.com/faiface/beep/speaker"
"github.com/faiface/beep/vorbis"
)

// PlayAudioStream will output a stream to device speakers
func PlayAudioStream(as io.ReadCloser) {
// we decode the ogg stream
s, format, _ := vorbis.Decode(as)

// the sample rate is set to 12000 as s.SampleRate does
// InitAudio inits the audio speaker
func InitAudio() {
// the sample rate is set to 12000 as format.SampleRate does
// not return an accurate value
err := speaker.Init(12000, format.SampleRate.N(time.Second))
err := speaker.Init(12000, 12000)
if err != nil {
fmt.Println("audio: err: could not play audio stream")
log.Fatal("audio: could not init speaker")
return
}
}

// PlayAudioStream will output a stream to device speakers
func PlayAudioStream(as io.ReadCloser) {
// we decode the ogg stream
s, _, _ := vorbis.Decode(as)

// channel, which will signal the end of the playback.
playing := make(chan struct{})
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
func main() {
// load config
howl.LoadConfig()
// init audio speakers
howl.InitAudio()
// init aws polly services
howl.InitPolly()
// connect to slack
Expand Down

0 comments on commit cfc24b3

Please sign in to comment.