Thursday, 12 October 2017

Azure video indexer - Get text from the Video


Question: What is Video Indexer API?
This API is used to Get the Visual Text from the Video. It will give you all the text that appear in the video.



Question: How to Get Text from the video?
  1. Get the API key
  2. Get the VIdeo URL from Azure OR Amazon S3 Or any public video URL.
  3. Pass the Video URL with API key and get the video Id token.
  4. Pass the video Id token with API key and get the all Text



Question: How to Get the API Key?
Follow the below link, you will get the API key which can be used further.
https://docs.microsoft.com/en-us/azure/cognitive-services/video-indexer/video-indexer-use-apis#subscribe-to-the-api


Question: How to Get the videoId token from the video?
$subScriptionKey = 'AZURE_SUBSCRIPTION_KEY_HERE';   
$videoUrl='https://foldername.blob.core.windows.net/bucketname/GV-NNokn-989-5175_360p.mp4';

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns?name=new%20video%20test&privacy=Private&videoUrl=".urlencode($videoUrl),
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    "ocp-apim-subscription-key: {$subScriptionKey}",    
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

OR Using Zend Framework
$subScriptionKey = 'AZURE_SUBSCRIPTION_KEY_HERE';   
$videoUrl='https://foldername.blob.core.windows.net/bucketname/GV-NNokn-989-5175_360p.mp4';
$jsonData = '';        
$config = array(
       'adapter' => 'Zend_Http_Client_Adapter_Curl',
       'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,CURLOPT_SSL_VERIFYPEER =>FALSE),            
   );
    $url='https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns';
   $client = new Zend_Http_Client($url, $config);
   //Set the Header value
    $client->setHeaders('Content-Type', "multipart/form-data");
    $client->setHeaders('Ocp-Apim-Subscription-Key', $subScriptionKey);

    $postData = array(
    'name'=>'GV-NNokn-989-5175',
    'privacy'=>'Private',
    'videoUrl'=>$videoUrl
    );
    $client->setParameterGet($postData);

   $response = $client->request('POST'); 
   $jsonData= ($response->getBody());



Output
9a10d9d0002



Question: How to get video text from videoId token?
$subScriptionKey = 'AZURE_SUBSCRIPTION_KEY_HERE';   
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns/VIDEOIDTOKEN",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "ocp-apim-subscription-key: {$subScriptionKey}",
    "postman-token: 43c1c192-1de6-ac3d-42e0-b1ddc7cc0ee0"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

OR Using Zend Framework
$subScriptionKey = 'AZURE_SUBSCRIPTION_KEY_HERE';   
        $language = 'English';
        $body = 'How to you?';
        $breadDownsId='2bc89c5ec1';

        //Main Data
        $client = new Zend_Http_Client('https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns/' . $breadDownsId, array(
            'maxredirects' => 0,
            'timeout' => 30
        ));       
        
        $client->setHeaders('Ocp-Apim-Subscription-Key', $subScriptionKey);

        $parameters = array(
            'language' => $language,
        );
        $client->setParameterGet($parameters);

        try {
            $response = $client->request('GET');
            $data = $response->getBody();
        } catch (Exception $ex) {
            $data = $ex;
        }
        echo $response->getBody();die;

Output
{
    "accountId": "2b525a6-3a5408006294",
    "id": "9a10d9d912",
    "partition": null,
    "name": "new video test",
    "description": null,
    "userName": "Ram Kumar",
    "createTime": "2017-10-12T04:41:20.8986398+00:00",
    "organization": "",
    "privacyMode": "Private",
    "state": "Processed",
    "isOwned": true,
    "isEditable": false,
    "isBase": true,
    "durationInSeconds": 1373,
    "summarizedInsights":{/* It will have data*/},
    "breakdowns":{/* It will have data*/},
    "social":{/* It will have data*/}
}




Wednesday, 11 October 2017

How to get Speech Recognition from Audio OR Video

How to get Speech Recognition from Audio OR Video

Question: What does do the voicebase.com?
Give the Audio/Video URL in API and get all Speech in Text.


Question: How to get the API Key?
You can request API access using this form: http://info.voicebase.com/request-api-key


Question: What other it can do?
  1. Machine-generated Transcript
  2. Per Word Confidence
  3. Time-stamped words
  4. Player SDK
  5. Stereo speaker ID



Question: How to get media-id in voicebase api?
    //Get Token
    $tokenKey='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUadDKFDSLJLDLJKJLKKWWUEUUEEUUEUEUUEUUEUDUUDUDDLDLDLLDLLLDLLDLDLKFMFKK2b2ljZWJhc2UuY29tIn0.8M4bmafBqdlqon-o65CMKabBjxVatDObzRklDoUysNU';

    //Get Video URL
    $videoAudioURL='http://example.com/audio/filename.mp3';

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://apis.voicebase.com/v3/media",
      CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER=>false,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"mediaUrl\"\r\n\r\n{$videoAudioURL}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
      CURLOPT_HTTPHEADER => array(
        "authorization: Bearer {$tokenKey}",
        "cache-control: no-cache",
        "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",    
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }



Output
{
  "_links": {
    "self": {
      "href": "/v3/media/70cafaf7-89bc-474f-bb02-c59f0181a51f"
    },
    "progress": {
      "href": "/v3/media/70cafaf7-89bc-474f-bb02-c59f0181a51f/progress"
    },
    "metadata": {
      "href": "/v3/media/70cafaf7-89bc-474f-bb02-c59f0181a51f/metadata"
    }
  },
  "formatVersion": "3.0.1",
  "mediaId": "70cafaf7-89bc-474f-bb02-c59f0181a51f",
  "status": "accepted",
  "dateCreated": "2017-10-11T08:46:56.343Z",
  "metadata": {
    
  },
  "mediaContentType": "video/mp4",
  "length": 222956
}



Question: How to get transcription from mediaID?
        //Get Token
        $tokenKey='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUadDKFDSLJLDLJKJLKKWWUEUUEEUUEUEUUEUUEUDUUDUDDLDLDLLDLLLDLLDLDLKFMFKK2b2ljZWJhc2UuY29tIn0.8M4bmafBqdlqon-o65CMKabBjxVatDObzRklDoUysNU';
        $mediaId='70cafaf7-89bc-474f-bb02-c59f0181a51f';

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://apis.voicebase.com/v3/media/{$mediaId}",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"mediaUrl\"\r\n\r\nhttp://enterprise-dev2.georama.com/test/love.mp3\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer {$tokenKey}",
    "cache-control: no-cache",
    "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    "postman-token: 0effcf6c-38cd-0ebc-dc87-3d821fd5ca72"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
Output
{
  "confidence": 0.16606535003699963,
  "words": [
    {
      "p": 0,
      "c": 0.998,
      "s": 4230,
      "e": 4540,
      "w": "Hello"
    },
    {
      "p": 1,
      "c": 0.95,
      "s": 4549,
      "e": 4660,
      "w": "my"
    },
    {
      "p": 2,
      "c": 0.941,
      "s": 4670,
      "e": 4799,
      "w": "name"
    }
  ]
}