Refactor chunking logic for lower-latency realtime audio streaming#22
Refactor chunking logic for lower-latency realtime audio streaming#22mgupta-soundhound wants to merge 1 commit into
Conversation
c84e205 to
c10c6cd
Compare
e70d0dc to
a92c6b4
Compare
86b1e3d to
8d6e5fe
Compare
8d6e5fe to
4620d42
Compare
There was a problem hiding this comment.
Should we move this file into example folder to indicate this is not part of the core SDK but some helper functions used in the client code?
We could keep it here if we want add some simpler API to allow SDK users to stream with a certain interval in the future.
There was a problem hiding this comment.
I’m intentionally including this in the main SDK so clients can directly configure streaming chunking and duration for LPCM audio formats. This makes it a first-class part of the SDK, available to anyone who needs it. If it lived under github.com/soundhound/houndify-sdk-go/example, clients would have to either copy the code each time or import an example package, which isn’t ideal for production use. As it stands, they can simply import github.com/soundhound/houndify-sdk-go and use it out of the box.
|
LGTM |
Problem(s)
SafeToStopAudiosignals are received.wavformat, making it harder to reuse, validate, or modify for different LPCM formats.Solution Summary
What changed
SafeToStopAudiohandling.GetLPCMStreamInfoto centralize LPCM chunk-size and streaming-interval calculation.numChans,bitDepth,sampleRate, andtargetStreamIntervalMs).timer.Sleep()totickerin audio streaming example - to avoid any drifts over time. This change will also help prevent writing any chunks afterSafeToStopAudiohas been received.1.26io/ioutilgithub.com/pkg/errorsgotest.tools/assertwithgithub.com/stretchr/testify/assertWhy
LPCM Streaming Calculations
The helper calculates streaming info in three steps:
Testing
lpcm_stream_info_test.gocoverage for valid and invalid cases.Follow-up(s)
io.Pipebehaves like a buffer-less channel: writes block until the reader is ready to consume the data. That means the writer’s pacing is coupled to the request body reader, which can distort the intended realtime streaming cadence. Replacing this pattern with a simple buffered approach would decouple writes from reads, making the streaming example non-blocking.