|
|
|
|
|
|
|
|
import requests |
|
|
from config import HUGGINGFACE_API_KEY, HUGGINGFACE_STT_MODEL_ID |
|
|
|
|
|
def transcribe_audio(file_bytes: bytes) -> str: |
|
|
""" |
|
|
Convert audio bytes into English text using Whisper large-v3 |
|
|
through Hugging Face Inference API. |
|
|
""" |
|
|
headers = { |
|
|
"Authorization": f"Bearer {HUGGINGFACE_API_KEY}", |
|
|
"Content-Type": "application/octet-stream", |
|
|
} |
|
|
|
|
|
url = f"https://api-inference.huggingface.co/models/{HUGGINGFACE_STT_MODEL_ID}" |
|
|
|
|
|
response = requests.post(url, headers=headers, data=file_bytes) |
|
|
|
|
|
try: |
|
|
result = response.json() |
|
|
return result.get("text", "Error: No transcription returned.") |
|
|
except Exception: |
|
|
return "Error: Invalid response from STT model." |
|
|
|