Spaces:
Sleeping
Sleeping
File size: 1,088 Bytes
f41beca 88e38f4 f41beca 88e38f4 f41beca 88e38f4 f41beca 88e38f4 f41beca 88e38f4 f41beca 88e38f4 |
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 |
import logging
from groq import Groq
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
stt_model = "whisper-large-v3"
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def transcribe_audio(file_path):
"""
Transcribe audio to text using Groq Whisper.
:param file_path: Path to the audio file.
:return: Transcribed text.
"""
try:
with open(file_path, "rb") as audio_file:
audio_data = audio_file.read()
logging.info("Transcribing audio...")
groq = Groq(api_key=GROQ_API_KEY)
response = groq.audio.transcriptions.create(
model=stt_model,
file=audio_data,
language="en",
response_format="text"
)
logging.info("Audio transcription complete.")
return response
except Exception as e:
logging.error(f"Error transcribing audio: {e}")
return "Transcription failed. Check logs."
|