formatSentenceResponse static method

SentenceInfo formatSentenceResponse(
  1. Map<String, dynamic> response
)

将补充处理后的句子翻译结果转换为 SentenceInfo。

Implementation

static SentenceInfo formatSentenceResponse(Map<String, dynamic> response) {
  final sentence = response['sentence'] as String;
  final translation = [response['text'] as String];
  final audio = response['audio_data'];
  final audioData = audio is Uint8List
      ? audio
      : audio is List<int>
      ? Uint8List.fromList(audio)
      : Uint8List(0);

  return SentenceInfo(
    sentence: sentence,
    translations: translation,
    audioData: audioData,
  );
}