Showing posts with label voicebase. Show all posts
Showing posts with label voicebase. Show all posts

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"
    }
  ]
}