import requests import json import soundfile as sf import numpy as np import os # Test the API connection API_URL = "http://localhost:5000/batch_confirm" def test_api(): print("Testing API connection...") try: response = requests.get("http://localhost:5000/") print(f"API health check: {response.status_code}") print(f"Response: {response.json()}") except Exception as e: print(f"API not reachable: {e}") return False return True def test_batch_confirm(): print("\nTesting batch confirm...") # Create a simple test audio file test_audio = np.random.randn(16000).astype(np.float32) # 1 second of noise test_path = "test_audio.flac" sf.write(test_path, test_audio, 16000, format="FLAC") # Test batch confirm with open(test_path, "rb") as f: files = {"audio0": f} data = {"references": json.dumps(["test sentence"])} try: response = requests.post(API_URL, files=files, data=data, timeout=30) print(f"Batch confirm response: {response.status_code}") if response.status_code == 200: print(f"Response JSON: {response.json()}") else: print(f"Error: {response.text}") except Exception as e: print(f"Batch confirm failed: {e}") # Clean up if os.path.exists(test_path): os.remove(test_path) if __name__ == "__main__": if test_api(): test_batch_confirm() else: print("Please start the Vosk API first!")