gpt4 book ai didi

Android - RecognizerIntent 搜索联系人

转载 作者:行者123 更新时间:2023-11-29 18:09:56 25 4
gpt4 key购买 nike

我正在尝试构建可以帮助我像 Google 语音搜索一样调用联系人的应用程序,但是通过 RecognizerIntent 使用 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);
}
}

最佳答案

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

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

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

关于Android - RecognizerIntent 搜索联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11286469/

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