[英]Send Voice or Text Command From My App To Google Assistant (Hey Google)
我可以向 Google 助理发送语音或文本命令以执行命令吗?
我现在正在使用此代码,但它打开的是普通的谷歌搜索而不是谷歌助手。
String command = "hey google , open camera";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.setClassName("com.google.android.googlequicksearchbox", "com.google.android.googlequicksearchbox.SearchActivity");
intent.putExtra("query", command);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //necessary if launching from Service
startActivity(intent);
我所做的工作是
1 - 使用语音命令意图启动助手
Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
2 - 使用 TextToSpeach 引擎读取命令
首先在oncreate之外定义TTS变量function
private TextToSpeech mTTS;
然后运行这个
mTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status==TextToSpeech.SUCCESS) {
mTTS.setLanguage(Locale.US);
mTTS.speak(" turn lights on ", TextToSpeech.QUEUE_FLUSH, null);
}
}
它就像一个魅力
这是您从应用程序中打开谷歌助手的方式,但实际上无法向其发送命令。
Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.