【问题标题】:Why is Google Speech API getting timeout为什么 Google Speech API 会超时
【发布时间】:2018-01-22 08:13:45
【问题描述】:

我正在开发一个包含音频到文本页面的网站,我正在尝试使用来自 Google 的 API,但它似乎无限加载并给我一个超时,在 Google 控制台上它向我显示已发出请求所以我猜它来自我的渲染(我正在 Symfony 上开发)

这是我的功能

public function transcribeAction($audioFile = 'C:\Users\Poste3\Downloads\rec.flac', $languageCode = 'fr-FR', $options = ['sampleRateHertz' => 16000, 'speechContexts' => ['phrases' => ['The Google Cloud Platform', 'Speech API']]])
{

    // Create the speech client
    $speech = new SpeechClient([
        'keyFilePath' => 'C:\Users\Poste3\Downloads\Speech-74da45e82b8e.json',
        'languageCode' => $languageCode,
    ]);

    // Make the API call
    $results = $speech->recognize(
        fopen($audioFile, 'r'),
        $options
    );

    // Print the results
    foreach ($results as $result) {
        $alternative = $result->alternatives()[0];
        printf('Transcript: %s' . PHP_EOL, $alternative['transcript']);
        printf('Confidence: %s' . PHP_EOL, $alternative['confidence']);
    }

    return $this->render('OCPlatformBundle:Advert:speech.html.twig');
}

这是对函数的调用

{{ render(controller('OCPlatformBundle:Advert:transcribe')) }}

【问题讨论】:

    标签: php symfony google-speech-api


    【解决方案1】:

    首先,您应该转储您从 Speech API 获得的响应。

    这里可能出现的问题:

    • 密钥配置不正确,无权进行此操作
    • 您的文件时长超过 1 分钟,在这种情况下 google Speech 要求您先将 .flac 文件上传到 Google Cloud 并使用 longrunningrecognize

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-07
      • 2018-04-25
      • 2019-08-14
      相关资源
      最近更新 更多