feat(whatsapp): add voice message transcription via OpenAI/Groq Whisper

Automatically transcribe WhatsApp voice messages using OpenAI Whisper
or Groq. Configurable via transcriptionProvider and transcriptionApiKey.

Config:
  "whatsapp": {
    "transcriptionProvider": "openai",
    "transcriptionApiKey": "sk-..."
  }
This commit is contained in:
comadreja
2026-03-26 21:46:31 -05:00
parent e7d371ec1e
commit db50dd8a77
3 changed files with 51 additions and 10 deletions
+29 -1
View File
@@ -1,8 +1,36 @@
"""Voice transcription provider using Groq."""
"""Voice transcription providers (Groq and OpenAI Whisper)."""
import os
from pathlib import Path
class OpenAITranscriptionProvider:
"""Voice transcription provider using OpenAI's Whisper API."""
def __init__(self, api_key: str | None = None):
self.api_key = api_key or os.environ.get("OPENAI_API_KEY")
self.api_url = "https://api.openai.com/v1/audio/transcriptions"
async def transcribe(self, file_path: str | Path) -> str:
if not self.api_key:
return ""
path = Path(file_path)
if not path.exists():
return ""
try:
import httpx
async with httpx.AsyncClient() as client:
with open(path, "rb") as f:
files = {"file": (path.name, f), "model": (None, "whisper-1")}
headers = {"Authorization": f"Bearer {self.api_key}"}
response = await client.post(
self.api_url, headers=headers, files=files, timeout=60.0,
)
response.raise_for_status()
return response.json().get("text", "")
except Exception:
return ""
import httpx
from loguru import logger