mirror of
https://github.com/jhechavarria/say.sh.git
synced 2025-12-10 06:06:59 +00:00
securisation globale des fonction et ajout de l'option arret immediat a la fonction shutup
This commit is contained in:
68
say.sh
68
say.sh
@@ -16,11 +16,18 @@ P2WLNGSNAME=( 'English (British)' 'English (US)' 'French' 'German' 'Italian' 'Sp
|
|||||||
## Checks if language is supported by synthesiser
|
## Checks if language is supported by synthesiser
|
||||||
saysupport()
|
saysupport()
|
||||||
{
|
{
|
||||||
for i in "${P2WLNGS[@]}"; do
|
re='^[a-z]{2}\-[A-Z]{2}$';
|
||||||
if [[ "$i" = "$1" ]]; then
|
|
||||||
return 1;
|
if [ $# -eq 1 ]; then
|
||||||
|
if ! [[ $1 =~ $re ]]; then
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
for i in "${P2WLNGS[@]}"; do
|
||||||
|
if [[ "$i" = "$1" ]]; then
|
||||||
|
return 1;
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,15 +43,21 @@ saycfg ()
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ $# -ge 2 ]; then
|
if [ $# -ge 2 ]; then
|
||||||
num=`echo "0 + $2" | bc`;
|
re='^[0-2](\.[0-9])?$'
|
||||||
if [ `echo "$num >= 0 && $num <= 2" | bc` -eq 1 ]; then
|
if [[ $2 =~ $re ]]; then
|
||||||
cfg[1]="$num";
|
num=`echo "0 + $2" | bc`;
|
||||||
|
if [ `echo "$num >= 0 && $num <= 2" | bc` -eq 1 ]; then
|
||||||
|
cfg[1]="$num";
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ $# -ge 3 ]; then
|
if [ $# -ge 3 ]; then
|
||||||
num=`echo "0 + $3" | bc`;
|
re='^[0-2](\.[0-9])?$'
|
||||||
if [ `echo "$num >= 0.5 && $num <= 1.5" | bc` -eq 1 ]; then
|
if [[ $2 =~ $re ]]; then
|
||||||
cfg[2]="$num";
|
num=`echo "0 + $3" | bc`;
|
||||||
|
if [ `echo "$num >= 0.5 && $num <= 1.5" | bc` -eq 1 ]; then
|
||||||
|
cfg[2]="$num";
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ $# -ge 1 ]; then
|
if [ $# -ge 1 ]; then
|
||||||
@@ -74,11 +87,14 @@ saylng ()
|
|||||||
sayvol()
|
sayvol()
|
||||||
{
|
{
|
||||||
cfg=( `cat $CFGPATH` )
|
cfg=( `cat $CFGPATH` )
|
||||||
if [ $# -ge 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
num=`echo "0 + $1" | bc`
|
re='^[0-2](\.[0-9])?$'
|
||||||
if [ `echo "$num >= 0 && $num <= 2" | bc` -eq 1 ]; then
|
if [[ $1 =~ $re ]]; then
|
||||||
cfg[1]="$num"
|
num=`echo "0 + $1" | bc`
|
||||||
echo "${cfg[*]}" > $CFGPATH
|
if [ `echo "$num >= 0 && $num <= 2" | bc` -eq 1 ]; then
|
||||||
|
cfg[1]="$num"
|
||||||
|
echo "${cfg[*]}" > $CFGPATH
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "${cfg[1]}"
|
echo "${cfg[1]}"
|
||||||
@@ -89,11 +105,14 @@ sayvol()
|
|||||||
sayspd()
|
sayspd()
|
||||||
{
|
{
|
||||||
cfg=( `cat $CFGPATH` );
|
cfg=( `cat $CFGPATH` );
|
||||||
if [ $# -ge 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
num=`echo "0 + $1" | bc`
|
re='^[0-2](\.[0-9])?$'
|
||||||
if [ `echo "$num >= 0.5 && $num <= 1.5" | bc` -eq 1 ]; then
|
if [[ $1 =~ $re ]]; then
|
||||||
cfg[2]="$num"
|
num=`echo "0 + $1" | bc`
|
||||||
echo "${cfg[*]}" > $CFGPATH
|
if [ `echo "$num >= 0.5 && $num <= 1.5" | bc` -eq 1 ]; then
|
||||||
|
cfg[2]="$num"
|
||||||
|
echo "${cfg[*]}" > $CFGPATH
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "${cfg[2]}"
|
echo "${cfg[2]}"
|
||||||
@@ -104,8 +123,12 @@ sayspd()
|
|||||||
saylngindex()
|
saylngindex()
|
||||||
{
|
{
|
||||||
i=0;
|
i=0;
|
||||||
|
re='^[a-z]{2}\-[A-Z]{2}$';
|
||||||
|
|
||||||
if [ $# -eq 1 ]; then
|
if [ $# -eq 1 ]; then
|
||||||
|
if ! [[ $1 =~ $re ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
TEST=$1;
|
TEST=$1;
|
||||||
else
|
else
|
||||||
TEST=`saylng`;
|
TEST=`saylng`;
|
||||||
@@ -123,7 +146,7 @@ saylngindex()
|
|||||||
# Stops audio playback
|
# Stops audio playback
|
||||||
shutup ()
|
shutup ()
|
||||||
{
|
{
|
||||||
killall play;
|
killall -9 play;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Start synthesiser
|
# Start synthesiser
|
||||||
@@ -145,7 +168,7 @@ say ()
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
saysupport $1;
|
saysupport $1;
|
||||||
if [[ "$?" = "1" ]]; then
|
if [[ $? -eq 1 ]]; then
|
||||||
cfg[0]=$1;
|
cfg[0]=$1;
|
||||||
unset text[0];
|
unset text[0];
|
||||||
fi
|
fi
|
||||||
@@ -223,6 +246,7 @@ elif [ "$1" = "say" ]; then
|
|||||||
shutup;
|
shutup;
|
||||||
else
|
else
|
||||||
TEXT=`xsel`;
|
TEXT=`xsel`;
|
||||||
|
echo "$TEXT";
|
||||||
echo "$TEXT" | say;
|
echo "$TEXT" | say;
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user