-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_request.sh
executable file
·87 lines (75 loc) · 1.91 KB
/
test_request.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Base URL for the TTS server
BASE_URL="http://localhost:8765"
# Function to display usage
usage() {
echo "Usage: $0 -t text [-s speaker] [-h]"
echo "Options:"
echo " -t Text to convert to speech (required)"
echo " -s Speaker (default: xenia)"
echo " -h Show this help message"
exit 1
}
# Default values
TEXT=""
SPEAKER="xenia"
# Parse arguments using getopts
while getopts ":t:s:h" opt; do
case ${opt} in
t)
TEXT="$OPTARG"
;;
s)
SPEAKER="$OPTARG"
;;
h)
usage
;;
\?)
echo "Invalid option: $OPTARG" 1>&2
usage
;;
:)
echo "Invalid option: $OPTARG requires an argument" 1>&2
usage
;;
esac
done
shift $((OPTIND - 1))
# Check if text is provided
if [ -z "$TEXT" ]; then
echo "Error: Text is required" 1>&2
usage
fi
# Perform TTS request
echo -e "${YELLOW}Generating speech...${NC}"
echo -e "${GREEN}Text:${NC} $TEXT"
echo -e "${GREEN}Speaker:${NC} $SPEAKER"
# Make the request
RESPONSE=$(curl -s -X POST "$BASE_URL/tts" \
-H "Content-Type: application/json" \
-d "{
\"text\": \"$TEXT\",
\"speaker\": \"$SPEAKER\",
\"enhance_noise\": true
}")
# Check if request was successful
SUCCESS=$(echo "$RESPONSE" | jq -r '.success')
if [ "$SUCCESS" = "true" ]; then
FILENAME=$(echo "$RESPONSE" | jq -r '.filename')
echo -e "${GREEN}Speech generated successfully!${NC}"
echo -e "${YELLOW}Filename:${NC} $FILENAME"
# Attempt to download the audio file
echo -e "${YELLOW}Downloading audio file...${NC}"
curl -s -O "$BASE_URL/audio/$FILENAME"
echo -e "${GREEN}Audio file downloaded: $FILENAME${NC}"
else
ERROR=$(echo "$RESPONSE" | jq -r '.error')
echo -e "${RED}Error generating speech:${NC} $ERROR"
exit 1
fi