结果为数组时从php exec()获取数组

时间:2018-08-18 10:53:26

标签: php arrays exec gcloud

我有以下代码:

Singleton

结果是:

$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>';

前两个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] => } ) 返回空。

我要做的就是将gCloud返回的json放入数组中,以便在其余代码中正确引用它。换句话说,看起来像这样的数组:

print_r

我想念什么?

1 个答案:

答案 0 :(得分:1)

通过更多StackOverflow搜索解决了这一问题。

exec返回它所做的所有事情

shell_exec仅以原始格式返回执行结果。