stopRecord method

Future<Map<String, dynamic>> stopRecord(
  1. String apiKey,
  2. String language
)

Implementation

Future<Map<String, dynamic>> stopRecord(
  String apiKey,
  String language,
) async {
  recorder.hasPermission();
  Map<String, dynamic> resultStopRecord = {
    'status': false,
    'transcript': 'Não detectou nada...',
    'input_tokens': 0,
    'output_tokens': 0,
    'url': ''
  };

  try {
    final path = await recorder.stop();
    File? audioFile = File(path!);

    Map speechToTextResult =
        await _service.getTranscript(audioFile, language, apiKey);
    bool isSuccess = speechToTextResult['transcript'].toString().isNotEmpty;

    if (isSuccess) {
      resultStopRecord['transcript'] = speechToTextResult['transcript'];
      resultStopRecord['input_tokens'] = speechToTextResult['input_tokens'];
      resultStopRecord['output_tokens'] = speechToTextResult['output_tokens'];
      resultStopRecord['url'] = speechToTextResult['url'];
      resultStopRecord['status'] = true;
      return resultStopRecord;
    }

    return resultStopRecord;
  } catch (e) {
    return resultStopRecord;
  }
}