gpt4 book ai didi

node.js - 从 twilio 访问转录文本

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

我想访问我的 Twilio 帐户中的转录下的转录生成的转录文本,因为我想将用户记录的响应作为文本进行比较

twiml.say('Hi there! Please speak your response after the beep,-Get ready!')
.record({
transcribe:true,
timeout:5,
maxLength:30,
transcribeCallback:'/recording',
action:'/recording'

});
app.post('/recording', (request,response) => {
if(transcriptionText=='yes'){

twiml.say('thank you for positive response');
}
response.type('text/xml');
response.send(twiml.toString());

});

最佳答案

这里是 Twilio 开发者布道者。

当使用transcription时与 <Record> ,一旦录音完成,调用将继续向 action 发出请求。同步属性。无论您从action返回什么属性 URL 将控制调用。

然而,当您获得 transcribeCallback 的 Webhook 时,实际转录需要更多时间。 URL 它是在调用上下文之外异步完成的。因此,返回 TwiML 根本不会影响调用。

您将通过检查请求正文来获取转录文本。有很多parameters sent to the transcribeCallback ,但您正在寻找的是 TranscriptionText 。在你的 Node.js 应用程序中(对我来说它看起来像 Express),你可以通过调用 request.body.TranscriptionText 来获取它。 .

如果您确实想在收到转录回调时影响通话,则需要 use the REST API to modify the call and redirect it to some new TwiML .

请告诉我这是否有帮助。

[编辑]

从评论中我可以看到您正在尝试通过口头回复来插入部分通话。 transcribeCallback由于需要完成转录,因此不会立即调用 URL,因此您需要 action您在等待时可以将调用者转到的 URL。

因此,调整您的录音路线,为action设置不同的端点。和transcribeCallback :

app.post("/voice", (request, response) => {
var twiml = new twilio.TwimlResponse();
twiml.say('Hi there! Please speak your response after the beep,-Get ready!')
.record({
transcribe:true,
timeout:5,
maxLength:30,
transcribeCallback:'/transcribe',
action:'/recording'
});
response.type('text/xml');
response.send(twiml.toString());
})

然后,您的录制端点将需要在 Twilio 转录文本时让用户等待。

app.post('/recording', (request,response) => {
var twiml = new twilio.TwimlResponse();
// A message for the user
twiml.say('Please wait while we transcribe your answer.');
twiml.pause();
// Then redirect around again while we wait
twiml.redirect('/recording');
response.type('text/xml');
response.send(twiml.toString());
});

最后,当您收到转录回调时,您可以以某种方式从转录文本中找出路线,然后将实时调用重定向到一个新端点,该端点使用新信息进行调用。

app.post('/transcribe', (request, response) => {
var text = request.body.TranscriptionText;
var callSid = require.body.CallSid;

// Do something with the text
var courseId = getCourseFromText(text);

var accountSid = '{{ account_sid }}'; // Your Account SID from www.twilio.com/console
var authToken = '{{ auth_token }}'; // Your Auth Token from www.twilio.com/console
var client = new twilio.RestClient(accountSid, authToken);

// Redirect the call
client.calls(callSid).update({
url: '/course?courseId=' + courseId,
method: 'POST'
}, (err, res) => {
response.sendStatus(200);
})
});

关于node.js - 从 twilio 访问转录文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41195569/

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