I'm using text to synthesize speech, and since the text is very long I can't wait until it's fully synthesized before playing it. I plan to use websocket technology to synthesize and play at the same time. I use just_audio to play the synthesized bytes. When the new clip is synthesized, I need to add it to the bytes currently being played.
So I'm wondering if it's possible to append bytes when just_audio plays from a StreamSource?
Yes that is possible.
You should create a custom class that extends StreamAudioSource and receives a ByteStream or Stream<List> in the constructor and assigns it to a class variabele.
Extending StreamAudioSource means you have to provide a request([int? start, int? end]) method that returns a Future< StreamAudioResponse>. This will be called by the audioplayer.
Something like this should work:
And to use it:
You can keep writing to myByteStream and the player will play it.