You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
procedure TranscreverAudio(const ApiKey, AudioFilePath: string);
var
Http : TIdHTTP;
SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
Request : TIdMultipartFormDataStream;
Response : TStringStream;
begin
Http := TIdHTTP.Create(nil);
SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
Request := TIdMultipartFormDataStream.Create;
Response := TStringStream.Create;
try
if FileExists(AudioFilePath) then
ShowMessage('Arquivo existe')
else
ShowMessage('Arquivo nao existe');
// Configuração do SSL Handler para suportar TLS 1.2
SSLHandler.SSLOptions.Method := sslvTLSv1_2;
SSLHandler.SSLOptions.SSLVersions := [sslvTLSv1_2];
Http.IOHandler := SSLHandler;
// Configuração do cabeçalho com o token da API
Http.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + ApiKey;
// Adicionando o arquivo de áudio (MP3) e o modelo ao corpo da requisição
Request.AddFile('file', AudioFilePath, 'audio/mpeg'); // Para arquivos MP3, o tipo MIME é 'audio/mpeg'
Request.AddFormField('model', 'whisper-1'); // Usando o modelo Whisper para transcrição
// Enviar a requisição POST para a API da OpenAI
Http.Post('https://api.openai.com/v1/audio/transcriptions', Request, Response);
// Exibir a resposta (transcrição) no console
Writeln('Resposta da Transcrição: ' + Response.DataString);
except
on E: Exception do
Writeln('Erro ao transcrever o áudio: ' + E.Message);
end;
// Liberar os objetos usados
Request.Free;
Response.Free;
SSLHandler.Free;
Http.Free;
end;
The text was updated successfully, but these errors were encountered:
Uses
IdHTTP,
IdSSLOpenSSL,
IdGlobal,
IdMultipartFormData;
procedure TranscreverAudio(const ApiKey, AudioFilePath: string);
var
Http : TIdHTTP;
SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
Request : TIdMultipartFormDataStream;
Response : TStringStream;
begin
Http := TIdHTTP.Create(nil);
SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
Request := TIdMultipartFormDataStream.Create;
Response := TStringStream.Create;
try
if FileExists(AudioFilePath) then
ShowMessage('Arquivo existe')
else
ShowMessage('Arquivo nao existe');
except
on E: Exception do
Writeln('Erro ao transcrever o áudio: ' + E.Message);
end;
// Liberar os objetos usados
Request.Free;
Response.Free;
SSLHandler.Free;
Http.Free;
end;
The text was updated successfully, but these errors were encountered: