[英]How do I force google action to switch the language during conversation?
I am building a bot for the google assistant using the action-on-google sdk and dialogflow in a webhook .我正在使用webhook 中的action-on-google sdk和 dialogflow 为 google 助手构建一个机器人。
During the conversation, I need to give to the user the option to switch the language, as the implemented language detection doesn't work every time.在对话期间,我需要为用户提供切换语言的选项,因为实现的语言检测并非每次都有效。
Exemple, in the middle of the conversation:例如,在谈话中间:
All I have found is that I can get the language of the request with agent.locale
, but I haven't found any way to set it.我所发现的只是我可以使用
agent.locale
获取请求的语言,但我还没有找到任何设置它的方法。
Any help?有什么帮助吗?
该平台不支持动态交换语言。
If you are using any SDK to call dialogflow then you can change language code based on some logic or some utterance (maybe identify the language and pass the language code accordingly).如果您使用任何 SDK 来调用对话流,那么您可以根据某种逻辑或某种话语更改语言代码(可能识别语言并相应地传递语言代码)。
For python SDK you can use below code and change the language_code
accordingly.对于python SDK,您可以使用以下代码并相应地更改
language_code
。
text_input = dialogflow.types.TextInput(text=text, language_code="en")
query_input = dialogflow.types.QueryInput(text=text_input)
response = session_client.detect_intent(session=session, query_input=query_input)
Hope it helps.希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.