File size: 885 Bytes
f103f44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import os
import io
from groq import Groq
import soundfile as sf
from deepgram import DeepgramClient, SpeakOptions
from langchain_groq import ChatGroq
from dotenv import load_dotenv

load_dotenv('.env')


# Text to Speech and Speech to Text
class Speech_Text():
    def __init__(self):
        self.client = Groq(api_key=os.getenv("GROQ_API_KEY"))
        
    # Function to get transcript from audio
    def get_transcript(self,audio):
        audio_buffer = io.BytesIO()
        sf.write(audio_buffer, audio[1], samplerate=audio[0], format="MP3")
        audio_buffer.seek(0)
        translation = self.client.audio.transcriptions.create(
            file=("audio.mp3", audio_buffer.read()),
            model="distil-whisper-large-v3-en",
            response_format="json",
            temperature=0.0,
        )
        return translation.text