gpt4 book ai didi

node.js - 在 Twilio 语音通话中重放一段话

转载 作者:搜寻专家 更新时间:2023-11-01 00:03:49 26 4
gpt4 key购买 nike

我正在尝试编写一个简单的 Twilio 设置,该设置将进行出站调用、记录用户的语音消息并立即将其重播给他。我创建了两个函数:startcallmsginStartCall 调用用户并在调用的 url 参数中指定 MsgInMsgIn 然后有两种主要的操作模式:最初,当没有附加录音时,它会返回一个开始录音的 TwiML 响应,然后当使用适当的参数作为 webhook 调用时,它会播放录音并挂起向上。至少那是它应该做的。

根据我对文档的理解,我必须将一个 webhook 附加到 recordingStatusCallback,因为当调用 action webhook 时,录音可能还不可用。然而,虽然功能控制台指示两个 webhook 都已执行,但调用日志仅显示 msgin 的一次后续调用,其中 event.RecordingStatus 为空值(对应to action), 通话确实挂断了,没有回放录音。我在这里缺少什么?

// this function's path is /msgin

exports.handler = function(context, event, callback) {
if (!event.RecordingStatus && !event.RecordingUrl) {
let twiml = new Twilio.twiml.VoiceResponse();
console.log("Initial MsgIn");
twiml.say({ voice: 'man', language: 'en-us' }, 'Leave your message');
twiml.record({
playBeep: false,
transcribe: false,
trim: "trim-silence",
timeout: 1,
recordingStatusCallback: "/msgin",
recordingStatusCallbackEvent: "completed",
action: "/msgin"
});
console.log("Recording started");
callback(null, twiml);
}
else if (event.RecordingStatus == "completed") {
let twiml = new Twilio.twiml.VoiceResponse();
console.log("Supposedly callback");
twiml.say({ voice: 'man', language: 'en-us' }, 'You said');
twiml.play(event.RecordingUrl);
twiml.hangup();
callback(null, twiml);
}
else {
console.log("Supposedly action");
callback(null, "");
}
};

最佳答案

我已按照此处接受的答案中的说明进行操作:Recording multiple user answers in Twilio call解决这个问题。不过,在录音可用之前会有相当长的延迟。

关于node.js - 在 Twilio 语音通话中重放一段话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54289124/

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