When I start playing request is called with start=null and end=null. When it is finished playing these bytes, there is no additional call to request.
I've been struggling with this for a few days now, with every different implementation getting a different error. So all tips welcome. I stream from the OpenAI TTS endpoint.
class MyCustomSource extends StreamAudioSource {
List<int> bytes = [];
Stream<List<int>> byteStream;
MyCustomSource(this.byteStream) {
byteStream.listen((event) {
this.bytes.addAll(event);
});
print("Added ${bytes.length} bytes to List<int>");
}
@override
Future<StreamAudioResponse> request([int? start, int? end]) async {
print("Request called with start: $start and end: $end");
print("Bytes.lenght: ${bytes.length}");
start??=0;
end??=bytes.length;
return StreamAudioResponse(
rangeRequestsSupported: true,
sourceLength: null, // this should indicate that we don't know the full lenght of the stream
contentLength: end-start,
offset: start,
stream: Stream.value(bytes.sublist(start, end)),
contentType: 'audio/mpeg',
);
}
}