Cordova 语音识别插件 "Invalid action"
Cordova speech recognition plugin "Invalid action"
我正在尝试使用这个插件: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>
谢谢。
据检查,此插件需要网络才能工作。查看此 link 了解更多信息。
您还可以在本 github repo
中查看使用不同插件的示例语音识别器应用
尝试按照此 issue 中所述请求许可,因为我在您的示例中没有看到此代码。
删除并重新添加 android 平台解决了这个问题,现在我有另一个不同的平台。
我正在尝试使用这个插件: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>
谢谢。
据检查,此插件需要网络才能工作。查看此 link 了解更多信息。
您还可以在本 github repo
中查看使用不同插件的示例语音识别器应用尝试按照此 issue 中所述请求许可,因为我在您的示例中没有看到此代码。
删除并重新添加 android 平台解决了这个问题,现在我有另一个不同的平台。