【发布时间】:2019-02-13 20:28:51
【问题描述】:
我正在使用 google 的 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 形式返回的完整结果?
谢谢!
【问题讨论】:
-
火箭科学家不需要将您拥有的内容转换为 JSON
-
点赞
foreach ($response->getResults() as $result) { $json[] = $result; } $theJson = json_encode($json); -
当然不是,但真的,为什么要重新发明轮子,那里(可能)有一个函数调用会返回这个。此外,这些结果非常深,导致大量结构化数组转换为 json。
-
那么它应该在手册中,如果不是他们可能没有
标签: php google-cloud-platform google-speech-api