#!/usr/bin/env python3 """ Test script for audio roleplay API """ import requests import json import base64 # API configuration API_BASE_URL = "http://localhost:8000" # API_BASE_URL = "https://abao77-run-code-api.hf.space" def test_text_message(): """Test sending text message only""" print("Testing text message...") scenario = { "scenario_title": "Restaurant Order", "scenario_description": "Order food at a restaurant", "scenario_context": "You are at a restaurant and want to order food", "your_role": "Customer", "key_vocabulary": ["menu", "order", "bill", "table"] } data = { "session_id": "test-session-123", "scenario": json.dumps(scenario), "text_message": "Hello, I'd like to see the menu please." } try: response = requests.post(f"{API_BASE_URL}/api/ai/roleplay", data=data) if response.ok: result = response.json() print("✅ Text message test successful!") print(f"Response: {result.get('response', 'No response')}") else: print(f"❌ Text message test failed: {response.status_code}") print(f"Error: {response.text}") except Exception as e: print(f"❌ Text message test error: {e}") def test_audio_message(): """Test sending audio file""" print("\nTesting audio message...") scenario = { "scenario_title": "Restaurant Order", "scenario_description": "Order food at a restaurant", "scenario_context": "You are at a restaurant and want to order food", "your_role": "Customer", "key_vocabulary": ["menu", "order", "bill", "table"] } # Create a dummy audio file (in real scenario, this would be actual audio) dummy_audio_data = b"fake_audio_data_for_testing" data = { "session_id": "test-session-456", "scenario": json.dumps(scenario) } files = { "audio_file": ("test_audio.wav", dummy_audio_data, "audio/wav") } try: response = requests.post(f"{API_BASE_URL}/api/ai/roleplay", data=data, files=files) if response.ok: result = response.json() print("✅ Audio message test successful!") print(f"Response: {result.get('response', 'No response')}") else: print(f"❌ Audio message test failed: {response.status_code}") print(f"Error: {response.text}") except Exception as e: print(f"❌ Audio message test error: {e}") def test_combined_message(): """Test sending both text and audio""" print("\nTesting combined text + audio message...") scenario = { "scenario_title": "Restaurant Order", "scenario_description": "Order food at a restaurant", "scenario_context": "You are at a restaurant and want to order food", "your_role": "Customer", "key_vocabulary": ["menu", "order", "bill", "table"] } dummy_audio_data = b"fake_audio_data_for_testing" data = { "session_id": "test-session-789", "scenario": json.dumps(scenario), "text_message": "I have a question about the menu" } files = { "audio_file": ("question.wav", dummy_audio_data, "audio/wav") } try: response = requests.post(f"{API_BASE_URL}/api/ai/roleplay", data=data, files=files) if response.ok: result = response.json() print("✅ Combined message test successful!") print(f"Response: {result.get('response', 'No response')}") else: print(f"❌ Combined message test failed: {response.status_code}") print(f"Error: {response.text}") except Exception as e: print(f"❌ Combined message test error: {e}") if __name__ == "__main__": print("🧪 Testing Audio Roleplay API") print("=" * 50) test_text_message() test_audio_message() test_combined_message() print("\n" + "=" * 50) print("🏁 Testing completed!")