gpt4 book ai didi

Twilio 录音

转载 作者:行者123 更新时间:2023-12-04 11:26:04 33 4
gpt4 key购买 nike

我正在使用 twilio JS 客户端从 Web 进行调用。客户端调用后端获取 token 。这里是返回 token 的后端代码。如何记录通话。表示在哪里设置录制网址。通话成功。但是不知道从哪里传录音的url。

public function newToken(Request $request)
{
$accountSid = config('services.twilio')['accountSid'];
$applicationSid = config('services.twilio')['applicationSid'];
$apiKey = config('services.twilio')['apiKey'];
$apiSecret = config('services.twilio')['apiSecret'];

$voiceGrant = new VoiceGrant();
$voiceGrant->setOutgoingApplicationSid($applicationSid);

$voiceGrant->setIncomingAllow(true);

$this->accessToken->addGrant($voiceGrant);

$token = $this->accessToken->toJWT();

return response()->json(['token' => $token]);
}
在 JS 端,使用 twillio 客户端库的代码。
const Device = Twilio.Device;

// Store some selectors for elements we'll reuse
var callStatus = $("#call-status");
var answerButton = $(".answer-button");
var callSupportButton = $(".call-support-button");
var hangUpButton = $(".hangup-button");
var callCustomerButtons = $(".call-customer-button");

var device = null;

function updateCallStatus(status) {
callStatus.attr('placeholder', status);
}

/* Get a Twilio Client token with an AJAX request */
$(document).ready(function() {
setupClient();
});

function setupHandlers(device) {
device.on('ready', function(_device) {
updateCallStatus("Ready");
});

/* Report any errors to the call status display */
device.on('error', function(error) {
updateCallStatus("ERROR: " + error.message);
});

/* Callback for when Twilio Client initiates a new connection */
device.on('connect', function(connection) {
// Enable the hang up button and disable the call buttons
hangUpButton.prop("disabled", false);
callCustomerButtons.prop("disabled", true);
callSupportButton.prop("disabled", true);
answerButton.prop("disabled", true);

// If phoneNumber is part of the connection, this is a call from a
// support agent to a customer's phone
if ("phoneNumber" in connection.message) {
updateCallStatus("In call with " + connection.message.phoneNumber);
} else {
// This is a call from a website user to a support agent
updateCallStatus("In call with support");
}
});

/* Callback for when a call ends */
device.on('disconnect', function(connection) {
// Disable the hangup button and enable the call buttons
hangUpButton.prop("disabled", true);
callCustomerButtons.prop("disabled", false);
callSupportButton.prop("disabled", false);

updateCallStatus("Ready");
});

/* Callback for when Twilio Client receives a new incoming call */
device.on('incoming', function(connection) {
updateCallStatus("Incoming support call");

// Set a callback to be executed when the connection is accepted
connection.accept(function() {
updateCallStatus("In call with customer");
});

// Set a callback on the answer button and enable it
answerButton.click(function() {
connection.accept();
});
answerButton.prop("disabled", false);
});
};

function setupClient() {
$.post("/token", {
forPage: window.location.pathname,
_token: $('meta[name="csrf-token"]').attr('content')
}).done(function(data) {
// Set up the Twilio Client device with the token
device = new Device();
device.setup(data.token);

setupHandlers(device);
}).fail(function() {
updateCallStatus("Could not get a token from server!");
});

};

/* Call a customer from a support ticket */
window.callCustomer = function(phoneNumber) {
updateCallStatus("Calling " + phoneNumber + "...");

var params = { "phoneNumber": phoneNumber };
device.connect(params);
};

/* Call the support_agent from the home page */
window.callSupport = function() {
updateCallStatus("Calling support...");

// Our backend will assume that no params means a call to support_agent
device.connect();
};

/* End a call */
window.hangUp = function() {
device.disconnectAll();
};

最佳答案

我假设您在 TwiML 应用程序上设置的 URL 生成的 TwiML 包含动词,以便将传入的客户端调用连接到类似 PSTN 号码的东西。
如果该假设是正确的,那么您可以包含 record该动词的属性:

<Response>
<Dial record="record-from-ringing-dual"
recordingStatusCallback="https://myapp.com/recording-events"
recordingStatusCallbackEvent="in-progress completed absent">
<Number>+15558675310</Number>
</Dial>
</Response>
对双 channel 录音使用从应答双录音或从振铃双录音的录音值,在不同的立体声轨道中进行 parent 和 child 的通话。
查看支持文章 Recording a Phone Call with Twilio更多细节。

关于Twilio 录音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67631521/

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