enqueue method
Implementation
@override
Future<void> enqueue(typed_data.Uint8List pcmData) async {
if (_audioContext == null || _outputSampleRate == null) {
throw Exception('AudioIo not initialized');
}
final audioBuffer = _createAudioBuffer(pcmData);
final source = _audioContext!.createBufferSource();
source.buffer = audioBuffer;
source.connect(_voiceGainNode!);
// Schedule voice audio sequentially to prevent gaps/overlaps.
// If playback schedule drifted behind, catch up to current time.
final currentTime = _audioContext!.currentTime;
if (_nextPlaybackTime < currentTime) {
_nextPlaybackTime = currentTime;
}
source.start(_nextPlaybackTime);
_nextPlaybackTime += audioBuffer.duration;
_playbackQueue.add(source);
source.onended = ((Event event) {
_playbackQueue.remove(source);
}).toJS;
}