nextPart method

String nextPart(
  1. int timeoutMs
)

Pull the next transcription part (JSON string).

Throws AimuxTranscriptionEndedException when the stream finished normally, AimuxTranscriptionTimeoutException when no part arrived in time (a poll state, not an error — the session stays live; call again). timeoutMs: >0 wait at most; 0 immediate poll; negative = wait indefinitely.

Implementation

String nextPart(int timeoutMs) {
  _checkOpen();
  final outPart = calloc<Pointer<Utf8>>();
  final outState = calloc<Int32>();
  try {
    expectAimuxError(
        _ffi.transcriptionNextPart(_handle, timeoutMs, outPart, outState),
        'transcription_next_part');
    switch (outState.value) {
      case _nextPartStatePart:
        final p = outPart.value;
        if (p == nullptr) {
          throw StateError('aimux ffi: transcription_next_part: NULL part');
        }
        try {
          return p.toDartString();
        } finally {
          aimuxFreeString(p);
        }
      case _nextPartStateEnded:
        throw AimuxTranscriptionEndedException();
      case _nextPartStateTimeout:
        throw AimuxTranscriptionTimeoutException();
      default:
        throw StateError(
            'aimux ffi: transcription_next_part: unknown state ${outState.value}');
    }
  } finally {
    calloc.free(outPart);
    calloc.free(outState);
  }
}