在不知道 SID 的情况下在 PHP 中检索 Twilio 转录文本

retrieve twilio transcription text in php without knowing sid

提问人:Dango 提问时间:10/26/2013 更新时间:11/17/2013 访问量:726

问:

我正在开发一个 twilio 应用程序,该应用程序可以转录语音,然后将其转换为文本。在检索转录文本之前,一切都正常运行。我知道如果我知道“sid”,我可以检索转录代码,但是如果我想即时获取转录代码并且不知道“sid”怎么办。换句话说,我想要电话号码“555-555-1212”的最新转录,我能找到的只是下面的代码。

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "AC1240edf87a1d3b6717472af6deda4ce7";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
$client->account->transcriptions->delete("TR8c61027b709ffb038236612dc5af8723");
?>

提前致谢! 迭 戈

PHP Twilio

评论


答:

0赞 E.J. Brennan 10/26/2013 #1

您将需要获取呼叫的 SID,但如果您知道电话号码,并且可以选择要查找的日期范围,这很容易做到(我的 PHP 生锈了,所以你可能需要修饰一下):

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "{{ sid }}"; 
$token = "{{ auth_token }}"; 
$client = new Services_Twilio($sid, $token);

// Get calls to a number on or after a certain date.
foreach ($client->account->calls->getIterator(0, 50, array("Status" => "completed", "To" => "555-555-1212","StartTime" => "2013-10-26")) as $call)  {
    echo $call->sid
    //now use the sid to get the transcription text using a seperate rest call.
    $transcription = $client->account->transcriptions->get($call->sid);
    echo $transcription->transcription_text;    
}

评论

0赞 Dango 10/27/2013
回声 $transcription->transcription_text;抛出以下错误 --> 致命错误:未捕获异常“Services_Twilio_RestException”,并显示消息“未找到请求的资源” 似乎调用 sid 和 transcrption sid 完全不同......
0赞 Dango 11/17/2013 #2

修复我原来的问题=)

<?php
//RETRIEVE NUMBERS LAST TRANSCRIPTION
$client = new Services_Twilio($sid, $token);
$i=0;
foreach($client->account->transcriptions->getIterator(0, 50, array('Status' =>  'completed', 'To' => ''.$_GET['number'].'')) as $call)  {  
//now use the sid to get the transcription text using a seperate rest call.
if($i==1) break;
$transcription = $client->account->transcriptions->get($call->sid);
$sms_text = $transcription->transcription_text;
$i++;
}
?>
0赞 Devin Rader 11/17/2013 #3

Twilio 布道者在这里。

另一种选择是,如果您使用动词,则可以设置 transcribeCallback 参数:<Record>

https://www.twilio.com/docs/api/twiml/record#attributes-transcribe-callback

这样,你就可以向 Twilio 提供一个 URL,我们将在完成转录时请求该 URL。

希望能有所帮助。