You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Text to Speech service to generate streaming OGG data, I want to send the streaming output into a WebRTC audio track. I checked the play-from-disk example in the repo and the below code is what I have written so far.
The problem is that I can send data to the client but I can't hear the audio on the client.
Other things I have tested:
If I save the data into a ogg file, it's a valid file and I can play it.
Change the oggreader.NewWith(data) to oggreader.NewWith(f) where f is a file opened from disk. There is sound in the client but the speed is weird.
It seems it's something about the ogg options, but I'm not familiar with it. Any idea how can I get this code to work?
funcsendAudioData(data io.Reader, audioTrack*webrtc.TrackLocalStaticSample) error {
ogg, _, oggErr:=oggreader.NewWith(data)
ifoggErr!=nil {
returnoggErr
}
varlastGranuleuint64for {
pageData, pageHeader, oggErr:=ogg.ParseNextPage()
iferrors.Is(oggErr, io.EOF) {
fmt.Printf("All audio pages parsed and sent")
returnnil
}
ifoggErr!=nil {
returnoggErr
}
slog.Info("ParseNextPage", "header", pageHeader)
// The amount of samples is the difference between the last and current timestampsampleCount:=float64(pageHeader.GranulePosition-lastGranule)
lastGranule=pageHeader.GranulePositionsampleDuration:=time.Duration((sampleCount/48000)*1000) *time.Millisecondslog.Info("Write Sample", "duration", sampleDuration, "length", len(pageData))
ifoggErr=audioTrack.WriteSample(media.Sample{Data: pageData, Duration: sampleDuration}); oggErr!=nil {
returnoggErr
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm using Text to Speech service to generate streaming OGG data, I want to send the streaming output into a WebRTC audio track. I checked the play-from-disk example in the repo and the below code is what I have written so far.
The problem is that I can send data to the client but I can't hear the audio on the client.
Other things I have tested:
oggreader.NewWith(data)
tooggreader.NewWith(f)
wheref
is a file opened from disk. There is sound in the client but the speed is weird.It seems it's something about the ogg options, but I'm not familiar with it. Any idea how can I get this code to work?
Beta Was this translation helpful? Give feedback.
All reactions