#!/bin/bash # Standalone inference script for Saudi MSA Piper TTS # Usage: ./inference.sh "Arabic text here" output.wav set -e # Configuration MODEL_FILE="${MODEL_FILE:-saudi_msa_epoch455.onnx}" CONFIG_FILE="${CONFIG_FILE:-saudi_msa_epoch455.onnx.json}" # Colors for output GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Function to print colored messages print_success() { echo -e "${GREEN}✓${NC} $1" } print_error() { echo -e "${RED}✗${NC} $1" } print_info() { echo -e "${YELLOW}ℹ${NC} $1" } # Check if piper is installed if ! command -v piper &> /dev/null; then print_error "piper command not found" echo "" echo "Please install piper-tts:" echo " pip install piper-tts" echo "" echo "Or use the Python script:" echo " python3 inference.py -t \"Arabic text\" -o output.wav" exit 1 fi # Check if model file exists if [ ! -f "$MODEL_FILE" ]; then print_error "Model file not found: $MODEL_FILE" echo "" echo "Please download the model from:" echo " https://huggingface.co/ISTNetworks/saudi-msa-piper" exit 1 fi # Get text and output file if [ $# -eq 0 ]; then echo "Usage: $0 \"Arabic text\" [output.wav]" echo "" echo "Examples:" echo " $0 \"مرحبا بك\" output.wav" echo " echo \"مرحبا بك\" | $0 - output.wav" echo " cat text.txt | $0 - output.wav" echo "" echo "Environment variables:" echo " MODEL_FILE - Path to ONNX model (default: saudi_msa_epoch455.onnx)" echo " CONFIG_FILE - Path to config file (default: saudi_msa_epoch455.onnx.json)" exit 1 fi TEXT="$1" OUTPUT="${2:-output.wav}" # Read from stdin if text is "-" if [ "$TEXT" = "-" ]; then print_info "Reading text from stdin..." TEXT=$(cat) fi # Check if text is empty if [ -z "$TEXT" ]; then print_error "No text provided" exit 1 fi # Synthesize print_info "Model: $MODEL_FILE" print_info "Text: $TEXT" print_info "Output: $OUTPUT" echo "" echo "$TEXT" | piper --model "$MODEL_FILE" --output_file "$OUTPUT" if [ $? -eq 0 ]; then print_success "Audio generated successfully: $OUTPUT" # Show file info if 'file' command is available if command -v file &> /dev/null; then file "$OUTPUT" fi # Show file size if command -v du &> /dev/null; then SIZE=$(du -h "$OUTPUT" | cut -f1) echo "File size: $SIZE" fi else print_error "Failed to generate audio" exit 1 fi