0

I am using IBM's speech to text sessionless api with this endpoint- "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_NarrowbandModel"; , and uploading flac file for transcribing into text, but getting an error 400 with this message "unable to transcode data stream audio/flac -> audio/x-float-array". Please let me know where Am I getting wrong.

PrashJ
  • 11
  • 3
  • Welcome. Take a moment to read though the Guide: _[ask]_ which has lots of useful information about what should be included with your questions in order to help us help you with this problem. – mike510a Jan 24 '17 at 14:53
  • Possible duplicate of [ffmpeg to convert from flac to wav](http://stackoverflow.com/questions/23333678/ffmpeg-to-convert-from-flac-to-wav) – Nikolay Shmyrev Jan 24 '17 at 15:56

1 Answers1

1

I took a look at the code that you shared with us and I fixed a couple of things. The problem was not really related to the Watson STT service, but the way you were accessing and pushing the audio bytes in php, here is the working version:

<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;
    }

?>
Daniel Bolanos
  • 770
  • 3
  • 6