Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form method="post" name="post_form" action="conversion.php" enctype="multipart/form-data">
- <input type="file" name="voice">
- <input type="submit" name="btnUpload" value="submit">
- </form>
- <?php
- if($_POST['btnUpload']) {
- $username = "username";
- $password = "password";
- $url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?continuous=true&model=en-US_NarrowbandModel';
- $filename = $_FILES['voice']['name'];
- $filedata = $_FILES['voice']['tmp_name'];
- $file = fopen($filename, 'r');
- $filesize = filesize($filename);
- $bytes = fread($file,$filesize);
- $data = array('part_content_type' => 'audio/flac');
- $headers = array("Content-Type: audio/flac", "Transfer-Encoding: chunked");
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $bytes);
- curl_setopt($ch, CURLOPT_INFILESIZE, $filesize);
- curl_setopt($ch, CURLOPT_VERBOSE, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $executed = curl_exec($ch);
- curl_close($ch);
- var_dump($executed); exit;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement