File size: 676 Bytes
b9970ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai
import os
import time
import logging
from dotenv import load_dotenv

# Load the .env file
load_dotenv()

openai.api_key = os.getenv("OPENAI_API_KEY")

class AutomaticSpeechRecognition():
    """
    Class for automatic speech recognition(ASR).

    This class uses faster whisper model for low latency ASR

    Args:
        model_size: size of model (small, base, etc.)
    """
    def __init__(self):
        pass

    def run_transcription(self, filepath):
        audio_file= open(filepath, "rb")
        sentence = openai.Audio.transcribe("whisper-1", audio_file)
        
        logging.debug(f'transcription: {sentence}')
        
        return sentence