go-whisper-api/transcode/ogg_decode_test.go
admin b5c083e06f
Some checks failed
CodeQL / Analyze (go) (push) Successful in 6m28s
Docker Image / build-docker (push) Failing after 13m26s
Lint and Testing / lint (push) Successful in 11m17s
Lint and Testing / test (push) Successful in 11m17s
Lint and Testing / golangci (push) Successful in 2m40s
first commit
2026-06-04 18:10:52 +07:00

53 lines
1.3 KiB
Go

package transcode
import (
"os"
"path/filepath"
"runtime"
"testing"
)
func TestSniffOggCodec_opus(t *testing.T) {
path := pionTinyOggPath(t)
if got := sniffOggCodec(path); got != "opus" {
t.Fatalf("sniffOggCodec() = %q want opus", got)
}
}
func TestDecodeOggOpus_pionTiny(t *testing.T) {
path := pionTinyOggPath(t)
streamer, format, closer, err := decodeOggOpus(path)
if err != nil {
t.Fatal(err)
}
defer closer.Close()
if format.SampleRate == 0 {
t.Fatal("zero sample rate")
}
buf := make([][2]float64, 4096)
n, ok := streamer.Stream(buf)
if !ok || n == 0 {
t.Fatal("expected pcm samples")
}
}
func pionTinyOggPath(t *testing.T) string {
t.Helper()
_, file, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("runtime.Caller failed")
}
modRoot := filepath.Clean(filepath.Join(filepath.Dir(file), ".."))
cache := os.Getenv("GOMODCACHE")
if cache == "" {
home, _ := os.UserHomeDir()
cache = filepath.Join(home, "go", "pkg", "mod")
}
path := filepath.Join(cache, "github.com/pion/opus@v0.0.0-20260601214817-71d58474cec8/testdata/tiny.ogg")
if _, err := os.Stat(path); err != nil {
_ = modRoot
t.Skipf("pion testdata not in module cache: %v", err)
}
return path
}