[英]Send Voice or Text Command From My App To Google Assistant (Hey Google)
Can I sned Voice or Text Commands to Google Assistant to execute Commands?我可以向 Google 助理发送语音或文本命令以执行命令吗?
I am using this Code now but it's open Normal Google Search Not Google Assistant.我现在正在使用此代码,但它打开的是普通的谷歌搜索而不是谷歌助手。
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);
The work around I did was我所做的工作是
1 - launch the Assistant with voice command intent 1 - 使用语音命令意图启动助手
Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
2 - read the command with a TextToSpeach engine 2 - 使用 TextToSpeach 引擎读取命令
first define the TTS variable outside the oncreate function首先在oncreate之外定义TTS变量function
private TextToSpeech mTTS;
then run this然后运行这个
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);
}
}
it worked like a charm它就像一个魅力
this is how you open the google assistant from your app, but actually it is not possible to to send a command to it.这是您从应用程序中打开谷歌助手的方式,但实际上无法向其发送命令。
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.