簡體   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