【问题标题】:Cordova speech recognition plugin "Invalid action"Cordova 语音识别插件“无效动作”
【发布时间】:2017-06-06 19:13:36
【问题描述】:

我正在尝试使用这个插件:https://github.com/pbakondy/cordova-plugin-speechrecognition

所有设置都正常,但是当我致电 isRecognitionAvailable() 时,我收到了一个带有错误消息的承诺拒绝:'Invalid action'

我检查了生成的 AndroidManifest.xml 和所有内容中的所有权限和 minSDKVersion 是否正确。

注意:我正在使用 Wifi。

这是我的代码:

let options = {
  language: 'en-US',
  matches: 1,
  prompt: '',          
  showPopup: false,
  showPartial: false
}
this.speechRecognition.startListening(options).subscribe(
    (matches: Array<string>) => {
      // matches arrive here....
    },
    (onerror) => {
      alert(JSON.stringify(onerror));
    }
); 

清单:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="io.ionic.starter" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name="cordova.plugins.Diagnostic$LocationProviderChangedReceiver">
            <intent-filter>
                <action android:name="android.location.PROVIDERS_CHANGED" />
            </intent-filter>
        </receiver>
        <receiver android:name="cordova.plugins.Diagnostic$NFCStateChangedReceiver">
            <intent-filter>
                <action android:name="android.nfc.action.ADAPTER_STATE_CHANGED" />
            </intent-filter>
        </receiver>
    </application>
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="25" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

谢谢。

【问题讨论】:

    标签: cordova ionic-framework ionic2 speech-recognition


    【解决方案1】:

    据检查,此插件需要网络才能工作。查看此link 了解更多信息。

    您还可以在 github repo 中查看使用不同插件的示例语音识别器应用程序

    尝试按照issue 中的说明请求许可,因为我在您的示例中没有看到此代码。

    【讨论】:

    • 我真的不明白你的意思。我在最初的问题中说我已经连接到 wifi。
    • @Dave 我忽略了这一点。你能用移动数据试试一次吗?
    • 已经试过了,关闭wifi。我也检查了 android manifest 权限是否正确。
    • @Dave 在我提出任何建议之前,我需要对此进行更多研究。即使在提供了工作样本的链接之后,也不理解投票反对的意义。感觉没有动力
    • 只是因为答案没有考虑清楚表明我有联系的问题文本。就这样。谢谢。我还尝试了您的工作示例,当它运行时我立即收到“无效操作”错误。
    【解决方案2】:

    删除并重新添加 android 平台解决了这个问题,现在我有了另一个不同的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      相关资源
      最近更新 更多