mirror of
https://github.com/fumiama/ahsai.git
synced 2026-06-05 07:40:23 +08:00
drop cgo
This commit is contained in:
27
ogg.go
27
ogg.go
@@ -4,10 +4,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/faiface/beep"
|
"github.com/faiface/beep"
|
||||||
"github.com/faiface/beep/speaker"
|
|
||||||
"github.com/faiface/beep/vorbis"
|
"github.com/faiface/beep/vorbis"
|
||||||
"github.com/faiface/beep/wav"
|
"github.com/faiface/beep/wav"
|
||||||
)
|
)
|
||||||
@@ -96,28 +94,3 @@ func SaveOggToWriteSeeker(u string, f io.WriteSeeker) error {
|
|||||||
cutstream(s)
|
cutstream(s)
|
||||||
return wav.Encode(f, s, format)
|
return wav.Encode(f, s, format)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|||||||
38
play_nounix.go
Normal file
38
play_nounix.go
Normal 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
|
||||||
|
}
|
||||||
11
play_stub.go
Normal file
11
play_stub.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
//go:build !android && !darwin && !js && !windows
|
||||||
|
// +build !android,!darwin,!js,!windows
|
||||||
|
|
||||||
|
package ahsai
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
// PlayOgg cut leading demo text and play directly
|
||||||
|
func PlayOgg(u string) error {
|
||||||
|
return errors.New("cannot play directly on this platform")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user