Let’s translate the CURL:
curl
: Starts the CURL.
-k
: Set to unsafe mode, not checking SSL.
-H "Authorization: Bearer TOKEN_DE_ACESSO"
Sets the header of Authorization
with the value of Bearer TOKEN_DE_ACESSO
.
-H "Accept-language: pt-BR"
: Sets the header of Accept-language
with value of pt-BR
"https://txttovoice.org/v/tts?v=1.1&text=Hello+world"
: Define the website you want to connect to.
-o arquivo.wav
: Sets the output location of the result.
Now let’s port this to PHP in the same order:
// Inicia o CURL:
$ch = curl_init();
// Adiciona as opções:
curl_setopt_array($ch, [
// Modo inseguro:
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
// Adiciona os cabeçalhos:
CURLOPT_HTTPHEADER => [
'Authorization: Bearer TOKEN_DE_ACESSO',
'Accept-language: pt-BR',
],
// Define o URL para se conectar:
CURLOPT_URL => 'https://txttovoice.org/v/tts?v=1.1&text=Hello+world',
// Saída:
CURLOPT_RETURNTRANSFER => true
]);
// Executa:
$resultado = curl_exec($ch);
// Encerra CURL:
curl_close($ch);
The variable $resultado
will have the result returned by the website, so if you want to save somewhere use the file_put_contents()
.
file_put_contents('nome_arquivo.formato', $resultado);
This is one of the easiest ways, but there may be problems related to memory and so can treat the storage directly in the CURL, which will fix the problem.
For this the solution is to use the CURLOPT_FILE
, which will basically do exactly what the -o
ago.
$escreverArquivo = fopen('nome_arquivo.formato', 'w+');
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer TOKEN_DE_ACESSO',
'Accept-language: pt-BR',
],
CURLOPT_URL => 'https://txttovoice.org/v/tts?v=1.1&text=Hello+world',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FILE => $escreverArquivo
]);
curl_exec($ch);
curl_close($ch);
fclose($escreverArquivo);
Remember that the TOKEN_DE_ACESSO
must be the token
, which is usually obtained in a previous request, in the case of Oauth, for example. This must be mentioned in the API documentation, but this was not mentioned in the question so you could answer.
This link It’s not the chewed solution, but it might get you in the way. You make the request by Curl and you can save the reply to a file or process the content of the request response however you want.
– Edson Horacio Junior
you try to thank
– Jasar Orion