Android emulator中的语音到文本:未找到可处理意图的活动
我想问一下如何在模拟器上使用语音到文本代码。我的代码在真实设备上工作,但在模拟器上不工作。错误是这样的:Android emulator中的语音到文本:未找到可处理意图的活动,android,speech-recognition,speech-to-text,Android,Speech Recognition,Speech To Text,我想问一下如何在模拟器上使用语音到文本代码。我的代码在真实设备上工作,但在模拟器上不工作。错误是这样的: No Activity found to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH (has extras) } 我能做什么?您可能需要一个虚拟SD卡。您可以参考您需要在模拟器上安装一个应用程序,该应用程序包含处理识别语音-intent的活动。你可以在网上找到谷歌的VoiceSearch.apk。package
No Activity found to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH (has extras) }
我能做什么?您可能需要一个虚拟SD卡。您可以参考您需要在模拟器上安装一个应用程序,该应用程序包含处理
识别语音
-intent的活动。你可以在网上找到谷歌的VoiceSearch.apk
。package net.viralpatel.android.speechtotextdemo;
package net.viralpatel.android.speechtotextdemo;
import java.util.ArrayList;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
protected static final int RESULT_SPEECH = 1;
private ImageButton btnSpeak;
private TextView txtText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtText = (TextView) findViewById(R.id.txtText);
btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);
btnSpeak.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
try {
startActivityForResult(intent, RESULT_SPEECH);
txtText.setText("");
} catch (ActivityNotFoundException a) {
Toast t = Toast.makeText(getApplicationContext(),
"Ops! Your device doesn't support Speech to Text",
Toast.LENGTH_SHORT);
t.show();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RESULT_SPEECH: {
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> text = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
txtText.setText(text.get(0));
}
break;
}
}
}
}
导入java.util.ArrayList;
导入android.app.Activity;
导入android.content.ActivityNotFoundException;
导入android.content.Intent;
导入android.os.Bundle;
导入android.speech.RecognizerIntent;
导入android.view.Menu;
导入android.view.view;
导入android.widget.ImageButton;
导入android.widget.TextView;
导入android.widget.Toast;
公共类MainActivity扩展了活动{
受保护的静态最终整数结果\u SPEECH=1;
专用图像按钮btnSpeak;
私有文本视图txtText;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtText=(TextView)findViewById(R.id.txtText);
btnSpeak=(图像按钮)findViewById(R.id.btnSpeak);
btnSpeak.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
意图=新意图(
识别者(意图、行动、识别、言语);
intent.putExtra(RecognizerIntent.EXTRA_语言_模型,“en-US”);
试一试{
startActivityForResult(意图、结果和演讲);
txtText.setText(“”);
}捕获(ActivityNotFoundException a){
Toast t=Toast.makeText(getApplicationContext(),
“操作!您的设备不支持语音转换为文本”,
烤面包片(长/短);
t、 show();
}
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
getMenuInflater().充气(R.menu.activity\u主菜单);
返回true;
}
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
开关(请求代码){
个案结果(演讲):{
if(resultCode==RESULT\u OK&&null!=数据){
ArrayList文本=数据
.getStringArrayListExtra(识别器意图.额外结果);
setText(text.get(0));
}
打破
}
}
}
}
有些东西无法使用模拟器进行测试。从语音到文本是其中之一
我不确定这一点,但你不能在模拟器上使用这个android功能
不管怎样,您都应该通过try/catch来处理此异常,并向用户提供一些反馈
您可以检查运行应用程序的当前设备中是否存在类似以下操作的活动
:
PackageManager pm = context.getPackageManager();
List<ResolveInfo> infoList = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (infoList.size() == 0) {
/** Show some feedback to user if there is the activity. Something like "Your device is not abl to run this feature..."*/
}else{
/**Your current code goes here.*/
}
PackageManager pm=context.getPackageManager();
List infoList=pm.querytentActivities(新意图(RecognizerIntent.ACTION\u recognizer\u SPEECH),0);
if(infoList.size()==0){
/**如果有活动,则向用户显示一些反馈。例如“您的设备无法运行此功能…”*/
}否则{
/**您当前的代码在这里*/
}
如果有帮助,请告诉我。您需要在没有语音识别活动的目标设备上安装
com.google.android.voicesearch
应用程序,如:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.voicesearch"));
startActivity(browserIntent);
如果你尝试安装谷歌的搜索应用程序-它不会有帮助,因为它里面没有虚拟现实引擎,因此它会尝试同样的操作-安装
com.Google.android.voicesearch
应用程序,但它可能会因为包名中的错误而失败(pname:com.Google.android.voicesearch
,而不仅仅是包名)。但是,com.google.android.voicesearch
安装可能不可能,因为“在您的国家不可用”。但我不想录制语音,我使用语音到文本,就像这样[它在真实设备上工作,但在模拟器上不工作为什么?我安装了谷歌语音,但它也不工作。如果您有工作。apk请给出url。