go-whisper-api/transcode/samples_stream.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

39 lines
779 B
Go

package transcode
import "github.com/gopxl/beep"
type samplesStreamer struct {
samples []float64
pos int
sampleRate beep.SampleRate
}
func newSamplesStreamer(samples []float64, sampleRate int) *samplesStreamer {
return &samplesStreamer{
samples: samples,
sampleRate: beep.SampleRate(sampleRate),
}
}
func (s *samplesStreamer) Stream(buf [][2]float64) (int, bool) {
if s.pos >= len(s.samples) {
return 0, false
}
n := 0
for i := range buf {
if s.pos >= len(s.samples) {
return n, n > 0
}
v := s.samples[s.pos]
buf[i][0] = v
buf[i][1] = v
s.pos++
n++
}
return n, true
}
func (s *samplesStreamer) Err() error {
return nil
}