flushAnnotated method

Processes any remaining audio data and returns its transcription.

returns CheetahTranscriptAnnotated object.

Implementation

Future<CheetahTranscriptAnnotated> flushAnnotated() async {
  try {
    Map<String, dynamic> transcript = Map<String, dynamic>.from(await _channel
        .invokeMethod(_NativeFunctions.FLUSH_ANNOTATED.name, {'handle': _handle}));

    if (transcript['transcript'] == null) {
      throw CheetahInvalidStateException("field 'transcript' must be always present");
    } else if (transcript['words'] == null) {
      throw CheetahInvalidStateException("field 'words' must be always present");
    }

    List<CheetahWord> words = (transcript['words'] as List).map(
      (obj) {
        Map<String, dynamic> word = Map<String, dynamic>.from(obj as Map);
        return CheetahWord(word["word"], word["startSeconds"], word["endSeconds"], word["confidence"]);
      }
    ).toList();
    return CheetahTranscriptAnnotated(transcript['transcript'], words, null);
  } on PlatformException catch (error) {
    throw cheetahStatusToException(error.code, error.message);
  } on Exception catch (error) {
    throw CheetahException(error.toString());
  }
}