我有以下代码:
$transcribe1 = exec('"C:pathtogcloudgcloud.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] => }
)
前两个print_r
返回空。
我要做的就是将从 gCloud 返回的 json 放入一个数组中,以便我可以在其余代码中正确引用它。换句话说,一个看起来像这样的数组:
[results] => Array(
[alternatives] => Array(
[confidence] => "0.880379",
[transcript] => "the text returned from google cloud"
);
);
我错过了什么?
通过更多的 StackOverflow 搜索解决了这个问题。
exec
返回它所做的一整套东西
shell_exec
仅以原始格式返回执行结果。