pushAudio method

void pushAudio(
  1. Uint8List audio
)

Push one binary audio chunk. Blocks while the internal channel is full (backpressure propagation).

Implementation

void pushAudio(Uint8List audio) {
  _checkOpen();
  final ptr = audio.isEmpty
      ? Pointer<Uint8>.fromAddress(0)
      : calloc<Uint8>(audio.length);
  final allocated = audio.isNotEmpty;
  try {
    if (allocated) {
      ptr.asTypedList(audio.length).setAll(0, audio);
    }
    withAimuxCError((err) {
      final rc = _ffi.transcriptionPushAudio(
          _handle, ptr, audio.length, err);
      if (rc == 0) {
        // Build the exception FIRST (it reads the message), then free.
        final ex = AimuxException.fromC(err.ref);
        _freeCError(err);
        throw ex;
      }
      return 0;
    });
  } finally {
    if (allocated) calloc.free(ptr);
  }
}