Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何处理_platformcallhandlercall speech.onError 7?_Flutter - Fatal编程技术网

Flutter 如何处理_platformcallhandlercall speech.onError 7?

Flutter 如何处理_platformcallhandlercall speech.onError 7?,flutter,Flutter,我正在尝试在Flitter中实现语音识别插件。当我说话时,识别效果非常好,应用程序运行平稳。但当我点击麦克风按钮,什么也不说时,会显示以下错误,然后麦克风按钮的功能会停止,直到我重新启动应用程序 D/SpeechRecognitionPlugin( 1155): onError : 7 I/flutter ( 1155): _platformCallHandler call speech.onSpeechAvailability false I/flutter ( 1155): _platfor

我正在尝试在Flitter中实现语音识别插件。当我说话时,识别效果非常好,应用程序运行平稳。但当我点击麦克风按钮,什么也不说时,会显示以下错误,然后麦克风按钮的功能会停止,直到我重新启动应用程序

D/SpeechRecognitionPlugin( 1155): onError : 7
I/flutter ( 1155): _platformCallHandler call speech.onSpeechAvailability false
I/flutter ( 1155): _platformCallHandler call speech.onError 7
I/flutter ( 1155): Unknowm method speech.onError 
有人能帮我解决这个问题吗

这是我的speech_recognition.dart文件

import 'dart:async';

import 'dart:ui';
import 'package:flutter/services.dart';

typedef void AvailabilityHandler(bool result);
typedef void StringResultHandler(String text);

/// the channel to control the speech recognition
class SpeechRecognition {
  static const MethodChannel _channel =
      const MethodChannel('speech_recognition');

  static final SpeechRecognition _speech = new SpeechRecognition._internal();

  factory SpeechRecognition() => _speech;

  SpeechRecognition._internal() {
    _channel.setMethodCallHandler(_platformCallHandler);
  }

  AvailabilityHandler availabilityHandler;

  StringResultHandler currentLocaleHandler;
  StringResultHandler recognitionResultHandler;

  VoidCallback recognitionStartedHandler;

  VoidCallback recognitionCompleteHandler;
  VoidCallback errorHandler;

  /// ask for speech  recognizer permission
  Future activate() => _channel.invokeMethod("speech.activate");

  /// start listening
  Future listen({String locale}) =>
      _channel.invokeMethod("speech.listen", locale);

  Future cancel() => _channel.invokeMethod("speech.cancel");

  Future stop() => _channel.invokeMethod("speech.stop");

  Future _platformCallHandler(MethodCall call) async {
    print("_platformCallHandler call ${call.method} ${call.arguments}");
    switch (call.method) {
      case "speech.onSpeechAvailability":
        availabilityHandler(call.arguments);
        break;
      case "speech.onCurrentLocale":
        currentLocaleHandler(call.arguments);
        break;
      case "speech.onSpeech":
        recognitionResultHandler(call.arguments);
        break;
      case "speech.onRecognitionStarted":
        recognitionStartedHandler();
        break;
      case "speech.onRecognitionComplete":
        recognitionCompleteHandler();
        break;
      case "speech.onError":
        errorHandler();
        break;
      default:
        print('Unknowm method ${call.method} ');
    }
  }

  // define a method to handle availability / permission result
  void setAvailabilityHandler(AvailabilityHandler handler) =>
      availabilityHandler = handler;

  // define a method to handle recognition result
  void setRecognitionResultHandler(StringResultHandler handler) =>
      recognitionResultHandler = handler;

  // define a method to handle native call
  void setRecognitionStartedHandler(VoidCallback handler) =>
      recognitionStartedHandler = handler;

  // define a method to handle native call
  void setRecognitionCompleteHandler(VoidCallback handler) =>
      recognitionCompleteHandler = handler;

  void setCurrentLocaleHandler(StringResultHandler handler) =>
      currentLocaleHandler = handler;

  void setErrorHandler(VoidCallback handler) => errorHandler = handler;

}

语音识别
未积极维护。有太多的请求仍在等待合并。你可以选择图书馆

\u platformCallHandler
函数中,在
默认
案例之前添加以下案例

case "speech.onError":
   errorHandler();
   break;
在下面声明
errorHandler
recognitionCompleteHandler

VoidCallback errorHandler;
在文件末尾,声明public方法以设置此
errorHandler

void setErrorHandler(VoidCallback handler) => errorHandler = handler;
这是大量的工作,因此您可以使用已经实现了上述功能的库

在实现中,处理错误处理程序

_speechRecognition.setErrorHandler(() {
   initSpeechRecognizer();
});

我已经按照你的要求进行了更改,但仍然得到了相同的输出。为了实现flatter_speech或sppech_to_text插件,我必须更改很多代码,这是我想解决这个问题的主要原因,如果可能的话,我甚至在上面添加了speech_recognition.dart文件,请看一下
speech_recognition.dart
文件代码。请添加您的实现代码,以便我们检查。是实现文件的链接,请看that@UmakanthPendyala,您必须处理在
speech\u recognition.dart
中定义的
setErrorHandler
。更新了我的答案,请看。我的建议是使用
flatter\u speech
,这是
speech\u recognition
的精确副本,但该库添加了错误处理。