dqoeghe9452 2016-09-27 20:11
浏览 96
已采纳

Google Speech API“请求中的采样率与FLAC标头不匹配”

I'm trying to convert an mp4 video clip into a FLAC audio file and then have google speech spit out the words from the video so that I can detect if specific words were said.

I have everything working except that I am getting an error from the Speech API:

{
  "error": {
    "code": 400,
    "message": "Sample rate in request does not match FLAC header.",
    "status": "INVALID_ARGUMENT"
  }
}

I am using FFMPEG in order to convert the mp4 into a FLAC file. I am specifying that the FLAC file be 16 bits in the command, but when I right click on the FLAC file Windows is telling me it is 302kbps.

Here is my PHP code:

// convert mp4 video to 16 bit flac audio file
$cmd = 'C:/wamp/www/ffmpeg/bin/ffmpeg.exe -i C:/wamp/www/test.mp4 -c:a flac -sample_fmt s16 C:/wamp/www/test.flac';
exec($cmd, $output);

// convert flac to text so we can detect if certain words were said
$data = array(
    "config" => array(
        "encoding" => "FLAC",
        "sampleRate" => 16000,
        "languageCode" => "en-US"
    ),
    "audio" => array(
        "content" => base64_encode(file_get_contents("test.flac")),
    )
);

$json_data = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=MY_API_KEY');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);

展开全部

  • 写回答

2条回答 默认 最新

  • dongshushi5579 2016-09-27 20:25
    关注

    Fixed it by being very specific in my FFMPEG command:

    $cmd = 'C:/wamp/www/ffmpeg/bin/ffmpeg.exe -i C:/wamp/www/test.mp4 -acodec flac -bits_per_raw_sample 16 -ar 44100 -ac 1 C:/wamp/www/test.flac';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥50 智能家庭防盗系统设计
  • ¥20 MC9S12XS128单片机开发板实验,
  • ¥15 C#多线程假死或卡死问题
  • ¥15 关于#tcp/ip#的问题:苹果电脑M1,easyconnect登录成功,显示虚拟 IP 地址
  • ¥15 客户端发现不了OPC服务器
  • ¥500 寻找华为新款路由器开telnet方法
  • ¥20 运行pointnerf模型遇到了pycuda的错误,如何解决?(相关搜索:测试代码|自动驾驶|数据集)
  • ¥15 失败的github程序安装
  • ¥15 WSL上下载的joern在windows怎么用?
  • ¥15 jetson nano4GB
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部