Created
January 16, 2023 06:55
-
-
Save ankushagarwal/c84a2e26e7980374dcd3b2997c3357e6 to your computer and use it in GitHub Desktop.
Revisions
-
ankushagarwal created this gist
Jan 16, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import requests from requests_toolbelt import MultipartEncoder import os, random, string # Some basics req_url = "https://api.openai.com/v1/engines/audio-transcribe-001/transcriptions" openai_key = 'OPEN_AI_KEY_GOES_HERE' # Load file as bytes and add it as a form field file_path = "test.mp3" file = open(file_path, "rb").read() form_fields = { 'file': (file_path, file, 'audio/mpeg'), } # Encode our fake form boundary = '--WebKitFormBoundary' + ''.join(random.sample(string.ascii_letters + string.digits, 16)) m = MultipartEncoder (fields=form_fields, boundary=boundary) # Send the request to OpenAI response = requests.post( req_url, headers={ "Authorization": f"Bearer {openai_key}", "Content-Type": m.content_type }, data=m ) # Et voila! print(response.json())