go-roflcopter/roflcopter/roflcopter.go

35 lines
597 B
Go

package roflcopter
import (
"bytes"
_ "embed"
"fmt"
"io"
"log"
"sync"
"time"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
)
//go:embed embed\swah.mp3
var swah []byte
func Sound(wg *sync.WaitGroup, output bool) {
wg.Add(1)
if output {
fmt.Println("SWAH")
}
t := 1*time.Second + 390*time.Millisecond
streamer, format, err := mp3.Decode(io.NopCloser(bytes.NewReader(swah)))
if err != nil {
log.Fatal(err)
}
defer streamer.Close()
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
speaker.Play(streamer)
time.Sleep(t * 1)
wg.Done()
}