简体   繁体   中英

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 .

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:

  • Assistant: "do you want to ask your question in English or in French?"
  • User: "in French"
  • Assistant: "D'accord, j'écoute votre question..."

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.

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).

For python SDK you can use below code and change the language_code accordingly.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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