gpt4 book ai didi

php - 我可以从 php 库中将 Google 的语音转为文本转录为 JSON 的完整结果吗?

转载 作者:行者123 更新时间:2023-12-05 04:02:10 26 4
gpt4 key购买 nike

我正在使用谷歌的 php api ( https://github.com/googleapis/google-cloud-php ) 进行语音到文本的转录,到目前为止一切正常。然而;所有使用 php 库的示例都显示了这样处理的结果:

if ($op->operationSucceeded()) {
$response = $op->getResult();

// each result is for a consecutive portion of the audio. iterate
// through them to get the transcripts for the entire audio file.
foreach ($response->getResults() as $result) {
$alternatives = $result->getAlternatives();
$mostLikely = $alternatives[0];
$transcript = $mostLikely->getTranscript();
$confidence = $mostLikely->getConfidence();
printf('Transcript: %s' . PHP_EOL, $transcript);
printf('Confidence: %s' . PHP_EOL, $confidence);
}
}

我真的很喜欢 json 格式的完整结果,这样我就可以轻松地将其存储在数据库表中。有没有办法将完整的结果作为 json 返回?

谢谢!

最佳答案

您可以对从 Google\Protobuf\Internal\Message 继承的任何对象调用 serializeToJsonString()。确保您使用的是相对较新的 google/cloud 版本。

此外,如果您只使用 Cloud Speech,google/cloud-speech可能会更好,因为它会安装一个小得多的包。

关于php - 我可以从 php 库中将 Google 的语音转为文本转录为 JSON 的完整结果吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54678895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com