-
Notifications
You must be signed in to change notification settings - Fork 0
/
voluble
71 lines (65 loc) · 3.5 KB
/
voluble
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
#!/usr/bin/zsh
# Copyright (c) 2024 Quantius Benignus
#
# THE SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#--------------------------------------------------------------------------
# NAME: voluble
# PREREQUSITES:
# - piper installation (see https://github.com/rhaspi/piper)
# - optionally, a recent version of 'sox' from your system's repositories.
# - optionally, a speech dispatcher installation (preinstalled in many distributions)
#--------------------------------------------------------------------------
#---USER CONFIGURATION BLOCK----------------------------------------------------------------------
#Please, adjust the variables here to suit your environment:
#Set to 1 to use sox instead of alsa play (for whatever reason):
use_sox=0
#Set to 1 to use speech dispatcher integration of Piper (as per instructions at https://github.com/QuantiusBenignus/voluble):
use_spd=0
#If the above is set to 0, piper will be called directly with the voice specified below.
# Choose the default piper voice (and language) for voluble to use for notifications:
pvoice="$HOME/PATH_TO_YOUR_Piper_VOICES/en_US-lessac-low.onnx"
#---END USER CONFIG BLOCK------------------------------------------------------------------------
#---CHECK DEPENDENCIES. This block can be commented out once dependencies confirmed-----------------------------------
if [ use_sox = 1 ]; then
command -v sox &>/dev/null || { echo "sox is required. Please, install sox" >&2 ; exit 1 ; }
fi
if [ use_spd = 1 ]; then
command -v spd-say &>/dev/null || { echo "You have selected to use speech dispatcher. Please, install it and set up to call piper." >&2 ; exit 1 ; }
fi
command -v piper &>/dev/null || { echo -e "Please, install the piper binary (see https://github.com/rhasspy/piper/releases)\
\nand create 'piper' in your PATH as a symbolic link to the executable, e.g.\n \
'ln -s /full/path/to/piper/piper \$HOME/.local/bin/piper'" >&2 ; exit 1 ; }
gnome-extensions list | grep 'voluble' &>/dev/null || { echo "This \
script is made to work with voluble (GNOME shell extension). Please, install it from https://extensions.gnome.org/extension/6849/voluble/" >&2 ; exit 1 ; }
#---END CHECK DEPENDENCIES. The above block can be commented out after successful 1st run----------------------------
#Decide on sample rate, based on model choice:
if [ "$pvoice" = "${pvoice%low*}" ]; then
srate=22050 # low not found
else
srate=16000 # Substring 'low' found
fi
if [ -e "$XDG_RUNTIME_DIR/voluble.tmp" ]; then
data=$(cat "$XDG_RUNTIME_DIR/voluble.tmp")
elif [ $# -gt 0 ]; then
# multiple arguments are ignored
# data="$1"
data="This script is made to work only with the Voluble GNOME shell extension"
else
data="All dependencies are satisfied. I have nothing else to say!"
fi
# Process data
if [ use_spd = 1 ]; then
spd-say -w "$data"
else
if [ use_sox = 1 ]; then
echo "$data" | piper --model $pvoice --output-raw 2>/dev/null | play -q -r $srate -b 16 --encoding signed-integer -t raw - 2>/dev/null
else
echo "$data" | piper --model $pvoice --output-raw 2>/dev/null | aplay -r $srate -f S16_LE -t raw - 2>/dev/null
fi
fi