Mar*_*ser 6 android speech-recognition android-permissions
我试图在没有标准对话框的情况下实现语音识别(它在对话框中工作正常).
我尝试开始收听时收到错误代码9.
我的设备是LG G Stylo(运行Android 6.0).
表现:
<manifest package="example.com.myapplication"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application
.....
Run Code Online (Sandbox Code Playgroud)
(也尝试添加INTERNET权限,即使这不应该是必要的,因为离线识别应该正常工作)
的build.gradle:
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "example.com.appname"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
Run Code Online (Sandbox Code Playgroud)
语音识别码:
private SpeechRecognizer speechRecognizer;
protected void onCreate(Bundle savedInstanceState) {
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
speechRecognizer.setRecognitionListener(new speech_listener());
Intent intent = new intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
getApplication().getPackageName());
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.ENGLISH);
speechRecognizer.startListening(intent);
Run Code Online (Sandbox Code Playgroud)
监听器(内部)类:
class speech_listener implements RecognitionListener
{
public void onReadyForSpeech(Bundle params){}
public void onBeginningOfSpeech(){}
public void onRmsChanged(float rmsdB){}
public void onBufferReceived(byte[] buffer){}
public void onEndOfSpeech(){}
public void onError(int error){
Log.d("Speech", "error: " + error);
}
public void onResults(Bundle results)
{
ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
String answer = (String)data.get(0);
processAnswer(answer);
}
public void onPartialResults(Bundle partialResults){}
public void onEvent(int eventType, Bundle params){}
}
Run Code Online (Sandbox Code Playgroud)
任何见解将不胜感激.
就我而言,错误消息是“9/权限不足”
通过向Google应用授予麦克风权限来解决
参考:https://github.com/react-native-voice/voice/issues/253#issuecomment-812726040
| 归档时间: |
|
| 查看次数: |
10653 次 |
| 最近记录: |