Debogage global et redaction du README

This commit is contained in:
jhechavarria
2018-08-23 01:09:37 +02:00
parent f5aa3e24b5
commit 9c92316cc6
2 changed files with 147 additions and 19 deletions

110
README.md Normal file
View File

@@ -0,0 +1,110 @@
# sayy.sh
This script enables any debian based GNU/Linux distribution to talk! Based on Google's text to speach Android application, it gives you a few commands to ease your TTS experience on Linux.
## Setup
### Prerequisites
Before installing the script, you will need to install a few dependencies:
. libttspico-utils
. sox
. dialog
. xsel
To install all them at once type the following command:
```
sudo apt-get install libttspico-utils sox dialog xsel
```
As libttspico-utils is a non-free package, it may not be available in your default packqge repositories.
## Install
To start installing the script simply type:
```
. say.sh install
```
This will go through a few operations required for it to work properly:
. creation of a /home/user/bin/say directory
. moving the script to newly created directory
. creating and setting config file within nely created directory
. adding an instruction to /gome/user/.bashrc file
. reloading .bashrc file
## Configuration
During setup a default configuration will be set. You still can change it using the **saycfg** command. This command takes 3 arguments: language, volume and speed.
Example:
This command sets language to US English, volume to 1.2 and speed to 0.8
```
saycfg en-US 1.2 0.8
```
The script supports over to 6 different languages. Volume and speed can differ from 0.5 to 1.5.
### Available languages
**en-GB** British English
**en-US** US English
**fr-FR** French
**de-DE** Deutsch
**es-ES** Spanish
**it-IT** Italiam
## Commands
### say
Start text interpretation and reading.
#### Basic usage
```
say Hello World!
```
#### Live changing language
If default configuration language doesn't fit with a text written in different language, you can overwrite it in command call.
```
say it-IT Buongiorno a tutti!
```
#### Using standard input
```
echo "Salut tout le monde!" | say
```
Even using standard input, language can still be overwrittem:
```
echo "I love this app!" | say en-GB
```
### saycfg
Set full configuration
```
saycfg es-ES 1 1
```
### saylng
Sets current languages in configuration
```
saylng de-DE
```

56
say.sh
View File

