So, how does it work? Each SpokenData API function is composed of SpokenData base API url, USER-ID, API-TOKEN and the name of the function.
SpokenData API url: | http://spokendata.com/api |
---|---|
USER-ID: | different for each user, available for signed-in at http://spokendata/api |
API-TOKEN: | different for each user, available for signed-in at http://spokendata/api |
API function: | recording/put |
If we concatenate the above values, we get the API call url. It may look like this:
http://spokendata.com/api/18/br3sp59a2it7fig94jdtbt3p9ife5qpx39fd8npp/recording/put
Each API call can have parameters. When uploading a new file through API, you need to enter the recording filename and the language for automatic speech processing. So basically, you will end up with a URL looking like this:
http://spokendata.com/api/18/br3sp59a2it7fig94jdtbt3p9ife5qpx39fd8npp/recording/put?filename=audio.mp3&language=english
Basically, there are also available other parameters you can read about in the SpokenData API documentation. When you call the above url, don't forget to put the file content.
Here is a code example that uploads an MP3 file using the HTTP PUT method to SpokenData.
<?php
$fileToUpload = 'd:/audio.mp3';
$url = 'http://spokendata.com/api/18/br3sp59a2it7fig94jdtbt3p9ife5qpx39fd8npp/recording/put?filename=audio.mp3&language=english';$file = fopen($fileToUpload, "rb");
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_VERBOSE, '1');
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Expect: '));
curl_setopt($curl, CURLOPT_PUT, 1);
curl_setopt($curl, CURLOPT_INFILE, $file);
curl_setopt($curl, CURLOPT_INFILESIZE, filesize($fileToUpload));
$response = curl_exec($curl);
curl_close($curl);
header ("Content-Type:text/xml");
echo $response;
The server responds in XML. Here is an example response of the above script.
<?xml version="1.0" encoding="utf8"?> | |
<data> | |
<message>New media file "audio.mp3" was successfully added.</message> | |
<recording id="1373"></recording> | |
</data> |
As you can see, the file audio.mp3 was successfully added and assigned the recording id = 1373.
No comments:
Post a Comment