I just converted the []float32 to []byte (see function below) and it works.
But the sound produced while recognizable is very staticy and I don't know 
why.

func floats32ToBytes(fs []float32) []byte {
var buf bytes.Buffer
for _, f := range fs {
if err := binary.Write(&buf, binary.LittleEndian, f); err != nil {
panic(err)
}
}
return buf.Bytes()
}

On Thursday, November 23, 2023 at 10:03:24 AM UTC Mark wrote:

> I've now tried using those libraries, but there seems to be an 
> incompatibility []float32 vs []byte.
> Here's the error:
>
> ./play.go:24:29: cannot use reader (variable of type *oggvorbis.Reader) as 
> io.Reader value in argument to otoCtx.NewPlayer: *oggvorbis.Reader does not 
> implement io.Reader (wrong type for method Read)
> have Read([]float32) (int, error)
> want Read([]byte) (int, error)
>
> And here's the code (main.go):
>
> package main
>
> import (
> "log"
> "os"
> "time"
>
> //"github.com/ebitengine/oto/v3"
> "github.com/hajimehoshi/oto/v2"
> "github.com/jfreymuth/oggvorbis"
> )
>
> func main() {
> log.SetFlags(0)
> file, err := os.Open(os.Args[0])
> checkErr(err)
> defer file.Close()
> reader, err := oggvorbis.NewReader(file)
> checkErr(err)
> otoCtx, readyCh, err := oto.NewContext(reader.SampleRate(),
> reader.Channels(), 2)
> checkErr(err)
> <-readyCh // wait for h/w
> player := otoCtx.NewPlayer(reader)
> defer player.Close()
> player.Play()
> for player.IsPlaying() {
> time.Sleep(time.Millisecond * 10)
> }
> }
>
> func checkErr(err error) {
> if err != nil {
> log.Fatal(err)
> }
> }
>
> On Wednesday, November 22, 2023 at 10:31:25 PM UTC Raffaele Sena wrote:
>
>> I have used github.com/jfreymuth/oggvorbis to read the ogg file (and 
>> convert to PCM) and github.com/ebitengine/oto/v3 to play the PCM.
>> I don't know of a full ogg player in Go
>>
>>
>> On Wed, Nov 22, 2023 at 2:02 PM 'Mark' via golang-nuts <
>> golan...@googlegroups.com> wrote:
>>
>>> Is there a simple vorbis/oga audio player package for Go that works on 
>>> Linux.
>>> The only API I need is something like this:
>>>
>>> player.SetFilename(string) error // string is say tune.ogg; stops 
>>> playing previous if any
>>> player.Play(float32) error // plays current filename from given second 
>>> e.g. 0.0 for the beginning
>>> player.Pause() (float32, error) // pauses current playing and returns 
>>> position
>>> player.Resume() error // resumes playing
>>> player.Secs() float32 // returns current position
>>>
>>> The ones I've seen on awsome go either don't seem to play ogg format or 
>>> are far more sophisticated than I need.
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to golang-nuts...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/a38e3a9b-a357-4c85-aa4d-a7a4322ec216n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/golang-nuts/a38e3a9b-a357-4c85-aa4d-a7a4322ec216n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4bbdeb78-6ac8-49c3-b71f-a270bb090a38n%40googlegroups.com.

Reply via email to