Files
maternal-app/test-voice-commands.sh
Andrei 4b8828fdad
Some checks failed
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
Voice commands now create activities directly via API
- Replace navigation to pre-filled forms with direct API activity creation
- Fetch children from family and use first child (can be enhanced for name matching)
- Show success/error messages with proper feedback
- Auto-close dialog after successful save
- Add test endpoint /api/v1/voice/test-classify for easy testing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-02 08:08:31 +00:00

140 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
# Voice Command Testing Script
# Tests the voice classification API with various baby care commands
API_URL="${API_URL:-http://localhost:3020}"
ENDPOINT="/api/v1/voice/transcribe"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Voice Command Testing Suite${NC}"
echo -e "${BLUE}========================================${NC}\n"
# Test commands
declare -a commands=(
"Change wet diaper"
"Baby ate 150ml formula"
"Baby slept for 1 hour"
"Alice slept for 30 min"
"Alice ate 3 pcs of broccoli at 11:00 AM"
"Dirty diaper change"
"Fed baby 120ml"
"Baby napped for 45 minutes"
"Changed diaper, it was wet"
"Gave baby vitamin D drops"
)
# Function to test a command
test_command() {
local command="$1"
local test_num="$2"
echo -e "${YELLOW}Test #$test_num: \"$command\"${NC}"
echo "---"
# Make API request
response=$(curl -s -X POST "${API_URL}${ENDPOINT}" \
-H "Content-Type: application/json" \
-d "{\"text\":\"$command\",\"language\":\"en\",\"childName\":\"Alice\"}")
# Check if request was successful
if [ $? -ne 0 ]; then
echo -e "${RED}✗ API request failed${NC}\n"
return 1
fi
# Parse response
success=$(echo "$response" | jq -r '.success // false')
if [ "$success" != "true" ]; then
echo -e "${RED}✗ API returned error${NC}"
echo "$response" | jq '.'
echo ""
return 1
fi
# Extract classification details
type=$(echo "$response" | jq -r '.classification.type // "unknown"')
confidence=$(echo "$response" | jq -r '.classification.confidence // 0')
details=$(echo "$response" | jq -r '.classification.details // {}')
timestamp=$(echo "$response" | jq -r '.classification.timestamp // "null"')
# Color-code based on type
case "$type" in
feeding)
type_color="${GREEN}"
;;
sleep)
type_color="${BLUE}"
;;
diaper)
type_color="${YELLOW}"
;;
medicine)
type_color="${RED}"
;;
milestone)
type_color="${GREEN}"
;;
*)
type_color="${RED}"
;;
esac
# Display results
echo -e "Type: ${type_color}${type}${NC}"
echo -e "Confidence: ${confidence}"
echo -e "Timestamp: ${timestamp}"
echo "Details:"
echo "$details" | jq '.'
# Validate confidence threshold
confidence_float=$(echo "$confidence" | awk '{print ($1 >= 0.3) ? "pass" : "fail"}')
if [ "$type" != "unknown" ] && [ "$confidence_float" == "pass" ]; then
echo -e "${GREEN}✓ Command successfully classified${NC}\n"
return 0
else
echo -e "${RED}✗ Low confidence or unknown type${NC}\n"
return 1
fi
}
# Run all tests
total_tests=${#commands[@]}
passed=0
failed=0
for i in "${!commands[@]}"; do
test_num=$((i + 1))
if test_command "${commands[$i]}" "$test_num"; then
((passed++))
else
((failed++))
fi
done
# Summary
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}Test Summary${NC}"
echo -e "${BLUE}========================================${NC}"
echo -e "Total: $total_tests"
echo -e "${GREEN}Passed: $passed${NC}"
echo -e "${RED}Failed: $failed${NC}"
echo ""
if [ $failed -eq 0 ]; then
echo -e "${GREEN}All tests passed! 🎉${NC}"
exit 0
else
echo -e "${RED}Some tests failed. Check the output above.${NC}"
exit 1
fi