File size: 1,118 Bytes
c05b3cb
 
8be6421
c05b3cb
 
 
8be6421
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c05b3cb
 
 
ae85fcc
5705491
 
ae85fcc
8be6421
 
 
 
 
bfca00b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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