2017-08-03 7 views
0

私はVoiceBase High Accuracy Transcriptionアドオンを使用しています。私はPHPを使用してtrascriptedテキストをダウンロードする必要があります。私はwebhookのURLを与えた後、私はペイロードのURLで成功の応答を得た。Twilio VoiceBase高精度転写PHPを使用したダウンロード

しかし、これらの情報を使ってPHPでトランスクリプトファイルをダウンロードするにはどうすればよいですか?

おかげ

答えて

3

<?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); 

    ?> 
+0

ウル迅速な返信いただきありがとうございますあなたのウェブフックのURLでこのスクリプトを使用します –

関連する問題