Android - RecognizerIntent搜索联系人

时间:2012-07-01 23:43:14

标签: android speech-recognition

我正在尝试构建可以帮助我像Google语音搜索一样拨打联系人的应用程序,但是通过使用识别器内容使用Google语音使用捷克语。

问题是什么,似乎没有浏览我的联系人列表。

让我们说联系人姓名的“Rebro”[或任何不属于字典的内容“,例如Schwarzenegger,或者等等)

无论选择何种语言,或者如果我使用英语发音或捷克语发音,它在调用时都不会进入结果集     data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

这有点可能吗?如果是,我怎么能实现呢? 非常感谢提前

编辑:代码添加......这是我在网上找到的代码

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView; 

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends Activity implements OnClickListener {

private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;

private ListView mList;

/**
 * Called with the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button speakButton = (Button) findViewById(R.id.button1);
    mList = (ListView) findViewById(R.id.listView1);

    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (activities.size() != 0) {
        speakButton.setOnClickListener(this);
    } else {
        speakButton.setEnabled(false);
        speakButton.setText("Recognizer not present");
    }
}

/**
 * Handle the click on the start recognition button.
 */
public void onClick(View v) {
    if (v.getId() == R.id.button1) {
        startVoiceRecognitionActivity();
    }
}

/**
 * Fire an intent to start the speech recognition activity.
 */
private void startVoiceRecognitionActivity() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
   // intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
    startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);



}

/**
 * Handle the results from the recognition activity.
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
        // Fill the list view with the strings the recognizer thought it could have heard
        ArrayList<String> matches = data.getStringArrayListExtra(
                RecognizerIntent.EXTRA_RESULTS);



        mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                matches));
    }

    super.onActivityResult(requestCode, resultCode, data);
}
}

2 个答案:

答案 0 :(得分:3)

我认为Google语音搜索不会(也不能)通过RecognizerIntent公开其所有功能,即它只会执行一般语音转录而不支持语音命令(call ...,{{1} })或有关地址簿内容的知识。遗憾的是,text ... API不允许您指定语法或允许的单词列表。

解决方案是忽略Google的语音识别器并实现自己的语音识别器。看,例如进入Pocketsphinx。您需要有捷克声学模型,除非您想以英语方式发音(您可以使用CMU Sphinx附带的英语声学模型)。

我为爱沙尼亚语实现了一个基于Pocketsphinx的开源联系人搜索应用程序,请参阅Inimesed

答案 1 :(得分:0)

使用speechRecongizer是不可能的,因为它只允许大城市名称,而不是任何名称。它的谷歌相应增强它。但你可以看到其他图书馆pocketphinx

相关问题