【问题标题】:Google Speech to Text api client return without exception but no actual resultsGoogle Speech to Text api 客户端无异常返回但没有实际结果
【发布时间】:2019-05-28 09:13:51
【问题描述】:

我正在使用来自谷歌网站的示例代码,这不会引发异常,但不会返回任何结果。

如果我使用 API 资源管理器,相同的数据就可以正常工作。我尝试了不同的文件(全部来自谷歌示例代码)不同的设置。所有这些都给了我相同的结果,什么都没有。

function transcribe_sync($content)
{
    // set string as audio content
    $audio = (new RecognitionAudio())
        ->setContent($content);
    // set config
    $encoding = AudioEncoding::LINEAR16;
    $sampleRateHertz = 32000;
    $languageCode = 'en-US';
    $config = (new RecognitionConfig())
        ->setEncoding($encoding)
        ->setSampleRateHertz($sampleRateHertz)
        ->setAudioChannelCount(1)
        ->setMaxAlternatives(1)
        ->setLanguageCode($languageCode);

    // create the speech client
    $client = new SpeechClient();
    try {
        $response = $client->recognize($config, $audio);
        echo $response->getResults()
    }
    catch (\Exception $e) {

        $this->handleError('Error determining recognition. ' . $e->getMessage());
    }
    finally {
        $client->close();
    }

【问题讨论】:

  • 你解决了这个问题吗?我也有同样的问题,只是在 Java 中。

标签: php speech-recognition google-api-client


【解决方案1】:

我对这个问题的解决方案是我传递文件的方式(不要认为文件被正确填充或根本没有填充)。奇怪的是我没有收到错误。由于我的音频文件的长度,我最终集成了谷歌存储来上传文件()并使用:

$audio = (new RecognitionAudio())->setUri("gs://...");
... longRunningRecognize($config, $audio);

希望这对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多