Spaces:
Sleeping
Sleeping
Peter Michael Gits Claude commited on
Commit Β·
1e03d76
1
Parent(s): fc06bd2
test: Add comprehensive STT service connection testing
Browse files- Created direct STT service test to verify audio processing
- Added WebRTC handler connection test with endpoint discovery
- Identified STT service internal exception requiring verbose errors
- Test scripts help diagnose WebRTC to STT pipeline issues
π€ Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- __pycache__/webrtc_streamlit.cpython-313.pyc +0 -0
- test_stt_direct.py +149 -0
- test_webrtc_connection.py +103 -0
__pycache__/webrtc_streamlit.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/webrtc_streamlit.cpython-313.pyc and b/__pycache__/webrtc_streamlit.cpython-313.pyc differ
|
|
|
test_stt_direct.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Direct STT Service Test
|
| 3 |
+
Test the STT service directly with a real audio file to verify it's receiving and processing data
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import asyncio
|
| 7 |
+
import tempfile
|
| 8 |
+
import wave
|
| 9 |
+
import numpy as np
|
| 10 |
+
import requests
|
| 11 |
+
import logging
|
| 12 |
+
from datetime import datetime
|
| 13 |
+
from mcp_voice_service import mcp_create_test_voice
|
| 14 |
+
|
| 15 |
+
logging.basicConfig(level=logging.INFO)
|
| 16 |
+
logger = logging.getLogger(__name__)
|
| 17 |
+
|
| 18 |
+
class STTDirectTest:
|
| 19 |
+
"""Test STT service directly with audio files"""
|
| 20 |
+
|
| 21 |
+
def __init__(self):
|
| 22 |
+
self.stt_service_url = "https://pgits-stt-gpu-service.hf.space"
|
| 23 |
+
|
| 24 |
+
async def test_stt_service_direct(self):
|
| 25 |
+
"""Test STT service with direct audio file upload"""
|
| 26 |
+
logger.info("π€ Starting direct STT service test")
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
# Step 1: Create test audio file
|
| 30 |
+
logger.info("π Creating test audio file...")
|
| 31 |
+
test_voice_file = await mcp_create_test_voice()
|
| 32 |
+
logger.info(f"β
Test audio file created: {test_voice_file}")
|
| 33 |
+
|
| 34 |
+
# Step 2: Test Gradio API endpoint
|
| 35 |
+
logger.info("π Testing Gradio API endpoint...")
|
| 36 |
+
await self.test_gradio_api(test_voice_file)
|
| 37 |
+
|
| 38 |
+
# Step 3: Test HTTP API endpoint
|
| 39 |
+
logger.info("π Testing HTTP API endpoint...")
|
| 40 |
+
await self.test_http_api(test_voice_file)
|
| 41 |
+
|
| 42 |
+
# Step 4: Verify service is receiving requests
|
| 43 |
+
logger.info("π Checking service status...")
|
| 44 |
+
await self.check_service_status()
|
| 45 |
+
|
| 46 |
+
except Exception as e:
|
| 47 |
+
logger.error(f"β Direct STT test failed: {e}")
|
| 48 |
+
|
| 49 |
+
async def test_gradio_api(self, audio_file_path):
|
| 50 |
+
"""Test STT service via Gradio Client API"""
|
| 51 |
+
try:
|
| 52 |
+
from gradio_client import Client
|
| 53 |
+
|
| 54 |
+
logger.info(f"π‘ Connecting to Gradio API at {self.stt_service_url}")
|
| 55 |
+
client = Client(self.stt_service_url)
|
| 56 |
+
|
| 57 |
+
logger.info(f"π€ Sending audio file to Gradio API...")
|
| 58 |
+
result = client.predict(
|
| 59 |
+
audio_file_path, # audio file path
|
| 60 |
+
"en", # language
|
| 61 |
+
"base", # model_size_param
|
| 62 |
+
api_name="/gradio_transcribe_wrapper"
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
logger.info(f"β
Gradio API response: {result}")
|
| 66 |
+
|
| 67 |
+
# Parse response
|
| 68 |
+
transcription_text, timing_json, status_text = result
|
| 69 |
+
logger.info(f"π Transcription: {transcription_text}")
|
| 70 |
+
logger.info(f"β±οΈ Timing: {timing_json}")
|
| 71 |
+
logger.info(f"π Status: {status_text}")
|
| 72 |
+
|
| 73 |
+
return result
|
| 74 |
+
|
| 75 |
+
except Exception as e:
|
| 76 |
+
logger.error(f"β Gradio API test failed: {e}")
|
| 77 |
+
return None
|
| 78 |
+
|
| 79 |
+
async def test_http_api(self, audio_file_path):
|
| 80 |
+
"""Test STT service via HTTP API endpoint"""
|
| 81 |
+
try:
|
| 82 |
+
logger.info(f"π Testing HTTP API at {self.stt_service_url}/api/transcribe")
|
| 83 |
+
|
| 84 |
+
# Prepare file for upload
|
| 85 |
+
with open(audio_file_path, 'rb') as audio_file:
|
| 86 |
+
files = {
|
| 87 |
+
'file': ('test_audio.wav', audio_file, 'audio/wav')
|
| 88 |
+
}
|
| 89 |
+
data = {
|
| 90 |
+
'language': 'en',
|
| 91 |
+
'model_size_param': 'base'
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
logger.info("π€ Uploading audio file to HTTP API...")
|
| 95 |
+
response = requests.post(
|
| 96 |
+
f"{self.stt_service_url}/api/transcribe",
|
| 97 |
+
files=files,
|
| 98 |
+
data=data,
|
| 99 |
+
timeout=30
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
logger.info(f"π₯ HTTP API response status: {response.status_code}")
|
| 103 |
+
|
| 104 |
+
if response.status_code == 200:
|
| 105 |
+
result = response.json()
|
| 106 |
+
logger.info(f"β
HTTP API response: {result}")
|
| 107 |
+
return result
|
| 108 |
+
else:
|
| 109 |
+
logger.error(f"β HTTP API failed with status {response.status_code}: {response.text}")
|
| 110 |
+
return None
|
| 111 |
+
|
| 112 |
+
except Exception as e:
|
| 113 |
+
logger.error(f"β HTTP API test failed: {e}")
|
| 114 |
+
return None
|
| 115 |
+
|
| 116 |
+
async def check_service_status(self):
|
| 117 |
+
"""Check if STT service is responding"""
|
| 118 |
+
try:
|
| 119 |
+
# Test basic connectivity
|
| 120 |
+
logger.info(f"π Checking service connectivity...")
|
| 121 |
+
response = requests.get(f"{self.stt_service_url}/", timeout=10)
|
| 122 |
+
logger.info(f"π‘ Service status: {response.status_code}")
|
| 123 |
+
|
| 124 |
+
if response.status_code == 200:
|
| 125 |
+
logger.info("β
STT service is responding")
|
| 126 |
+
else:
|
| 127 |
+
logger.warning(f"β οΈ STT service returned status {response.status_code}")
|
| 128 |
+
|
| 129 |
+
# Test API health endpoint if it exists
|
| 130 |
+
try:
|
| 131 |
+
health_response = requests.get(f"{self.stt_service_url}/api/health", timeout=5)
|
| 132 |
+
if health_response.status_code == 200:
|
| 133 |
+
health_data = health_response.json()
|
| 134 |
+
logger.info(f"π Health check: {health_data}")
|
| 135 |
+
else:
|
| 136 |
+
logger.info(f"βΉοΈ No health endpoint available")
|
| 137 |
+
except:
|
| 138 |
+
logger.info("βΉοΈ No health endpoint available")
|
| 139 |
+
|
| 140 |
+
except Exception as e:
|
| 141 |
+
logger.error(f"β Service status check failed: {e}")
|
| 142 |
+
|
| 143 |
+
async def run_stt_direct_test():
|
| 144 |
+
"""Run the direct STT service test"""
|
| 145 |
+
test = STTDirectTest()
|
| 146 |
+
await test.test_stt_service_direct()
|
| 147 |
+
|
| 148 |
+
if __name__ == "__main__":
|
| 149 |
+
asyncio.run(run_stt_direct_test())
|
test_webrtc_connection.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Test WebRTC Handler Connection to STT Service
|
| 3 |
+
Verify if the WebRTC handler can actually connect and send audio to STT service
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import asyncio
|
| 7 |
+
import tempfile
|
| 8 |
+
import wave
|
| 9 |
+
import numpy as np
|
| 10 |
+
import logging
|
| 11 |
+
from datetime import datetime
|
| 12 |
+
from mcp_voice_service import mcp_create_test_voice
|
| 13 |
+
from webrtc_streamlit import StreamlitWebRTCHandler
|
| 14 |
+
|
| 15 |
+
logging.basicConfig(level=logging.INFO)
|
| 16 |
+
logger = logging.getLogger(__name__)
|
| 17 |
+
|
| 18 |
+
async def test_webrtc_stt_connection():
|
| 19 |
+
"""Test WebRTC handler connection to STT service"""
|
| 20 |
+
logger.info("π Testing WebRTC handler connection to STT service")
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
# Step 1: Create test audio
|
| 24 |
+
logger.info("π Creating test audio file...")
|
| 25 |
+
test_voice_file = await mcp_create_test_voice()
|
| 26 |
+
logger.info(f"β
Test audio created: {test_voice_file}")
|
| 27 |
+
|
| 28 |
+
# Step 2: Initialize WebRTC handler
|
| 29 |
+
logger.info("π€ Initializing WebRTC handler...")
|
| 30 |
+
handler = StreamlitWebRTCHandler()
|
| 31 |
+
|
| 32 |
+
# Step 3: Test client connection
|
| 33 |
+
logger.info("π Testing STT client connection...")
|
| 34 |
+
client = handler.client
|
| 35 |
+
if client:
|
| 36 |
+
logger.info("β
WebRTC handler client initialized successfully")
|
| 37 |
+
else:
|
| 38 |
+
logger.error("β WebRTC handler client initialization failed")
|
| 39 |
+
return
|
| 40 |
+
|
| 41 |
+
# Step 4: Test transcription directly via handler
|
| 42 |
+
logger.info("π€ Testing transcription via WebRTC handler...")
|
| 43 |
+
transcription = await handler.transcribe_audio_file(test_voice_file)
|
| 44 |
+
|
| 45 |
+
if transcription and not transcription.startswith("ERROR"):
|
| 46 |
+
logger.info(f"β
WebRTC transcription successful: '{transcription}'")
|
| 47 |
+
else:
|
| 48 |
+
logger.error(f"β WebRTC transcription failed: {transcription}")
|
| 49 |
+
|
| 50 |
+
# Step 5: Test with HTTP fallback if available
|
| 51 |
+
logger.info("π Testing HTTP fallback...")
|
| 52 |
+
await test_http_fallback(test_voice_file)
|
| 53 |
+
|
| 54 |
+
except Exception as e:
|
| 55 |
+
logger.error(f"β WebRTC connection test failed: {e}")
|
| 56 |
+
|
| 57 |
+
async def test_http_fallback(audio_file_path):
|
| 58 |
+
"""Test HTTP fallback for WebRTC connection"""
|
| 59 |
+
try:
|
| 60 |
+
import requests
|
| 61 |
+
|
| 62 |
+
stt_url = "https://pgits-stt-gpu-service.hf.space"
|
| 63 |
+
|
| 64 |
+
# Try the Gradio HTTP endpoint directly
|
| 65 |
+
logger.info("π€ Testing Gradio HTTP upload...")
|
| 66 |
+
|
| 67 |
+
with open(audio_file_path, 'rb') as f:
|
| 68 |
+
files = {'file': ('test_audio.wav', f, 'audio/wav')}
|
| 69 |
+
|
| 70 |
+
# Try Gradio's file upload endpoint
|
| 71 |
+
try:
|
| 72 |
+
response = requests.post(
|
| 73 |
+
f"{stt_url}/upload",
|
| 74 |
+
files=files,
|
| 75 |
+
timeout=10
|
| 76 |
+
)
|
| 77 |
+
logger.info(f"π₯ Upload response: {response.status_code}")
|
| 78 |
+
if response.status_code != 200:
|
| 79 |
+
logger.info(f"π Response text: {response.text[:200]}")
|
| 80 |
+
except Exception as e:
|
| 81 |
+
logger.info(f"βΉοΈ Upload endpoint not available: {e}")
|
| 82 |
+
|
| 83 |
+
# Check available endpoints
|
| 84 |
+
logger.info("π Checking available endpoints...")
|
| 85 |
+
endpoints_to_try = [
|
| 86 |
+
"/queue/join",
|
| 87 |
+
"/run/gradio_transcribe_wrapper",
|
| 88 |
+
"/api/gradio_transcribe_wrapper",
|
| 89 |
+
"/gradio_api/run/gradio_transcribe_wrapper"
|
| 90 |
+
]
|
| 91 |
+
|
| 92 |
+
for endpoint in endpoints_to_try:
|
| 93 |
+
try:
|
| 94 |
+
response = requests.get(f"{stt_url}{endpoint}", timeout=5)
|
| 95 |
+
logger.info(f"π‘ {endpoint}: {response.status_code}")
|
| 96 |
+
except Exception as e:
|
| 97 |
+
logger.info(f"β {endpoint}: Not available")
|
| 98 |
+
|
| 99 |
+
except Exception as e:
|
| 100 |
+
logger.error(f"β HTTP fallback test failed: {e}")
|
| 101 |
+
|
| 102 |
+
if __name__ == "__main__":
|
| 103 |
+
asyncio.run(test_webrtc_stt_connection())
|