48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
import requests
|
|
import sys
|
|
import os
|
|
|
|
# ---- Config ----
|
|
LMSTUDIO_URL = "http://172.22.22.210:1234/v1"
|
|
AUDIO_FILE = "/Users/despiegk/Downloads/harvard.wav" # change to your input file
|
|
|
|
# ---- Step 1: List available models ----
|
|
models_resp = requests.get(f"{LMSTUDIO_URL}/models")
|
|
models_resp.raise_for_status()
|
|
models = [m["id"] for m in models_resp.json().get("data", [])]
|
|
|
|
print("Available models:", models)
|
|
|
|
# ---- Step 2: Find Whisper ----
|
|
whisper_model = None
|
|
for m in models:
|
|
if "whisper" in m.lower():
|
|
whisper_model = m
|
|
break
|
|
|
|
if not whisper_model:
|
|
print("❌ No Whisper model found in LM Studio. Please download/start one.")
|
|
sys.exit(1)
|
|
|
|
print(f"✅ Found Whisper model: {whisper_model}")
|
|
|
|
# ---- Step 3: Transcribe ----
|
|
if not os.path.exists(AUDIO_FILE):
|
|
print(f"❌ Audio file '{AUDIO_FILE}' not found.")
|
|
sys.exit(1)
|
|
|
|
with open(AUDIO_FILE, "rb") as f:
|
|
files = {"file": f}
|
|
data = {"model": whisper_model}
|
|
headers = {"Authorization": "Bearer no-key"} # LM Studio ignores key
|
|
resp = requests.post(f"{LMSTUDIO_URL}/audio/transcriptions",
|
|
headers=headers,
|
|
files=files,
|
|
data=data)
|
|
resp.raise_for_status()
|
|
result = resp.json()
|
|
|
|
print("📝 Transcription result:")
|
|
print(result.get("text", result))
|