diff --git a/lib/data/services/speech_impl/volcano_asr_api_service.dart b/lib/data/services/speech_impl/volcano_asr_api_service.dart index 66b67ddc6..dabf9e6e0 100644 --- a/lib/data/services/speech_impl/volcano_asr_api_service.dart +++ b/lib/data/services/speech_impl/volcano_asr_api_service.dart @@ -113,41 +113,41 @@ class VolcanoAsrApiService implements AsrService { final resultCompleter = Completer(); - // 开始连续识别流程 - final stream = await startContinuousRecognition(_audioSourceType); - - // 监听结果 - StreamSubscription? subscription; - subscription = stream.listen((event) { - if (event.type == RecognitionEventType.finalResult) { - // 收到最终结果,完成单次识别 - subscription?.cancel(); - resultCompleter.complete(event); - stopContinuousRecognition(); - } else if (event.type == RecognitionEventType.error) { - // 发生错误,返回错误 - subscription?.cancel(); - resultCompleter.completeError(event.error); - stopContinuousRecognition(); - } - }, onError: (e) { - subscription?.cancel(); - resultCompleter.completeError(e.toString()); - stopContinuousRecognition(); - }, onDone: () { - if (!resultCompleter.isCompleted) { - resultCompleter.complete(RecognitionEvent.error('未收到识别结果')); - } - }); - - // 设置超时 - Timer(const Duration(seconds: 30), () { - if (!resultCompleter.isCompleted) { - subscription?.cancel(); - resultCompleter.complete(RecognitionEvent.error('识别超时')); - stopContinuousRecognition(); - } - }); + // // 开始连续识别流程 + // final stream = await startContinuousRecognition(_audioSourceType); + + // // 监听结果 + // StreamSubscription? subscription; + // subscription = stream.listen((event) { + // if (event.type == RecognitionEventType.finalResult) { + // // 收到最终结果,完成单次识别 + // subscription?.cancel(); + // resultCompleter.complete(event); + // stopContinuousRecognition(); + // } else if (event.type == RecognitionEventType.error) { + // // 发生错误,返回错误 + // subscription?.cancel(); + // resultCompleter.completeError(event.error); + // stopContinuousRecognition(); + // } + // }, onError: (e) { + // subscription?.cancel(); + // resultCompleter.completeError(e.toString()); + // stopContinuousRecognition(); + // }, onDone: () { + // if (!resultCompleter.isCompleted) { + // resultCompleter.complete(RecognitionEvent.error('未收到识别结果')); + // } + // }); + + // // 设置超时 + // Timer(const Duration(seconds: 30), () { + // if (!resultCompleter.isCompleted) { + // subscription?.cancel(); + // resultCompleter.complete(RecognitionEvent.error('识别超时')); + // stopContinuousRecognition(); + // } + // }); return resultCompleter.future; } catch (e) { @@ -157,44 +157,44 @@ class VolcanoAsrApiService implements AsrService { } @override - Future> startContinuousRecognition( - bool audioSourceType) async { - if (!_isInitialized) { - await initialize(); - } + // Future> startContinuousRecognition( + // bool audioSourceType) async { + // if (!_isInitialized) { + // await initialize(); + // } - if (_isContinuousRecognitionActive) { - await stopContinuousRecognition(); - } + // if (_isContinuousRecognitionActive) { + // await stopContinuousRecognition(); + // } - try { - // 创建结果控制器 - _recognitionController = StreamController.broadcast(); + // try { + // // 创建结果控制器 + // _recognitionController = StreamController.broadcast(); - // 连接WebSocket - await _connectWebSocket(); + // // 连接WebSocket + // await _connectWebSocket(); - // 开始录音 - await _startRecording(); + // // 开始录音 + // await _startRecording(); - _isContinuousRecognitionActive = true; - _isRecognitionEndRequested = false; + // _isContinuousRecognitionActive = true; + // _isRecognitionEndRequested = false; - Logger.info('连续语音识别已开始'); + // Logger.info('连续语音识别已开始'); - return _recognitionController!.stream; - } catch (e) { - Logger.error('开始连续语音识别失败: ${e.toString()}'); - await _cleanupResources(); + // return _recognitionController!.stream; + // } catch (e) { + // Logger.error('开始连续语音识别失败: ${e.toString()}'); + // await _cleanupResources(); - // 返回一个包含错误的流 - final errorController = StreamController.broadcast(); - errorController.add(RecognitionEvent.error(e.toString())); - errorController.close(); + // // 返回一个包含错误的流 + // final errorController = StreamController.broadcast(); + // errorController.add(RecognitionEvent.error(e.toString())); + // errorController.close(); - return errorController.stream; - } - } + // return errorController.stream; + // } + // } @override Future stopContinuousRecognition() async { @@ -859,4 +859,10 @@ class VolcanoAsrApiService implements AsrService { // TODO: implement recognizeCallback throw UnimplementedError(); } + + @override + Future startContinuousRecognition(bool audioSourceType) { + // TODO: implement startContinuousRecognition + throw UnimplementedError(); + } } diff --git a/lib/data/services/speech_impl/volcano_asr_service.dart b/lib/data/services/speech_impl/volcano_asr_service.dart index 59c2f5ed6..b5e1493ec 100644 --- a/lib/data/services/speech_impl/volcano_asr_service.dart +++ b/lib/data/services/speech_impl/volcano_asr_service.dart @@ -265,39 +265,39 @@ class VolcanoAsrService extends GetxService implements AsrService { /// 开始连续语音识别 @override - Future> startContinuousRecognition( - bool audioSourceType) async { - if (!await _ensureInitialized()) { - _eventStreamController.add(RecognitionEvent( - type: RecognitionEventType.error, - error: '语音识别服务未初始化', - )); - return _eventStreamController.stream; - } - - try { - final success = await _channel.invokeMethod('audioSourceType', { - 'audioSourceType': audioSourceType, - }) ?? - false; - - if (success) { - _isContinuousRecognitionActive = true; - } else { - _eventStreamController.add(RecognitionEvent( - type: RecognitionEventType.error, - error: '启动连续识别失败', - )); - } - } catch (e) { - _eventStreamController.add(RecognitionEvent( - type: RecognitionEventType.error, - error: '启动连续识别异常:$e', - )); - } - - return _eventStreamController.stream; - } + // Future> startContinuousRecognition( + // bool audioSourceType) async { + // if (!await _ensureInitialized()) { + // _eventStreamController.add(RecognitionEvent( + // type: RecognitionEventType.error, + // error: '语音识别服务未初始化', + // )); + // return _eventStreamController.stream; + // } + + // try { + // final success = await _channel.invokeMethod('audioSourceType', { + // 'audioSourceType': audioSourceType, + // }) ?? + // false; + + // if (success) { + // _isContinuousRecognitionActive = true; + // } else { + // _eventStreamController.add(RecognitionEvent( + // type: RecognitionEventType.error, + // error: '启动连续识别失败', + // )); + // } + // } catch (e) { + // _eventStreamController.add(RecognitionEvent( + // type: RecognitionEventType.error, + // error: '启动连续识别异常:$e', + // )); + // } + + // return _eventStreamController.stream; + // } /// 停止连续语音识别 @override @@ -394,4 +394,10 @@ class VolcanoAsrService extends GetxService implements AsrService { // TODO: implement recognizeCallback throw UnimplementedError(); } + + @override + Future startContinuousRecognition(bool audioSourceType) { + // TODO: implement startContinuousRecognition + throw UnimplementedError(); + } }