Transcriptions: how to do it and use it!
March 26th, 2010 by John DyerSo you have got a great application, it does all this fancy stuff and now you want to add transcriptions, but how? Well its actually quite simple! Transcriptions in Tropo are sent as a XML body, via POST, to the URL specified in the transcriptionOutURI parameter of the recording method. So below I have taken an example from our blog which showed how to actually do a transcription using the the record method.
answer
say 'Welcome to ruby recording test'
event = record('Say something after the beep.',
{ :repeat => 0,
:bargein => true,
:beep => true,
:silenceTimeout => 2,
:maxTime => 30,
:timeout => 4.03456789,
:recordURI => 'http://tropo.to-a-domain.com/post_audio?filename=file123456.wav',
:transcriptionOutURI => 'http://tropo.to-a-domain.com/transcriptions/tropoTranscribeCatch.php',
:transcriptionID => '123456' })
log 'Recorded file: ' + event.recordURI
say 'Thanks for your testing ruby on Tropo platform'
hangup
So you can go ahead and deploy this bad boy to your hosted account and map it up to an application! So once this is done you need something on the other end to catch the transcription…what to do??!! Well I have a little example, which is also plug and play, that may be just what you are looking for! To start you simply deploy this little bit of ‘PHP Goodness ™’ to your webserver. This script will take the posted data, access the relevant nodes, and write it to disk for you.
<?
date_default_timezone_set('EST');
$obj = json_decode(@file_get_contents('php://input'));
$myFile = $obj->result->guid."-".$obj->result->identifier.".txt"; // Unique file name
touch ($myFile);
$fh = fopen($myFile, 'a');
fwrite($fh, "Time Stamp:" . date('D, d M Y H:i:s T') . "\n");
// access XML data
fwrite($fh, "Guid " . $obj->result->guid . "\n");
fwrite($fh, "Identifier: " . $obj->result->identifier . "\n");
fwrite($fh, "Transcription: " . $obj->result->transcription . "\n");
fwrite($fh,"________________________________________\n");
fclose($fh);
?>
Few tips that may help as well:
- You may want to make sure your webserver has write permissions to the directory were you will be saving transcriptions
- (chmod -R 775 /var/htdocs/transcriptions/)).
- Make sure your PHP install is at least PHP 5.2, as the json_decode extension used in this example requires it.
I really hope this helps, and if there are any questions please feel free to contact our support team. We are most certainly always here to help!
Regards,
John Dyer
Customer Engineer
Voxeo Support
Related posts:
Tags: PHP, transcription, transcriptions, Tropo
