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

编程入门 行业动态 更新时间:2024-10-17 13:36:12
本文介绍了Google Speech API“请求中的采样率与FLAC头部不匹配”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将mp4视频剪辑转换为FLAC音频文件,然后让Google语音从视频中吐出出来,以便我可以检测到是否有特定字词。

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.

我有一切工作,除了我从Speech API收到错误:

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

我正在使用FFMPEG将mp4转换为FLAC文件。我指定FLAC文件在命令中是16位,但是当我右键单击FLAC文件时,Windows告诉我是302kbps。

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.

这是我的PHP代码:

// 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, 'speech.googleapis/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);

推荐答案

通过在我的FFMPEG命令中非常具体地修正:

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

更多推荐

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

本文发布于:2023-11-02 17:05:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552940.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:头部   不匹配   采样率   Speech   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!