@@ -1,14 +1,19 @@
#!/bin/bash #!/bin/bash
# Text file and audio files name that will be used by the script # Text file and audio files name that will be used by the script
P2WFILE=".say"; P2WFILE="say";
# Set paths
ROOTPATH="$HOME/bin/say/"
SRCPATH="$ROOTPATH$P2WFILE.sh"
CFGPATH="$ROOTPATH$P2WFILE.cfg"
SNDPATH="$ROOTPATH$P2WFILE.wav"
# Accepted languages # Accepted languages
P2WLNGS=( "en-GB" "en-US" "fr-FR" "de-DE" "it-IT" "es-ES" ); P2WLNGS=( "en-GB" "en-US" "fr-FR" "de-DE" "it-IT" "es-ES" );
P2WLNGSNAME=( 'English (British)' 'English (US)' 'French' 'German' 'Italian' 'Spanish' ); P2WLNGSNAME=( 'English (British)' 'English (US)' 'French' 'German' 'Italian' 'Spanish' );
## Checks if language is supported by the synthesiser ## Checks if language is supported by synthesiser
saysupport() saysupport()
{ {
for i in "${P2WLNGS[@]}"; do for i in "${P2WLNGS[@]}"; do
@@ -19,10 +24,10 @@ saysupport()
return 0; return 0;
} }
# Set global config: language, volume, speed # Get/Set program config: language, volume, speed
saycfg () saycfg ()
{ {
cfg=`cat ~/$P2WFILE.cfg`; cfg=`cat $CFGPATH`;
IFS=', ' read -r -a cfg <<< "$cfg"; IFS=', ' read -r -a cfg <<< "$cfg";
if [ $# -ge 1 ]; then if [ $# -ge 1 ]; then
saysupport $1; saysupport $1;
@@ -43,15 +48,15 @@ saycfg ()
fi fi
fi fi
if [ $# -ge 1 ]; then if [ $# -ge 1 ]; then
echo "${cfg[*]}" > ~/$P2WFILE.cfg; echo "${cfg[*]}" > $CFGPATH;
fi fi
echo "${cfg[*]}"; echo "${cfg[*]}";
} }
# Change synthesiser lamguage # Get/Set synthesiser lamguage
saylng () saylng ()
{ {
cfg=`cat ~/$P2WFILE.cfg`; cfg=`cat $CFGPATH`;
IFS=', ' read -r -a cfg <<< "$cfg"; IFS=', ' read -r -a cfg <<< "$cfg";
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
saysupport $1; saysupport $1;
@@ -91,9 +96,10 @@ shutup ()
killall play; killall play;
} }
# Start synthesiser
say () say ()
{ {
cfg=`cat ~/$P2WFILE.cfg`; cfg=`cat $CFGPATH`;
IFS=', ' read -r -a cfg <<< "$cfg"; IFS=', ' read -r -a cfg <<< "$cfg";
text=( "$@" ); text=( "$@" );
if [ $# -ge 2 -a -f $2 ]; then if [ $# -ge 2 -a -f $2 ]; then
@@ -113,20 +119,23 @@ say ()
cfg[0]=$1; cfg[0]=$1;
unset text[0]; unset text[0];
fi fi
pico2wave -l ${cfg[0]} -w ~/$P2WFILE.wav "${text[*]}"; pico2wave -l ${cfg[0]} -w $SNDPATH "${text[*]}";
play ~/$P2WFILE.wav vol ${cfg[1]} speed ${cfg[2]}; play $SNDPATH vol ${cfg[1]} speed ${cfg[2]};
} }
if [[ "$1" = "install" ]]; then if [[ "$1" = "install" ]]; then
if [ ! -d $HOME/bin ] | [ $2 = "f" ]; then if [ ! -d "$ROOTPATH" ]; then
mkdir $HOME/bin mkdir -p $ROOTPATH
echo "Created directory: $ROOTPATH"
fi fi
if [ ! -f $HOME/bin/$P2WFILE.sh ] | [ $2 = "f" ]; then if [ ! -f "$SRCPATH" ]; then
mv ./$P2WFILE.sh $HOME/bin mv ./$P2WFILE.sh $ROOTPATH
echo "Script moved to: $ROOTPATH directory"
fi fi
SYSLNG="`echo $LANGUAGE | sed 's/_/-/g'`"; if [ ! -f "$CFGPATH" ]; then
sudo apt-get install libttspico-utils sox dialog xsel; SYSLNG="`echo $LANGUAGE | sed 's/_/-/g'`";
if [ ! -f $HOME/$P2WFILE.cfg ] | [ $2 = "f" ]; then touch $CFGPATH
echo -n "Default config set to: "
saysupport $SYSLNG saysupport $SYSLNG
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
saycfg "$SYSLNG" 1 1; saycfg "$SYSLNG" 1 1;
@@ -134,6 +143,15 @@ if [[ "$1" = "install" ]]; then
saycfg "en-US" 1 1; saycfg "en-US" 1 1;
fi fi
fi fi
if [ ! "`grep -rnw $HOME/.bashrc -e \". $SRCPATH\"`" > /dev/null ]; then
echo ". $SRCPATH" >> "$HOME/.bashrc"
echo "Script autoload instruction added to $HOME/.bashrc"
source "$HOME/.bashrc"
echo "Reloaded source: $HOME/.bashrc"
fi
if [ "$2" = "d" ]; then
sudo apt-get install libttspico-utils sox dialog xsel;
fi
elif [ "$1" = "config" ]; then elif [ "$1" = "config" ]; then
saycfg $2 $3 $4; saycfg $2 $3 $4;
elif [ "$1" = "lang" ] ; then elif [ "$1" = "lang" ] ; then
@@ -167,7 +185,7 @@ elif [ "$1" = "lang" ] ; then
esac esac
clear clear
elif [ "$1" = "say" ]; then elif [ "$1" = "say" ]; then
if [ pgrep -x "play" > /dev/null ]; then if [ "`pgrep -x play`" > /dev/null ]; then
shutup; shutup;
else else
TEXT=`xsel`; TEXT=`xsel`;