我正在使用IBM的演讲来使用此端点发送无会话api - “https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_NarrowbandModel”;并上传用于转录为文本的flac文件,但是使用此消息“无法转码数据流音频/ flac - > audio / x-float-array”获得错误400。请让我知道我哪里出错。
答案 0 :(得分:1)
我看了一下您与我们分享的代码,并修复了一些问题。问题与Watson STT服务没有关系,但是你在php中访问和推送音频字节的方式,这是工作版本:
<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;
}
?>