ISTNetworks commited on
Commit
b67625e
·
verified ·
1 Parent(s): 2ae7eb5

Add Bash inference script

Browse files
Files changed (1) hide show
  1. inference.sh +106 -0
inference.sh ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Standalone inference script for Saudi MSA Piper TTS
4
+ # Usage: ./inference.sh "Arabic text here" output.wav
5
+
6
+ set -e
7
+
8
+ # Configuration
9
+ MODEL_FILE="${MODEL_FILE:-saudi_msa_epoch455.onnx}"
10
+ CONFIG_FILE="${CONFIG_FILE:-saudi_msa_epoch455.onnx.json}"
11
+
12
+ # Colors for output
13
+ GREEN='\033[0;32m'
14
+ RED='\033[0;31m'
15
+ YELLOW='\033[1;33m'
16
+ NC='\033[0m' # No Color
17
+
18
+ # Function to print colored messages
19
+ print_success() {
20
+ echo -e "${GREEN}✓${NC} $1"
21
+ }
22
+
23
+ print_error() {
24
+ echo -e "${RED}✗${NC} $1"
25
+ }
26
+
27
+ print_info() {
28
+ echo -e "${YELLOW}ℹ${NC} $1"
29
+ }
30
+
31
+ # Check if piper is installed
32
+ if ! command -v piper &> /dev/null; then
33
+ print_error "piper command not found"
34
+ echo ""
35
+ echo "Please install piper-tts:"
36
+ echo " pip install piper-tts"
37
+ echo ""
38
+ echo "Or use the Python script:"
39
+ echo " python3 inference.py -t \"Arabic text\" -o output.wav"
40
+ exit 1
41
+ fi
42
+
43
+ # Check if model file exists
44
+ if [ ! -f "$MODEL_FILE" ]; then
45
+ print_error "Model file not found: $MODEL_FILE"
46
+ echo ""
47
+ echo "Please download the model from:"
48
+ echo " https://huggingface.co/ISTNetworks/saudi-msa-piper"
49
+ exit 1
50
+ fi
51
+
52
+ # Get text and output file
53
+ if [ $# -eq 0 ]; then
54
+ echo "Usage: $0 \"Arabic text\" [output.wav]"
55
+ echo ""
56
+ echo "Examples:"
57
+ echo " $0 \"مرحبا بك\" output.wav"
58
+ echo " echo \"مرحبا بك\" | $0 - output.wav"
59
+ echo " cat text.txt | $0 - output.wav"
60
+ echo ""
61
+ echo "Environment variables:"
62
+ echo " MODEL_FILE - Path to ONNX model (default: saudi_msa_epoch455.onnx)"
63
+ echo " CONFIG_FILE - Path to config file (default: saudi_msa_epoch455.onnx.json)"
64
+ exit 1
65
+ fi
66
+
67
+ TEXT="$1"
68
+ OUTPUT="${2:-output.wav}"
69
+
70
+ # Read from stdin if text is "-"
71
+ if [ "$TEXT" = "-" ]; then
72
+ print_info "Reading text from stdin..."
73
+ TEXT=$(cat)
74
+ fi
75
+
76
+ # Check if text is empty
77
+ if [ -z "$TEXT" ]; then
78
+ print_error "No text provided"
79
+ exit 1
80
+ fi
81
+
82
+ # Synthesize
83
+ print_info "Model: $MODEL_FILE"
84
+ print_info "Text: $TEXT"
85
+ print_info "Output: $OUTPUT"
86
+ echo ""
87
+
88
+ echo "$TEXT" | piper --model "$MODEL_FILE" --output_file "$OUTPUT"
89
+
90
+ if [ $? -eq 0 ]; then
91
+ print_success "Audio generated successfully: $OUTPUT"
92
+
93
+ # Show file info if 'file' command is available
94
+ if command -v file &> /dev/null; then
95
+ file "$OUTPUT"
96
+ fi
97
+
98
+ # Show file size
99
+ if command -v du &> /dev/null; then
100
+ SIZE=$(du -h "$OUTPUT" | cut -f1)
101
+ echo "File size: $SIZE"
102
+ fi
103
+ else
104
+ print_error "Failed to generate audio"
105
+ exit 1
106
+ fi