Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consegue implementar Audio Transcription OpenAI? #16

Open
knrocha99 opened this issue Sep 13, 2024 · 1 comment
Open

Consegue implementar Audio Transcription OpenAI? #16

knrocha99 opened this issue Sep 13, 2024 · 1 comment

Comments

@knrocha99
Copy link

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

// 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;

@marcelo386
Copy link

@wlandgraf I found it interesting, this application could check, to have this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants