Multimodal_AI_Doctor / patient_voice.py
Yanmife's picture
Update patient_voice.py
88e38f4 verified
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."