1
0
mirror of https://github.com/fumiama/ahsai.git synced 2026-06-28 15:20:23 +08:00
This commit is contained in:
fumiama
2022-08-08 11:28:21 +08:00
parent c88fca4594
commit 3f3bf32553
3 changed files with 49 additions and 27 deletions

38
play_nounix.go Normal file
View File

@@ -0,0 +1,38 @@
//go:build android || darwin || js || windows
// +build android darwin js windows
package ahsai
import (
"net/http"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/speaker"
"github.com/faiface/beep/vorbis"
)
// PlayOgg cut leading demo text and play directly
func PlayOgg(u string) error {
resp, err := http.Get(u)
if err != nil {
return err
}
s, format, err := vorbis.Decode(resp.Body)
if err != nil {
_ = resp.Body.Close()
return err
}
defer s.Close()
cutstream(s)
err = speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/32))
if err != nil {
return err
}
done := make(chan struct{})
speaker.Play(beep.Seq(s, beep.Callback(func() {
done <- struct{}{}
})))
<-done
return nil
}