steep-balloon-41261
05/09/2023, 3:47 AMmagnificent-art-43333
05/09/2023, 4:00 AMmagnificent-art-43333
05/09/2023, 4:01 AMbest-france-45538
05/09/2023, 7:45 AMbest-france-45538
05/18/2023, 10:19 AMlkgpt-service/pkg/service/transcriber.go
, since the ASR API I tried to use just received PCM raw data, so I tried to modify the code in start()
to use https://github.com/hraban/opus to decode ogg data to pcm data as following
stream, err:= opus.NewStream(t.oggReader)
if err != nil {
logger.Errorw("failed to create opus decoder", err)
}
but got failed to create opus decoder {"error": "OP_EBADTIMESTAMP"}
error.
I’m new to golang, so have no idea if I use a wrong lib?
or any other ways to get pcm raw data ?
THANK YOU VERY MUCH!magnificent-art-43333
05/18/2023, 2:01 PMdry-elephant-14928
05/18/2023, 4:52 PMNewStream
API might be expecting certain Opus/Ogg headers that aren't present in the stream.best-france-45538
05/19/2023, 11:22 AMbest-france-45538
05/22/2023, 11:45 AMimport (
"<http://mccoy.space/g/ogg|mccoy.space/g/ogg>"
)
func OggToPCM(data []byte) ([]byte) {
decoder := ogg.NewDecoder(bytes.NewReader(data))
page, err := decoder.Decode()
if err != nil {
logger.Errorw("Error while decoding opus file: %v", err)
return nil
}
//fmt.Println("ogg data has %d pages", len(page.Packets))
audiodata := make([]byte, 0)
for i:=0; i< len(page.Packets); i++ {
audiodata = append(audiodata, page.Packets[i]...)
}
return audiodata
}
and update transcriber.go
as following
go func() {
defer close(nextCh)
buf := make([]byte, 1024)
for {
select {
case <-endStreamCh:
return
default:
n, err := t.oggReader.Read(buf)
if err != nil {
if err != io.EOF {
logger.Errorw("failed to read from ogg reader", err)
}
return
}
if n <= 0 {
fmt.Printf("No Data read from OggReader \n")
continue // No data
}
opusdata := OggToPCM(buf[:n])
if opusdata != nil {
opusbytes = append(opusbytes, opusdata...)
} else {
fmt.Printf("No Data from OpusDecode \n")
}
}
}
}()
but seems it’s not working neither, any ideas on handle the buffer from oggReader
and convert it to PCM raw data?