0
我目前有一個問題,即錄音少數是空的(從Twilio的服務器上下載它們時)時,他們應該不會摔跤。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);
}