JAVA 使用谷歌语音识别 API

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16743533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 23:50:43  来源:igfitidea点击:

JAVA using google speech recognition API

javaapispeech

提问by seicaratteri

I'm trying to use google speech recognition API. Here's the code i've written:

我正在尝试使用谷歌语音识别 API。这是我写的代码:

http://pastebin.com/zJEhnJ74

http://pastebin.com/zJEhnJ74

It works. I get an answer from the server:

有用。我从服务器得到答复:

{"status":5,"id":"8803471b14a2310dfcf917754e8bd4a7-1","hypotheses":[]}

Now the problem is "status:5". Infact, here's status code:

现在的问题是“状态:5”。事实上,这是状态代码:

status: 0 – correct?, status: 4 – missing audio file, ?status: 5 – incorrect audio file.

My problem is "incorrect audio file". I don't understand if it is a .flac file error (you can download my test .flac file here: http://www21.zippyshare.com/v/61888405/file.html) or how i read the file (in a byte array then convert it into string)

我的问题是“音频文件不正确”。我不明白这是 .flac 文件错误(您可以在此处下载我的测试 .flac 文件:http://www21.zippyshare.com/v/61888405/file.html )或我如何读取文件(在一个字节数组,然后将其转换为字符串)

Thanks for help! and sorry for my bad english

感谢帮助!很抱歉我的英语不好

采纳答案by Jarandinor

You must use wr.write(data);instead of wr.writeBytes(new String(data));

您必须使用wr.write(data);代替wr.writeBytes(new String(data));

Google answer:

谷歌回答:

{"status":0,"id":"e0f4ced346ad18bbb81756ed4d639164-1","hypotheses":[{"utterance":"hello how are you","confidence":0.94028234},{"utterance":"hello how r you"},{"utterance":"hello how are u"},{"utterance":"hello how are you in"}]}