gpt4 book ai didi

node.js - Firebase 功能因印地语字符而出现故障

转载 作者:太空宇宙 更新时间:2023-11-04 01:29:12 25 4
gpt4 key购买 nike

Firebase 函数正在调用 this Hindi API用于对话流操作。 firebase 函数正在发送 API 调用错误,但是在使用 english API 进行测试时它可以正常工作。 ,但当时我的查询文本也是英文的。预期的输出是,它播放古兰经的经文。

我认为问题出在查询文本上。它可能需要有 utf-8 编码或类似的东西? firebase函数如下:

const functions = require('firebase-functions');
var request1 = require('request');

exports.webhook = functions.https.onRequest((request, response) => {
console.log("request.body.result.parameters: ", request.body.queryResult.parameters);
let params = request.body.queryResult.parameters;

if (request.body.queryResult.intent.displayName === "verseByVerse") {
var options = {
url: `https://theislam360.me/api/find/hindi/${params.any}`,
json: true
}
request1(options, function (error, res, body) {
if (error) response.send({ fulfillmentText: "error in API call" });
else {
var audio ="";
var length = Object.keys(body).length;
var surah_id = [];
var ayat_no = [];
for (i = 1; i <= length; i++) {
surah_id.push(body[`result_${i}`].Surah_No);
ayat_no.push(body[`result_${i}`].Ayat_No);
if ((surah_id[i-1]<10) && (ayat_no[i-1]<10)){
audio = audio +
`Surah Number ${surah_id[i-1]}, Ayat Number ${ayat_no[i-1]}<audio src='https://theislam360.me/api/play/versebyverse/00${surah_id[i-1]}00${ayat_no[i-1]}.mp3'></audio>`;
}
else if ((surah_id[i-1]<10) && (ayat_no[i-1]>9) && (ayat_no[i-1]<100)){
audio = audio +
`Surah Number ${surah_id[i-1]}, Ayat Number ${ayat_no[i-1]}<audio src='https://theislam360.me/api/play/versebyverse/00${surah_id[i-1]}0${ayat_no[i-1]}.mp3'></audio>`;
}
else if ((surah_id[i-1]<10) && (ayat_no[i-1]>99)){
audio = audio +
`Surah Number ${surah_id[i-1]}, Ayat Number ${ayat_no[i-1]}<audio src='https://theislam360.me/api/play/versebyverse/00${surah_id[i-1]}${ayat_no[i-1]}.mp3'></audio>`;
}
else if ((surah_id[i-1]>9) && (surah_id[i-1]<100) && (ayat_no[i-1]<10)){
audio = audio +
`Surah Number ${surah_id[i-1]}, Ayat Number ${ayat_no[i-1]}<audio src='https://theislam360.me/api/play/versebyverse/0${surah_id[i-1]}00${ayat_no[i-1]}.mp3'></audio>`;
}
else if ((surah_id[i-1]>9) && (surah_id[i-1]<100) && (ayat_no[i-1]>9) && (ayat_no[i-1]<100)){
audio = audio +
`Surah Number ${surah_id[i-1]}, Ayat Number ${ayat_no[i-1]}<audio src='https://theislam360.me/api/play/versebyverse/0${surah_id[i-1]}0${ayat_no[i-1]}.mp3'></audio>`;
}
else if ((surah_id[i-1]>9) && (surah_id[i-1]<100) && (ayat_no[i-1]>99)){
audio = audio +
`Surah Number ${surah_id[i-1]}, Ayat Number ${ayat_no[i-1]}<audio src='https://theislam360.me/api/play/versebyverse/0${surah_id[i-1]}${ayat_no[i-1]}.mp3'></audio>`;
}
else if ((surah_id[i-1]>99) && (ayat_no[i-1]<10)){
audio = audio +
`Surah Number ${surah_id[i-1]}, Ayat Number ${ayat_no[i-1]}<audio src='https://theislam360.me/api/play/versebyverse/${surah_id[i-1]}00${ayat_no[i-1]}.mp3'></audio>`;
}
else if ((surah_id[i-1]>99) && (ayat_no[i-1]>9) && (ayat_no[i-1]<100)){
audio = audio +
`Surah Number ${surah_id[i-1]}, Ayat Number ${ayat_no[i-1]}<audio src='https://theislam360.me/api/play/versebyverse/${surah_id[i-1]}0${ayat_no[i-1]}.mp3'></audio>`;
}
else if ((surah_id[i-1]>99) && (ayat_no[i-1]>99)){
audio = audio +
`Surah Number ${surah_id[i-1]}, Ayat Number ${ayat_no[i-1]}<audio src='https://theislam360.me/api/play/versebyverse/${surah_id[i-1]}${ayat_no[i-1]}.mp3'></audio>`;
}
if (surah_id[i-1]>90){
audio = audio + `<audio src='https://theislam360.me/api/play/versebyverseurdu/${surah_id[i-1]}-${ayat_no[i-1]}.mp3'></audio>`
}
// audio = audio +
// `<audio src="https://theislam360.me/api/play/versebyverse/002005.mp3"/>`;
}
response.send({fulfillmentText:`<speak>
${audio}
Let’s play the SSML Trivia Game!
<break time="500ms"/>
</speak>`})
}
}
)}
});

आदमी的意思是“男人”

原始 API 响应

{
"responseId": "8e0f258a-5931-4364-9f45-b4d283d95584-baaf0c1f",
"queryResult": {
"queryText": "क़ुरान आदमी के बारे में कहाँ बात करता है?",
"parameters": {
"any": "आदमी"
},
"allRequiredParamsPresent": true,
"fulfillmentText": "error in API call",
"fulfillmentMessages": [
{
"text": {
"text": [
"error in API call"
]
}
}
],
"intent": {
"name": "projects/versebyversequran/agent/intents/7c009ede-8b68-4db1-9cf6-b3cf1241691a",
"displayName": "verseByVerse"
},
"intentDetectionConfidence": 0.7840172,
"diagnosticInfo": {
"webhook_latency_ms": 122
},
"languageCode": "en"
},
"webhookStatus": {
"message": "Webhook execution successful"
}
}

注意:如果您需要任何进一步的信息,请告诉我

最佳答案

您将收到请求路径包含未转义字符错误,因此您需要encodeURI

var request1 = require('request');
var options = {
url: encodeURI(`https://theislam360.me/api/find/hindi/आदमी`),
json: true
}
request1(options, function (error, res, body) {
console.log(error);
console.log(body);
})

关于node.js - Firebase 功能因印地语字符而出现故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56596297/

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