import 'dart:async'; import 'dart:typed_data'; /// 语音识别服务接口 abstract class AstService { /// 支持的语言 List get supportedLanguages; /// 初始化语音识别服务 Future initialize({required List supportedLanguages}); /// 开始录音 Future enableRecord(String filePath); /// 停止录音 Future stopContinuousTranslation(bool isSave); /// 开始录音 Future path(String filePath); } /// 识别事件类型 // enum RecognitionEventType { // /// 最终识别结果 // finalResult, // /// 中间识别结果(实时反馈) // intermediateResult, // /// 音频 // onAudio, // /// 会话开始 // sessionStarted, // /// 会话结束 // sessionStopped, // /// 识别取消 // canceled, // /// 识别错误 // error, // } /// 识别事件 // class RecognitionEvent { // /// 事件类型 // final RecognitionEventType type; // /// 识别文本(仅在 finalResult 和 intermediateResult 类型中有效) // final String text; // /// 检测到的语言 // final String detectedLanguage; // /// 角色 // final String role; // /// 原始音频 // final Uint8List? audio; // /// 错误信息(仅在 error 和 canceled 类型中有效) // final String error; // RecognitionEvent({ // required this.type, // this.text = '', // this.detectedLanguage = '', // this.role = '', // this.audio, // this.error = '', // }); // /// 创建最终结果事件的快捷构造函数 // factory RecognitionEvent.finalResult({ // required String text, // String detectedLanguage = '', // }) { // return RecognitionEvent( // type: RecognitionEventType.finalResult, // text: text, // detectedLanguage: detectedLanguage, // ); // } // /// 创建错误事件的快捷构造函数 // factory RecognitionEvent.error(String errorMessage) { // return RecognitionEvent( // type: RecognitionEventType.error, // error: errorMessage, // ); // } // /// 检查是否为最终结果 // bool get isFinalResult => type == RecognitionEventType.finalResult; // /// 检查是否为错误 // bool get isError => // type == RecognitionEventType.error || // type == RecognitionEventType.canceled; // @override // String toString() { // return 'RecognitionEvent{type: $type, text: $text, detectedLanguage: $detectedLanguage, error: $error}'; // } // }