CoolFace
Apppublic

uxoxo/eb2ab

sourceHugging Faceapache-2.0updated 11mo agoView on Hugging Face
0likes
test_api_full_workflow.sh106 linesDownload Raw Back to root
1#!/bin/bash2# Full workflow test for the TTS REST API3 4# Configuration5API_BASE_URL="https://uxoxo-eb2ab.hf.space/api/v1"6API_KEY="${API_KEY:-your-api-key-here}"  # Set via environment or replace here7 8echo "=============================================="9echo "  TTS API Full Workflow Test"10echo "=============================================="11echo ""12 13# Step 1: Health check (no auth required)14echo "1. Testing health endpoint..."15HEALTH=$(curl -s "${API_BASE_URL}/health")16echo "   Response: $HEALTH"17echo ""18 19# Step 2: List available voices (requires auth)20echo "2. Listing available voices..."21VOICES=$(curl -s -H "X-API-Key: ${API_KEY}" "${API_BASE_URL}/tts/voices")22echo "   Found voices: $(echo $VOICES | jq -r '.voices | length // "error"') voices"23echo "   First 3 voices: $(echo $VOICES | jq -r '.voices[:3] | .[].name // empty' | tr '\n' ', ')"24echo ""25 26# Step 3: Submit TTS conversion job27echo "3. Submitting TTS conversion job..."28TEST_TEXT="Hello world! This is a test of the text to speech API. It should convert this text into an audio file."29 30JOB_RESPONSE=$(curl -s -X POST "${API_BASE_URL}/tts/convert" \31  -H "Content-Type: application/json" \32  -H "X-API-Key: ${API_KEY}" \33  -d "{34    \"text\": \"${TEST_TEXT}\",35    \"language\": \"eng\",36    \"engine\": \"xtts_v2\",37    \"output_format\": \"mp3\"38  }")39 40JOB_ID=$(echo $JOB_RESPONSE | jq -r '.job_id // empty')41 42if [ -z "$JOB_ID" ]; then43  echo "   ❌ Failed to submit job!"44  echo "   Response: $JOB_RESPONSE"45  exit 146fi47 48echo "   ✅ Job submitted successfully!"49echo "   Job ID: $JOB_ID"50echo ""51 52# Step 4: Poll job status53echo "4. Polling job status..."54MAX_ATTEMPTS=6055ATTEMPT=056 57while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do58  STATUS_RESPONSE=$(curl -s -H "X-API-Key: ${API_KEY}" "${API_BASE_URL}/tts/status/${JOB_ID}")59 60  STATUS=$(echo $STATUS_RESPONSE | jq -r '.status // empty')61  PROGRESS=$(echo $STATUS_RESPONSE | jq -r '.progress // 0')62  ERROR=$(echo $STATUS_RESPONSE | jq -r '.error // empty')63 64  echo "   Attempt $((ATTEMPT + 1)): Status=$STATUS, Progress=${PROGRESS}%"65 66  if [ "$STATUS" = "completed" ]; then67    echo "   ✅ Job completed successfully!"68    AUDIO_URL=$(echo $STATUS_RESPONSE | jq -r '.audio_url // empty')69    echo "   Audio URL: $AUDIO_URL"70    break71  elif [ "$STATUS" = "failed" ]; then72    echo "   ❌ Job failed!"73    echo "   Error: $ERROR"74    exit 175  fi76 77  ATTEMPT=$((ATTEMPT + 1))78  sleep 279done80 81if [ $ATTEMPT -ge $MAX_ATTEMPTS ]; then82  echo "   ❌ Timeout waiting for job completion"83  exit 184fi85 86echo ""87 88# Step 5: Download audio file89echo "5. Downloading audio file..."90curl -s -H "X-API-Key: ${API_KEY}" "${API_BASE_URL}/tts/audio/${JOB_ID}" \91  -o "test_output_${JOB_ID}.mp3"92 93if [ -f "test_output_${JOB_ID}.mp3" ]; then94  FILE_SIZE=$(stat -f%z "test_output_${JOB_ID}.mp3" 2>/dev/null || stat -c%s "test_output_${JOB_ID}.mp3" 2>/dev/null)95  echo "   ✅ Audio file downloaded: test_output_${JOB_ID}.mp3"96  echo "   File size: ${FILE_SIZE} bytes"97else98  echo "   ❌ Failed to download audio file"99  exit 1100fi101 102echo ""103echo "=============================================="104echo "  ✅ Full workflow test completed!"105echo "=============================================="106