Spaces:
Sleeping
Sleeping
| 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 | |