File size: 876 Bytes
d7fd1be
69601d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from ..utils.functions import getConfig
from ..utils.exceptions import CustomException
from ..utils.logger import logger
from groq import Groq
import os

class SpeechToText:
    def __init__(self):
        logger.info("Initializing speech-to-text Model.")
        self.config = getConfig(os.path.join(os.getcwd(), "config.ini"))
        self.client = Groq()

    def getTranscript(self, b64String = str) -> str:
        try:
            logger.info("generating transcript.")
            transcription = self.client.audio.transcriptions.create(
                url = f'data:audio/webm;base64,{b64String}',
                model = self.config.get("SPEECHTOTEXT", "model")
            )
            return transcription.text.strip()
        except Exception as e:
            logger.error(f"Error constructing metadata generation chain: {e}")
            raise CustomException(e)