bufferToData method
Convert audio buffer to PCM data
This would be called from platform-specific audio buffer callbacks to convert audio samples to the format expected by STT models.
buffer Int16 audio samples (16-bit PCM)
Returns PCM data as bytes
Implementation
Uint8List bufferToData(Int16List buffer) {
// Convert Int16 samples to bytes (little-endian)
final bytes = BytesBuilder();
for (final sample in buffer) {
bytes.add([
sample & 0xFF, // Low byte
(sample >> 8) & 0xFF, // High byte
]);
}
return bytes.toBytes();
}