我目前正在努力解决一个问题,即少数录音是空的(当从Twilio的服务器下载时)它们不应该是。
我的申请目前每天约有10,000个电话。如果应答,则记录这些呼叫中的每一个,然后将该记录下载到我的服务器。
无论出于何种原因,这些下载的mp3文件中的少数是空的,它们的大小为363字节(没有音频,只有文件本身),即使我知道mp3文件中应该有内容。例如,某些通话将持续30-40分钟,但下载时会录制空白。
我正在使用PHP开发并附加了用于下载下面录制的代码。有什么看起来偶尔会引起问题吗?我已经尝试过寻找其他人可能遇到的类似问题,到目前为止还没找到任何东西。
请记住,此代码适用于90%的情况......只有10%的代码无法正确下载。
非常感谢你的时间!
public function index()
{
if (isset($_REQUEST['RecordingUrl'])) {
// Get the call ID from the url
$confId = $this->security->xss_clean($_GET['confId']);
$callId = $this->security->xss_clean($_GET['callId']);
$userId = $this->security->xss_clean($_GET['userId']);
// Twilio account information
$accountSid = $this->config->item('twilio_accountSid');
$authToken = $this->config->item('twilio_authToken');
// Download the recording to our server
$callUrl = 'recordings/calls/' . $callId . '.mp3';
$this->getMp3($_REQUEST['RecordingUrl'], $callUrl);
// Delete the recording from Twilio's servers
$this->deleteMp3($_REQUEST['RecordingUrl'], $accountSid, $authToken);
// Mark this call as completed and update its log
$this->call->logEndOfCall($callId);
// Load a blank Twilio response to keep the server from throwing an error
$this->load->view('twilio/blank_twiml');
}
}
private function getMp3($sourceUrl = '', $destinationUrl = '')
{
// Add the '.mp3' onto the end of the url to return an mp3 file
$sourceUrl = $sourceUrl . '.mp3';
// Set the variables and initialize cURL
$destinationUrl = '/' . $destinationUrl;
$fp = fopen($destinationUrl, 'w+');
$ch = curl_init();
$timeout = 300;
// Sleep for two seconds to prevent a race condition with Twilio
sleep(2);
// Set the options for cURL to download the file
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $sourceUrl);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
// Execute the cURL
curl_exec($ch);
// Save any information for future debugging purposes
$info = curl_getinfo($ch);
// Close the new mp3 file and cURL
curl_close($ch);
fclose($fp);
}
private function deleteMp3($url = '', $username, $password)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
$result = curl_exec($ch);
curl_close($ch);
}
答案 0 :(得分:1)
我无法在他们的网站上收到Twilio的回复,而且我自己的搜索没有显示任何结果。
我现在所做的就是实现一个循环,它会多次调用getMp3,直到确认文件已正确下载为止。我是使用PHP的文件大小功能完成的。