gpt4 book ai didi

Android语音识别权限不足(错误码9)

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:42 30 4
gpt4 key购买 nike

我正在尝试在没有标准对话的情况下实现语音识别(它在对话中运行良好)。

我一尝试开始收听就收到错误代码 9。

我的设备是 LG G Stylo(运行 Android 6.0)。

list :

<manifest package="example.com.myapplication"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application
.....

(也尝试添加 INTERNET 权限,尽管这不是必需的,因为离线识别应该有效)

build.gradle:

compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "example.com.appname"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}

语音识别代码:

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);

监听器(内部)类:

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){}
}

如有任何见解,我们将不胜感激。

最佳答案

在 Android 6 上,此权限是危险权限之一,这意味着您需要要求用户确认(实际获取)。检查thisthis了解更多详情。

关于Android语音识别权限不足(错误码9),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35248075/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com