voice

public void onCreate(Bundle instance)
{
super.onCreate(instance);
setContentView(R.layout.speak);
imageView1 = (ImageView) findViewById(R.id.back_fill);
imageView2 = (ImageView) findViewById(R.id.talk);
imageView3 = (ImageView) findViewById(R.id.sound);
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if(list.size()!=0)
{
imageView2.setOnClickListener(new OnClickListener()
{
public void onClick(View view)
{
if(view.getId()==R.id.talk)
{
try
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); //设置为当前手机的语言类型
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "开始语音....");
startActivityForResult(intent,Parameters.VOICE_RECOGNITION_REQUEST_CODE);

}catch (ActivityNotFoundException e){ toast = new Toast(Speak.this);
toast = Toast.makeText(
getApplicationContext(),
"ActivityNotFoundException...", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} } } });} }
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
final LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);

if(requestCode == Parameters.VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK)
{
TextView textView = null;
String text_content = null;
ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if (null != results && results.size() > 0)
{
StringBuffer stemp = new StringBuffer();
llayout = (LinearLayout) inflater.inflate(R.layout.talk_right, null); //获取对应版块信息
for (int i = 0; i < results.size(); i++)
{
stemp.append(results.get(i));
}
text_content = stemp.toString();
textView = (TextView) llayout.findViewById(R.id.text);
textView.setText("您问:"+text_content);
layout = (LinearLayout) findViewById(R.id.contentArea);//加载当前项到原始模板
layout.addView(llayout);
getAnswer(text_content,layout);
}
}
super.onActivityResult(requestCode, resultCode, data);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值