Advertisement
Guest User

Untitled

a guest
Jan 25th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <form method="post" name="post_form" action="conversion.php" enctype="multipart/form-data">
  2. <input type="file" name="voice">
  3. <input type="submit" name="btnUpload" value="submit">
  4. </form>
  5. <?php
  6. if($_POST['btnUpload']) {
  7. $username = "username";
  8. $password = "password";
  9. $url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true&model=en-US_NarrowbandModel';
  10. $filename = $_FILES['voice']['name'];
  11. $filedata = $_FILES['voice']['tmp_name'];
  12. $file = fopen($filename, 'r');
  13. $filesize = filesize($filename);
  14. $bytes = fread($file,$filesize);
  15. $data = array('part_content_type' => 'audio/flac');
  16. $headers = array("Content-Type: audio/flac", "Transfer-Encoding: chunked");
  17. $ch = curl_init();
  18. curl_setopt($ch, CURLOPT_URL, $url);
  19. curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
  20. curl_setopt($ch, CURLOPT_POST, TRUE);
  21. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  22. curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
  23. curl_setopt($ch, CURLOPT_POSTFIELDS, $bytes);
  24. curl_setopt($ch, CURLOPT_INFILESIZE, $filesize);
  25. curl_setopt($ch, CURLOPT_VERBOSE, true);
  26. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  27. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  28. $executed = curl_exec($ch);
  29. curl_close($ch);
  30. var_dump($executed); exit;
  31. }
  32.  
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement