WEB开发网
开发学院手机开发Android 开发 Android 自带的语音识别例子初探 阅读

Android 自带的语音识别例子初探

 2010-03-25 17:02:00 来源:WEB开发网   
核心提示:if (activities.size() != 0){speakButton.setOnClickListener(this);}else{speakButton.setEnabled(false);speakButton.setText("Recognizer not present");}}p

if (activities.size() != 0)

{

speakButton.setOnClickListener(this);

}

else

{

speakButton.setEnabled(false);

speakButton.setText("Recognizer not present");

}

}

public void onClick(View v)

{

if (v.getId() == R.id.btn_speak)

{

startVoiceRecognitionActivity();

}

}

private void startVoiceRecognitionActivity()

{

// 通过Intent传递语音识别的模式

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

// 语言模式和自由形式的语音识别

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

// 提示语音开始

intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");

// 开始执行我们的Intent、语音识别

startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);

}

// 当语音结束时的回调函数onActivityResult

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data)

{

if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK)

{

// 取得语音的字符

ArrayList matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

mList.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, matches));

}

super.onActivityResult(requestCode, resultCode, data);

}

}

package com.example.android.apis.app;

import android.app.Activity;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.content.pm.ResolveInfo;

import android.os.Bundle;

上一页  1 2 3 4  下一页

Tags:Android 自带 语音

编辑录入:coldstar [复制链接] [打 印]
赞助商链接