Google的Cloud Speech API互联网请求的正确URL是什么以及如何使用Java请求?



我只是使用Eclipse IDE和Java尝试通过麦克风收集语音备忘录,然后将音频实时转换为文本。我不确定我做得是否正确,但如果我发送这个URL,编译器会给我一个403错误,这意味着它不接受我粘贴到URL上的密钥。所以我的问题是:有人知道为什么URL连接不占用我的密钥吗?或者我应该使用哪个应用程序限制而不是NONE?

public class Recognizer {
/**
* URL to POST audio data and retrieve results
*/
private static final 
String GOOGLE_RECOGNIZER_URL_NO_LANG 
= "http://www.google.com/speech-api/v2/recognize?lang=en- 
us&key=InsertMyKey&output=json";
. . . 
. . . 
. . . 
private String rawRequest(byte[] bytes, String language) throws Exception {
System.out.println("in this second construct" );
URL url;
URLConnection urlConn;
OutputStream outputStream;
BufferedReader br;
// URL of Remote Script.
url = new URL(GOOGLE_RECOGNIZER_URL_NO_LANG);
// Open New URL connection channel.
urlConn = url.openConnection();
// we want to do output.
urlConn.setDoOutput(true);
// No caching
urlConn.setUseCaches(false);
// Specify the header content type.
urlConn.setRequestProperty("Content-Type", "audio/x-flac; rate=8000");
// Send POST output.
outputStream = urlConn.getOutputStream();
outputStream.write(bytes);
outputStream.close();
// Get response data.
br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String response = br.readLine();
br.close();
return response;
}

我的密钥设置的图片

此API端点版本似乎仅为Chromium项目的社区开发人员提供;但是,NOT有可能获得额外的配额,如本文档中所述。

相反,它需要使用官方的v1或v1p1beta1端点来执行语音识别任务。此外,我建议您参阅客户端库指南,以便获得有关使用编程语言(包括Java(使用Speech-to-Textneneneba API服务的过程的详细信息。

最新更新