import requests import os from openai import OpenAI from dotenv import load_dotenv load_dotenv() client = OpenAI() # API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3" # headers = {"Authorization": f'Bearer {os.environ["HF_ACCESS_TOKEN"]}'} # def audio_transcribe(path): # try: # def query(filename): # with open(filename, "rb") as f: # data = f.read() # response = requests.post(API_URL, headers=headers, data=data) # os.remove(filename) # return response.json() # output = query(path) # return output["text"] # except Exception as e: # print(e) # return False def audio_transcribe(path): try: audio_file= None print(path, "path") audio_file = open(path, "rb") if not audio_file: return False transcription = client.audio.transcriptions.create( model="whisper-1", file=audio_file ) return transcription.text except Exception as e: print(e) return False