【问题标题】:Twilio - Downloaded call recordings are sometimes emptyTwilio - 下载的通话录音有时是空的
【发布时间】:2015-09-11 13:03:00
【问题描述】:

我目前正在努力解决一个问题,即少数记录是空的(从 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);
}

【问题讨论】:

    标签: download twilio recording conference


    【解决方案1】:

    我无法在他们的网站上获得 Twilio 的回复,我自己的搜索也没有找到任何结果。

    我现在解决这个问题的方法是实现一个循环,该循环将多次调用 getMp3,直到确认文件已正确下载。我使用 PHP 的文件大小函数做到了这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-17
      • 2017-12-07
      • 2018-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多