Parler_TTS_API / test_urdu_tts.sh
aspirant312's picture
Add Urdu TTS test suite - generates audio files and saves to output folder
5481f58
Raw
History Blame Contribute Delete
3.02 kB
#!/bin/bash
API_URL="https://ebitlogix-parler-tts-api.hf.space"
OUTPUT_DIR="tts_output"
mkdir -p "$OUTPUT_DIR"
echo "======================================================================"
echo "TTS API Test Suite - Urdu Text Generation"
echo "======================================================================"
echo ""
# Health check
echo "Testing API Health Check..."
response=$(curl -s "$API_URL/")
if echo "$response" | grep -q "ok"; then
echo "✅ API is running"
echo " Response: $response"
else
echo "❌ API is not responding"
exit 1
fi
echo ""
echo "======================================================================"
echo "Testing TTS Generation with Urdu Text"
echo "======================================================================"
echo ""
# Test cases: text|speaker|description
declare -a TESTS=(
"سلام دنیا|Divya|Hello World"
"مرحبا بك في تطبيق تحويل النص إلى كلام|Rani|Welcome to TTS App"
"یہ ایک اردو متن ہے جو آواز میں تبدیل ہوگا|Rohit|This is Urdu text"
"کتاب پڑھنا میرا پسندیدہ کام ہے|Aman|Reading books"
"خوشامدید، یہ ایک خوبصورت دن ہے|Generic Female|Beautiful day"
"ہمیں اپنے لیے بہتر مستقبل بنانی ہے|Generic Male|Build future"
)
successful=0
failed=0
count=0
for test in "${TESTS[@]}"; do
IFS='|' read -r text speaker description <<< "$test"
((count++))
echo "[$count/${#TESTS[@]}] Testing: $description"
echo " Text: $text"
echo " Speaker: $speaker"
# Create JSON payload
json_payload=$(cat <<EOF
{
"text": "$text",
"speaker": "$speaker",
"pitch": "Moderate",
"rate": "Moderate",
"temperature": 0.8,
"do_sample": true
}
EOF
)
# Make API request and save audio
timestamp=$(date +%Y%m%d_%H%M%S)
filename="${timestamp}_${speaker// /_}_${count}.wav"
filepath="$OUTPUT_DIR/$filename"
http_code=$(curl -s -w "%{http_code}" -o "$filepath" \
-X POST "$API_URL/tts" \
-H "Content-Type: application/json" \
-d "$json_payload")
if [ "$http_code" = "200" ]; then
file_size=$(du -h "$filepath" | cut -f1)
echo " ✅ Success - Saved to: $filepath ($file_size)"
((successful++))
else
echo " ❌ Failed - HTTP $http_code"
rm -f "$filepath"
((failed++))
fi
echo ""
done
echo "======================================================================"
echo "Results: $successful successful, $failed failed"
echo "Audio files saved to: $(pwd)/$OUTPUT_DIR"
echo "======================================================================"
echo ""
# List generated files
if [ $successful -gt 0 ]; then
echo "Generated files:"
ls -lh "$OUTPUT_DIR" | tail -n +2 | awk '{print " " $9, "(" $5 ")"}'
echo ""
fi
if [ $failed -eq 0 ]; then
echo "✅ All tests passed!"
else
echo "⚠️ $failed test(s) failed."
fi