()
| 81 | |
| 82 | |
| 83 | def main() -> int: |
| 84 | parser = argparse.ArgumentParser(description="Smoke test the FunASR OpenAI-compatible API") |
| 85 | parser.add_argument("audio_path", nargs="?", default="sample.wav", help="Audio file to transcribe; downloads a sample if missing") |
| 86 | parser.add_argument("--base-url", default=os.getenv("BASE_URL", "http://localhost:8000"), help="FunASR API base URL") |
| 87 | parser.add_argument("--model", default=os.getenv("MODEL", "sensevoice"), help="Model alias to use") |
| 88 | parser.add_argument("--response-format", default=os.getenv("RESPONSE_FORMAT", "verbose_json"), choices=["json", "verbose_json"], help="Transcription response format") |
| 89 | parser.add_argument("--sample-url", default=os.getenv("SAMPLE_URL", SAMPLE_URL), help="Sample audio URL used when audio_path does not exist") |
| 90 | parser.add_argument("--timeout", type=float, default=float(os.getenv("TIMEOUT", "300")), help="HTTP timeout in seconds") |
| 91 | args = parser.parse_args() |
| 92 | |
| 93 | base_url = args.base_url.rstrip("/") |
| 94 | audio_path = Path(args.audio_path) |
| 95 | |
| 96 | try: |
| 97 | download_if_needed(audio_path, args.sample_url, args.timeout) |
| 98 | print_json("health", request_json(f"{base_url}/health", args.timeout)) |
| 99 | print_json("models", request_json(f"{base_url}/v1/models", args.timeout)) |
| 100 | print(f"\nTranscribing {audio_path} with model={args.model}, response_format={args.response_format}") |
| 101 | print_json("transcription", transcribe(base_url, audio_path, args.model, args.response_format, args.timeout)) |
| 102 | except urllib.error.HTTPError as error: |
| 103 | detail = error.read().decode("utf-8", errors="replace") |
| 104 | print(f"HTTP {error.code} from {error.url}: {detail}", file=sys.stderr) |
| 105 | return 1 |
| 106 | except Exception as error: |
| 107 | print(f"Smoke test failed: {error}", file=sys.stderr) |
| 108 | return 1 |
| 109 | return 0 |
| 110 | |
| 111 | |
| 112 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…