-
Notifications
You must be signed in to change notification settings - Fork 43
/
install_piper.sh
executable file
·95 lines (71 loc) · 3.14 KB
/
install_piper.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
88
89
90
91
92
93
94
95
#!/bin/bash
function main() {
# Check for help flag
if [[ "$@" == "--help" || "$@" == "-h" ]]; then
echo "Usage: source install_piper.sh [download] [model]"
echo " download: Set to true to download. Default is false."
echo " model: Set the model number. Default is -1."
echo " set to -1 to skip model download."
return # Use return here because the script is sourced, not executed
fi
DOWNLOAD_=${1#*=}
MODEL_=${2#*=}
DOWNLOAD_=${DOWNLOAD_:-false}
MODEL_=${MODEL_:-"-1"}
# Determine system architecture
ARCH=$(uname -m)
# Set download link based on architecture
if [ "$ARCH" = "x86_64" ]; then
DOWNLOAD_LINK="https://github.com/rhasspy/piper/releases/download/v1.0.0/piper_amd64.tar.gz"
elif [ "$ARCH" = "aarch64" ]; then
DOWNLOAD_LINK="https://github.com/rhasspy/piper/releases/download/v1.0.0/piper_arm64.tar.gz"
elif [ "$ARCH" = "armv7l" ]; then
DOWNLOAD_LINK="https://github.com/rhasspy/piper/releases/download/v1.0.0/piper_armv7.tar.gz"
else
echo "Unsupported architecture: $ARCH. You will have to manually compile and install piper from their repo https://github.com/rhasspy/piper/"
return
fi
if [ $DOWNLOAD_ = true ]; then
# Download and extract Piper
echo "Downloading and extracting Piper in plugins/piper..."
mkdir -p plugins/voice
cd plugins/voice
wget $DOWNLOAD_LINK -O piper.tar.gz
tar -xvf piper.tar.gz
rm piper.tar.gz
cd ../../
fi
BASE_VOICE_MODEL_URL="https://api.github.com/repos/rhasspy/piper/releases/tags/v0.0.2"
if [ $MODEL_ != -1 ]; then
# Use the GitHub API to get a list of voice assets
VOICE_DATA=$(curl -s https://api.github.com/repos/rhasspy/piper/releases/tags/v0.0.2)
# Filter the voice assets using jq, selecting only the ones that start with "voice" and contain "_en"
VOICE_NAMES=($(echo $VOICE_DATA | jq -r '.assets[] | select(.name | startswith("voice") and contains("-en")) | .name' | head -10))
VOICE_URLS=($(echo $VOICE_DATA | jq -r '.assets[] | select(.name | startswith("voice") and contains("-en")) | .browser_download_url' | head -10))
# Give the user a choice to select a voice
echo "Please select one of the following voices:"
for i in "${!VOICE_NAMES[@]}"; do
echo "$((i+1))) ${VOICE_NAMES[$i]}"
done
read -p "Enter the number corresponding to the voice you want to select: " MODEL_
# Set voice download link based on user preference
VOICE_LINK="${VOICE_URLS[$MODEL_]}"
# Download and extract voice
mkdir -p models/piper
cd models/piper
wget $VOICE_LINK -O voice.tar.gz
tar -xvf voice.tar.gz
rm voice.tar.gz
if [ $? -eq 0 ]; then
echo "Voice model downloaded completed successfully."
else
echo "Voice model downloaded failed. Please errors and try again."
fi
cd ../..
fi
unset DOWNLOAD_
unset MODEL_
}
main "$@"
export PATH=$PATH:$PWD/plugins/voice/piper
echo "PATH updated to include $PWD/plugins/voice/piper"