(base_url: str, audio_path: Path, model: str, response_format: str, timeout: float)
| 60 | |
| 61 | |
| 62 | def transcribe(base_url: str, audio_path: Path, model: str, response_format: str, timeout: float) -> dict: |
| 63 | body, boundary = multipart_body(audio_path, model, response_format) |
| 64 | request = urllib.request.Request( |
| 65 | f"{base_url}/v1/audio/transcriptions", |
| 66 | data=body, |
| 67 | method="POST", |
| 68 | headers={ |
| 69 | "Accept": "application/json", |
| 70 | "Content-Type": f"multipart/form-data; boundary={boundary}", |
| 71 | "Content-Length": str(len(body)), |
| 72 | }, |
| 73 | ) |
| 74 | with urllib.request.urlopen(request, timeout=timeout) as response: |
| 75 | return json.loads(response.read().decode("utf-8")) |
| 76 | |
| 77 | |
| 78 | def print_json(title: str, payload: dict) -> None: |
no test coverage detected
searching dependent graphs…