Reputation: 571
I'm using google's php api (https://github.com/googleapis/google-cloud-php) for speech to text transcription and am getting everything to work so far. However; all the examples on using the php library show the results being handled like this:
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);
}
}
I would really like the full result as json so I can easily store it in a database table. Is there a way to get the full result returned as json?
Thanks!
Upvotes: 3
Views: 1383
Reputation: 3516
You can call serializeToJsonString()
on any object inheriting from Google\Protobuf\Internal\Message
. Make sure you're using a relatively recent release of google/cloud
.
Additionally, if you're only using Cloud Speech, google/cloud-speech
might be better, as it'll install a much smaller package.
Upvotes: 3