【问题标题】:What is the correct URL for Google's Cloud Speech API internet requests and how to request using java?Google Cloud Speech API 互联网请求的正确 URL 是什么以及如何使用 java 请求?
【发布时间】:2018-11-04 09:24:55
【问题描述】:

我只是使用 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;

}

picture of my key settings

【问题讨论】:

标签: java api key google-cloud-speech


【解决方案1】:

这个 API 端点版本似乎只提供给 Chromium 项目 的社区开发者;但是,如this documentation 中所述,不可能获得额外配额。

相反,需要使用官方的v1v1p1beta1 端点来执行语音识别任务。此外,我建议您查看 Client Libraries 指南,以获取有关使用编程语言(包括 Java)使用 Speech-to-Text API 服务的过程的详细信息。 p>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-07
    • 2012-10-04
    • 2020-04-30
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    相关资源
    最近更新 更多