"""Probe a running deployment with real inference; never sends to a caption relay. Requires dev environment dependencies. --spanish accepts a supplied test WAV. """ import argparse import json import os from pathlib import Path import urllib.request from faster_whisper.audio import decode_audio import numpy as np parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--url', default='http://127.0.0.1:8765') parser.add_argument('--spanish', type=Path) parser.add_argument('--output', type=Path) args = parser.parse_args() base = args.url.rstrip('/') def request(path, audio=None): req = urllib.request.Request(base+path, data=audio, headers={ 'Content-Type':'application/octet-stream', 'X-Caption-Local':'1', **({'Authorization':'Bearer '+os.environ['CAPTION_API_KEY']} if os.environ.get('CAPTION_API_KEY') else {})}) with urllib.request.urlopen(req, timeout=120) as response: return json.load(response) health = request('/health') assert health['ready'] root = Path(__file__).resolve().parents[1] fixture = root / 'samples/jfk.wav' fixture.parent.mkdir(exist_ok=True) if not fixture.exists(): urllib.request.urlretrieve('https://raw.githubusercontent.com/ggml-org/whisper.cpp/master/samples/jfk.wav', fixture) audio = decode_audio(str(fixture), sampling_rate=16000).astype('