1

I have the following code:

$transcribe1 = exec('"C:\path\to\gcloud\gcloud.cmd" ml speech recognize "audio-file.flac" --language-code="en-GB"', $transcribe2);
echo '<pre>'; print_r($transcribe1); echo '</pre>';
echo '<pre>'; print_r($transcribe2); echo '</pre>';
$transcribeArray = json_decode($transcribe1, true);
echo '<pre>'; print_r($transcribeArray); echo '</pre>';

The result is:

Array
(
    [0] => {
    [1] =>   "results": [
    [2] =>     {
    [3] =>       "alternatives": [
    [4] =>         {
    [5] =>           "confidence": 0.880379,
    [6] =>           "transcript": "the text returned from google cloud"
    [7] =>         }
    [8] =>       ]
    [9] =>     }
    [10] =>   ]
    [11] => }
)

The first two print_rs return empty.

All I'm trying to do is get the json returned from gCloud into an array so I can reference it properly in the rest of the code. In other words, an array that looks like this:

[results] => Array(
  [alternatives] => Array(
    [confidence] => "0.880379",
    [transcript] => "the text returned from google cloud"
  );
);

What am I missing?

1 Answer 1

1

Figured this out with more StackOverflow searching.

exec returns a whole array of stuff it does

shell_exec returns only the result of the execution, in its original format.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.