How do I change the language/locale in the Google Assistant SDK?

北城以北 提交于 2020-01-03 05:13:14

问题


As of the Google Assistant SDK 0.4.1, developers using it can change the language/locale using both the Google Assistant Library and the Google Assistant Service.

This post will explain how developers can take advantage of this feature.


回答1:


Google Assistant Service

Using the gRPC API, developers can easily and programmatically change the locale in each API call. They can also change the locale as an argument to the pushtotalk.py sample.

We can take a look at the Embedded Assistant protobuf which shows the API.

Embedded Assistant Protobuf

rpc Assist(stream AssistRequest) returns (stream AssistResponse);

The API call requires an AssistantRequest and returns an AssistResponse

An AssistantRequest can be an AssistConfig. An AssistConfig may contain several properties including a DialogStateIn. A DialogStateIn may contain several properties including a language_code.

string language_code = 2;

From the documentation about this property:

// *Required* Language of the request in
// [IETF BCP 47 syntax](https://tools.ietf.org/html/bcp47). For example:
// "en-US". If you have selected a language for this `device_id` using the
// [Settings](https://developers.google.com/assistant/sdk/guides/assistant-settings)
// menu in your phone's Google Assistant app, that selection will override
// this value.

Using strings such as en-US, fr-FR or any other locale that the Assistant supports.

pushtotalk.py

Developers running the sample can change locales by including the --lang argument followed by the locale code when running the script.

Google Assistant settings

After you register your device it will appear in the list of devices in the Google Assistant settings.

Google Assistant > Explore > Settings > Devices

From here, you can go into settings for each device. This will allow you to change the language of the device using a friendly picker. Note that once you do, this will override the value set programmatically.

Google Assistant Library

If you are using the Google Assistant Library or the hotword.py sample, you can only change the language in the Google Assistant settings on your phone.



来源:https://stackoverflow.com/questions/48017507/how-do-i-change-the-language-locale-in-the-google-assistant-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!