繁体   English   中英

如何从Android应用程序向Google Assistant发送文本查询

[英]How to send a text query to Google Assistant from Android app

我正在尝试启动Google Assistant并在按下按钮时从我的应用发送文本问题(不是语音)。 例如:我单击一个按钮,然后Google助手回答我的问题“今天的天气如何?”。

这可能吗?

编辑:当我按下一个按钮时,我希望Google助手执行一些操作并提供语音反馈。 例如:“阅读明天的天气并将闹钟设置为6.30 am”。

看来您可以从直接包类名称中引用它。

String queryString = "How is the weather today?";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.setClassName("com.google.android.googlequicksearchbox", 
                    "com.google.android.googlequicksearchbox.SearchActivity");
intent.putExtra("query", queryString);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

如果您已经在使用Assistant SDK,则非常简单。 只需将AudioInConfig替换为文本查询即可。 这是我的方法:

AssistConfig config = AssistConfig.newBuilder()
    .setTextQuery("Your text query goes here!")
    //.setAudioInConfig(audioInConfig)
    .setAudioOutConfig(audioOutConfig)
    .setDeviceConfig(deviceConfig)
    .setDialogStateIn(dialogStateIn)
    .setScreenOutConfig(screenOutConfig)
    .build();
AssistRequest request = AssistRequest.newBuilder().setConfig(config).build();

然后通过gRPC将请求发送到服务器,您将获得语音响应。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM