【问题标题】:Twilio VoiceBase High Accuracy Transcription download using PHP使用 PHP 下载 Twilio VoiceBase 高精度转录
【发布时间】:2017-08-05 04:12:24
【问题描述】:

我正在使用 VoiceBase 高精度转录插件。我需要使用 PHP 下载转录文本。在我给出 webhook URL 之后,我得到了一个带有有效负载 URL 的成功响应。

但是,我如何使用这些信息在 PHP 中下载脚本文件。

谢谢

【问题讨论】:

    标签: twilio


    【解决方案1】:

    在您的 webhook URL 中使用此脚本

    <?php
    
        //First collectand parse JSON from Twilio POST
        $twilio_response_payload = $_POST["AddOns"];
        $twilio_response_payload = json_decode($twilio_response_payload, true);
    
        //Grab the VoiceBase Data url
        $url = $twilio_response_payload['results']['voicebase_transcription']['payload'][0]['url'];
    
    
        $twilio_account_sid = "your-Twilio-sid";
        $twilio_auth_token = "your-Twilio-Auth-Token";
    
    
         //Send a GET with basic auth
    
            set_time_limit(0);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_POST, 0);
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 0);
            curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 0);
            curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 60);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_USERPWD, $twilio_account_sid . ":" . $twilio_auth_token);  
            $response = curl_exec($ch);
            curl_close($ch);
    
          //Response is of xml form that contains an s3 url, extract the s3 url. I manipulate the string, there is probably a cleaner way.
    
          $s3url = substr($response, strpos($response, "<RedirectTo>") + 12, strpos($response, "</RedirectTo>") - strpos($response, "<RedirectTo>") - 12);            
          $s3url = html_entity_decode($s3url);
    
    
          //Make another curl to that s3 url
    
            set_time_limit(0);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_POST, 0);
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 0);
            curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 0);
            curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 60);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
            curl_setopt($ch, CURLOPT_URL, $s3url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $response = curl_exec($ch);
            curl_close($ch);              
    
          //The response will be some JSON, parse the JSON
    
          $json_response = json_decode($response,true);
    
          //Media > Transcripts > Text is the plain text transcript, create a file or do whatever you like with it
    
          $text = $json_response['media']['transcripts']['text'];
    
          $file = 'transcription.txt';
          file_put_contents($file, $text);
    
      ?>
    

    【讨论】:

    • 感谢您的快速回复
    猜你喜欢
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    相关资源
    最近更新 更多