gpt4 book ai didi

node.js - DialogFlow 更改识别语言

转载 作者:太空宇宙 更新时间:2023-11-03 23:00:50 24 4
gpt4 key购买 nike

我正在 DialogFlow 上构建多语言教育应用程序。我遇到了一个大问题:切换识别语言。有什么建议我如何实现这一目标或任何其他方法?

我已添加到 DialogFlow Web 界面第二语言。

我正在使用带有 Node.js Webhook 的 action-on-google sdk。

更新:

 let responseToUser = {
//fulfillmentMessages: richResponsesV2, // Optional, uncomment to enable
//outputContexts: [{ 'name': `${session}/contexts/weather`, 'lifespanCount': 2, 'parameters': {'city': 'Rome'} }], // Optional, uncomment to enable
fulfillmentText: 'This is from Dialogflow\'s Cloud Functions for Firebase editor! :-)', // displayed response
payload: {
audioConfig : {
"audioEncoding": 'AUDIO_ENCODING_FLAC',
"sampleRateHertz": 16000,
"languageCode": 'de',
"phraseHints": ["gutten tag"]
}
},
function sendResponse (responseToUser) {
// if the response is a string send it as a response to the user
if (typeof responseToUser === 'string') {
let responseJson = {fulfillmentText: responseToUser}; // displayed response
response.json(responseJson); // Send response to Dialogflow
} else {
// If the response to the user includes rich responses or contexts send them to Dialogflow
let responseJson = {};
// Define the text response
responseJson.fulfillmentText = responseToUser.fulfillmentText;
responseJson.payload = responseToUser.payload;

// Send the response to Dialogflow
console.log('Response to Dialogflow: ' + JSON.stringify(responseJson));
response.json(responseJson);

请求json:

{
"responseId": "c4ea35d3-1455-4142-b7d2-22417c5880ae",
"queryResult": {
"queryText": "hi",
"action": "default",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "This is from Dialogflow's Cloud Functions for Firebase editor! :-)",
"fulfillmentMessages": [
{
"text": {
"text": [
"This is from Dialogflow's Cloud Functions for Firebase editor! :-)"
]
}
}
],
"webhookPayload": {
"sampleRateHertz": 16000,
"languageCode": "de",
"phraseHints": [
"gutten tag"
],
"audioEncoding": "AUDIO_ENCODING_FLAC"
},
"outputContexts": [
{
"name": "projects/homehf-master/agent/sessions/824b34b9-45f8-4c65-9377-a31242d3414b/contexts/test_context",
"lifespanCount": 5
}
],
"intent": {
"name": "projects/homehf-master/agent/intents/0259f134-6d4d-4aed-920d-9240adbe38fe",
"displayName": "starter_intent"
},
"intentDetectionConfidence": 0.75,
"diagnosticInfo": {
"webhook_latency_ms": 44
},
"languageCode": "en"
},
"webhookStatus": {
"message": "Webhook execution successful"
}
}

最佳答案

Dialogflow 需要带有 audio request 的语言,如果您想更改该语言,则需要发出新请求。您可以在 Webhook 和前端中实现一些逻辑,以使用不同的语言再次尝试请求。

为此,请在 webhook response 的有效负载字段中添加一些数据响应表明您想使用指定的不同语言发出新请求。在您的客户端中,检查 response payload 中的数据如果数据指示使用另一种语言重试,则使用 input audio config 中指定的不同语言发送另一个请求。具有相同的音频。

关于node.js - DialogFlow 更改识别语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48564428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com