0; $retries--) { echo "sending voicemail recording to ".$api_url." for transcription"; // submit the file for transcribing $file_path = $file_path.'/'.$file_name; $command = "curl -sX POST ".$api_url."/enqueue -H 'Authorization: Bearer ".$api_key."' -F file=@".$file_path; $stdout = shell_exec($command); $resp = json_decode($stdout, true); if ($resp === null) { echo "unexpected error: ".$stdout; // json not parsable, try again continue; } $transcription_id = $resp['id']; // wait for transcription to complete sleep(1); while(true) { echo "checking ".$api_url." for completion of job ".$transcription_id; $command = "curl -s ".$api_url."/j/".$transcription_id." -H 'Authorization: Bearer ".$api_key."'"; $resp = json_decode(shell_exec($command), true); if ($resp === null) { // json not parsable, try again continue; } if($resp['status'] == "failed") { echo "transcription failed, retrying"; break; } if($resp['status'] == "finished") { echo "transcription succeeded"; $message = $resp['result']; break; } // transcription is queued or in progress, check again in 1 second sleep(1); } if($message !== null) { break; } } if($message == null) { return false; } $array['provider'] = $transcribe_provider; $array['language'] = $transcribe_language; $array['api_key'] = $api_key; // $array['command'] = $command $array['message'] = $message; return $array; } } } ?>