diff --git a/README.md b/README.md index 97c19a3..b99607b 100644 --- a/README.md +++ b/README.md @@ -2,93 +2,38 @@ Author : T Shrinivasan - This is a script to install the Tamil text to Speech System provided by IIT Madras and SSN College of Engineering at https://www.iitm.ac.in/donlab/tts/voices.php ## System requirements: -Ubuntu 16.04 +1. Ubuntu 16.04 +2. Ubuntu 18.04 ## Will it work on Windows? - No. - -## How to execute: - - +## How to Install ``` git clone https://github.com/tshrinivasan/tamil-tts-install.git - cd tamil-tts-install +./tamil-tts.sh --clean --setup ``` -Edit the file, install-tamil-tts.sh - -Fill the following details. - -DOWNLOAD_PATH=/home/ubuntu/tts/packages #to download the required packages - -COMPILE_PATH=/home/ubuntu/tts/compiled # to place the compiled files and folders - - -Register here http://htk.eng.cam.ac.uk/download.shtml and get a username and password - -HTKUSER=htkuserchennai - -HTKPASSWORD=sgqY=t=M - - -Then, execute the file as - -bash install-tamil-tts.sh - - - -## How to convert a text to audio? - +## How to convert tamil text to .wav ``` -export FESTDIR=/usr - - -cd COMPILE_PATH -ssn_hts_demo/scripts/complete “தமிழ் வாழ்க” linux - +cd tamil-tts-install +./tamil-tts.sh --run --source tamil-text.txt ``` +This will generate 'tamil-text.wav' file - -This will convert the text and store as wav in - -ssn_hts_demo/wav/1.wav - -you can play it with any audio player. - - -The full details of what is on the compile process is explained here. -https://goinggnu.wordpress.com/2017/09/20/how-to-compile-tamil-tts-engine-from-source/ - -To hear a demo on how the tamil TTS system sounds, click here -https://soundcloud.com/shrinivasan/tamil-tts-demo - - - - -## How to convert a full text file to audio? - -Prepare the tamil text content as a text file. Save it as ".txt" extension. - -open the file convert-file-to-audio.py, with any text editor and replace the following two parapeters with suitable folders. - -ssn_demo_path = "/home/shrini/Downloads/ssn_hts_demo" - -mp3_out_path = "/home/shrini/test" - - -Then execute the below command - +## How to convert tamil text to .mp3 ``` -python convert-file-to-audio.py +cd tamil-tts-install +./tamil-tts.sh --run --gen-mp3 --source tamil-text.txt ``` +This will generate 'tamil-text.mp3' file -This will make mp3 file and store in the folder mp3_out_path/filename-timestamp +## howto set your own HTKUSER and HTKPASSWORD in tamil-tts.sh +Register here http://htk.eng.cam.ac.uk/download.shtml and get a username and password, replace your +own username and passward in HTKUSER and HTKPASSWORD diff --git a/convert-file-to-audio.py b/convert-file-to-audio.py deleted file mode 100644 index 4ec5695..0000000 --- a/convert-file-to-audio.py +++ /dev/null @@ -1,41 +0,0 @@ -import sys -import os -import time -import datetime - -ssn_demo_path = "/home/shrini/Downloads/ssn_hts_demo" -#mp3_out_path = "/home/shrini/test" - - -ts = time.time() -timestamp = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d%H%M%S') - -input_file = sys.argv[1] - -filename = input_file.split(".txt")[0] - -out_dir = filename + "-" + timestamp - -os.system("mkdir " + out_dir) - -lines = open(input_file).readlines() - -count_of_lines = len(lines) -digits = len(str(abs(count_of_lines))) +1 - -line_count = 1 - -for line in lines: - print line - line = line.strip() - os.chdir(ssn_demo_path) - command = "./scripts/complete '" + line + "' linux" - print command - os.system(command) - os.system("lame wav/1.wav " + out_dir + "/" + str(line_count).zfill(digits) + ".mp3") - line_count = line_count + 1 - - -os.chdir(out_dir) -os.system("cat *.mp3 > " + filename + ".mp3") -os.system("rm 0*.mp3") diff --git a/install-tamil-tts.sh b/install-tamil-tts.sh deleted file mode 100644 index 73269cb..0000000 --- a/install-tamil-tts.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/bash -DOWNLOAD_PATH=/home/nithya/dev/tts/packages -COMPILE_PATH=/home/nithya/dev/tts/compiled - - -#Register here http://htk.eng.cam.ac.uk/download.shtml and get a username and password - -HTKUSER=htkuserchennai -HTKPASSWORD=sgqY=t=M - - -sudo apt-get install wget festival libx11-dev perl build-essential g++-4.7 csh gawk bc sox tcsh default-jre lame -y - - -mkdir -p $DOWNLOAD_PATH -mkdir -p $COMPILE_PATH - -cd $DOWNLOAD_PATH -wget -nc https://www.iitm.ac.in/donlab/tts/downloads/voices/hts23/ssn_hts_demo_Tamil_male.tgz - -gunzip ssn_hts_demo_Tamil_male.tgz -tar xvf ssn_hts_demo_Tamil_male.tar - - - -cd $DOWNLOAD_PATH -wget -nc https://nchc.dl.sourceforge.net/project/sp-tk/SPTK/SPTK-3.10/SPTK-3.10.tar.gz -tar xvzf SPTK-3.10.tar.gz -cd SPTK-3.10 -./configure --prefix=$COMPILE_PATH/sptk -make -make install - - -cd $DOWNLOAD_PATH -mkdir hts-htk -cd hts-htk -wget -nc http://hts.sp.nitech.ac.jp/archives/2.3/HTS-2.3_for_HTK-3.4.1.tar.bz2 -tar xvjf HTS-2.3_for_HTK-3.4.1.tar.bz2 - -cd $DOWNLOAD_PATH -wget -nc http://htk.eng.cam.ac.uk/ftp/software/HTK-3.4.1.tar.gz --user=$HTKUSER --password=$HTKPASSWORD -wget -nc http://htk.eng.cam.ac.uk/ftp/software/hdecode/HDecode-3.4.1.tar.gz --user=$HTKUSER --password=$HTKPASSWORD - -tar -zxvf HTK-3.4.1.tar.gz -tar -zxvf HDecode-3.4.1.tar.gz - -cd htk -patch -p1 -d . < ../hts-htk/HTS-2.3_for_HTK-3.4.1.patch -export CC=gcc-4.7 CXX=g++-4.7 -./configure CFLAGS="-DARCH=linux" --prefix=$COMPILE_PATH/htk -make -make install - - - -cd $DOWNLOAD_PATH - -wget -nc https://nchc.dl.sourceforge.net/project/hts-engine/hts_engine%20API/hts_engine_API-1.10/hts_engine_API-1.10.tar.gz - -tar xvzf hts_engine_API-1.10.tar.gz -cd hts_engine_API-1.10 - -./configure --prefix=$COMPILE_PATH/hts_engine_api -make -make install - - -cd /usr/share/doc/festival/examples/ -sudo gunzip dumpfeats.gz - -sudo gunzip dumpfeats.sh.gz -sudo chmod a+rx /usr/share/doc/festival/examples/dumpfeats - - -cd $DOWNLOAD_PATH -cd ssn_hts_demo - -./configure --with-fest-search-path=/usr/share/doc/festival/examples --with-sptk-search-path=$COMPILE_PATH/sptk/bin/ --with-hts-search-path=$COMPILE_PATH/htk/bin/ --with-hts-engine-search-path=$COMPILE_PATH/hts_engine_api/bin/ - -sudo mv /usr/share/festival/radio_phones.scm /usr/share/festival/radio_phones.scm-old - -sudo cp $DOWNLOAD_PATH/ssn_hts_demo/radio_phones.scm /usr/share/festival/ - -sudo cp $DOWNLOAD_PATH/ssn_hts_demo/Slurp.pm /usr/share/perl5/File/ - -gcc scripts/tamil_trans.c -o scripts/tamil_trans - -#echo "FESTDIR=/usr" >> $HOME/.profile -#source $HOME/.profile - - -#comment the play audio file line on the complete script -sed -e '/play/ s/^#*/#/' -i $DOWNLOAD_PATH/ssn_hts_demo/scripts/complete - -#replace $FESTDIR to /usr as festival's path in ubuntu is /usr/bin/festival -perl -i -pe 's/\$FESTDIR/\/usr/g' $DOWNLOAD_PATH/ssn_hts_demo/scripts/complete diff --git a/tamil-tts.sh b/tamil-tts.sh new file mode 100755 index 0000000..1a1b677 --- /dev/null +++ b/tamil-tts.sh @@ -0,0 +1,197 @@ +#!/bin/bash +ROOT=$(git rev-parse --show-toplevel) +ROOT="${ROOT:-$(pwd)}" +BUILD="${ROOT}/build" +DOWNLOAD_PATH="${BUILD}"/packages +COMPILE_PATH="${BUILD}"/compiled +RUNDIR="${DOWNLOAD_PATH}"/ssn_hts_demo + +tamil_tts_setup() { + CURRENTDIR=$(pwd) + #Register here http://htk.eng.cam.ac.uk/download.shtml and get a username and password + HTKUSER=htkuserchennai + HTKPASSWORD=sgqY=t=M + + sudo apt-get install -y wget festival libx11-dev perl build-essential g++ csh gawk bc sox tcsh default-jre lame + + mkdir -p "${DOWNLOAD_PATH}" + mkdir -p "${COMPILE_PATH}" + + cd "${DOWNLOAD_PATH}" + if [[ ! -d ssn_hts_demo ]]; then + wget --no-check-certificate https://www.iitm.ac.in/donlab/tts/downloads/voices/hts23/ssn_hts_demo_Tamil_male.tgz + tar xvzf ssn_hts_demo_Tamil_male.tgz + fi + + cd "${DOWNLOAD_PATH}" + if [[ ! -d SPTK-3.10 ]]; then + wget --no-check-certificate https://nchc.dl.sourceforge.net/project/sp-tk/SPTK/SPTK-3.10/SPTK-3.10.tar.gz + tar xvzf SPTK-3.10.tar.gz + fi + cd SPTK-3.10 + ./configure --prefix="${COMPILE_PATH}"/sptk + make + make install + + cd "${DOWNLOAD_PATH}" + if [[ ! -d hts-htk ]]; then + mkdir hts-htk + fi + cd hts-htk + if [[ ! -f HTS-2.3_for_HTK-3.4.1.patch ]]; then + wget --no-check-certificate http://hts.sp.nitech.ac.jp/archives/2.3/HTS-2.3_for_HTK-3.4.1.tar.bz2 + tar xvjf HTS-2.3_for_HTK-3.4.1.tar.bz2 + fi + + cd "${DOWNLOAD_PATH}" + if [[ ! -d htk ]]; then + wget --no-check-certificate http://htk.eng.cam.ac.uk/ftp/software/HTK-3.4.1.tar.gz --user="${HTKUSER}" --password="${HTKPASSWORD}" + tar -zxvf HTK-3.4.1.tar.gz + fi + + if [[ ! -f htk/HTKLVRec/HLVRec.c ]]; then + wget --no-check-certificate http://htk.eng.cam.ac.uk/ftp/software/hdecode/HDecode-3.4.1.tar.gz --user="${HTKUSER}" --password="${HTKPASSWORD}" + tar -zxvf HDecode-3.4.1.tar.gz + fi + cd htk + patch --dry-run -s -N -p1 -d . < ../hts-htk/HTS-2.3_for_HTK-3.4.1.patch + if [[ "${?}" -eq 0 ]]; then + patch -s -N -p1 -d . < ../hts-htk/HTS-2.3_for_HTK-3.4.1.patch + fi + ./configure CFLAGS="-DARCH=linux" --prefix="${COMPILE_PATH}"/htk + make + make install + + cd "${DOWNLOAD_PATH}" + if [[ ! -d hts_engine_API-1.10 ]]; then + wget --no-check-certificate https://nchc.dl.sourceforge.net/project/hts-engine/hts_engine%20API/hts_engine_API-1.10/hts_engine_API-1.10.tar.gz + tar xvzf hts_engine_API-1.10.tar.gz + fi + cd hts_engine_API-1.10 + ./configure --prefix="${COMPILE_PATH}"/hts_engine_api + make + make install + + cd /usr/share/doc/festival/examples/ + if [[ ! -f dumpfeats ]]; then + sudo gunzip dumpfeats.gz + fi + if [[ ! -f dumpfeats.sh ]]; then + sudo gunzip dumpfeats.sh.gz + fi + sudo chmod a+rx /usr/share/doc/festival/examples/dumpfeats + + cd "${DOWNLOAD_PATH}" + cd ssn_hts_demo + if [[ ! -f /usr/share/festival/radio_phones.scm-old ]]; then + sudo mv /usr/share/festival/radio_phones.scm /usr/share/festival/radio_phones.scm-old + sudo cp "${DOWNLOAD_PATH}"/ssn_hts_demo/radio_phones.scm /usr/share/festival/ + fi + + if [[ ! -f /usr/share/perl5/File/Slurp.pm ]]; then + mkdir -p /usr/share/perl5/File + sudo cp "${DOWNLOAD_PATH}"/ssn_hts_demo/Slurp.pm /usr/share/perl5/File/ + fi + gcc scripts/tamil_trans.c -o scripts/tamil_trans + + #comment the play audio file line on the complete script + sed -i -e '/play/ s/^/#/' "${DOWNLOAD_PATH}"/ssn_hts_demo/scripts/complete + + #replace $FESTDIR to /usr as festival's path in ubuntu is /usr/bin/festival + sed -i -e 's:\$FESTDIR:/usr:g' "${DOWNLOAD_PATH}"/ssn_hts_demo/scripts/complete + + #make temp2 to point to input file + sed -i -e 's:^echo.*temp2$:cp $1 temp2:g' "${DOWNLOAD_PATH}"/ssn_hts_demo/scripts/complete + + cd "${CURRENTDIR}" + echo "installation completed" +} + +tamil_tts_run() { + if [[ -z "${SOURCE}" ]]; then + echo "${USAGE}" + exit 1 + fi + + if [[ -z "${OUTPUT}" ]]; then + OUTPUT="${SOURCE%.*}.wav" + fi + + SOURCE=$(readlink -f "${SOURCE}") + OUTPUT=$(readlink -f "${OUTPUT}") + MP3OUTPUT="${OUTPUT%.*}.mp3" + CURRENTDIR=$(pwd) + + rm -f "${OUTPUT}" "${MP3OUTPUT}" + cp -fra "${RUNDIR}" "${RUNDIR}_${RUNID}" + RUNDIR="${RUNDIR}_${RUNID}" + cd "${RUNDIR}" + ./configure --with-fest-search-path=/usr/share/doc/festival/examples --with-sptk-search-path="${COMPILE_PATH}"/sptk/bin/ --with-hts-search-path="${COMPILE_PATH}"/htk/bin/ --with-hts-engine-search-path="${COMPILE_PATH}"/hts_engine_api/bin/ + ./scripts/complete "${SOURCE}" linux + cd "${CURRENTDIR}" + if [[ $(stat -c '%s' "${RUNDIR}"/wav/1.wav) -eq 0 ]]; then + echo "output file genertion failed" 1>&2 + rm -fr "${RUNDIR}" + exit 1 + fi + + cp "${RUNDIR}"/wav/1.wav "${OUTPUT}" + rm -fr "${RUNDIR}" + + if [[ "${MP3}" -eq 1 ]]; then + lame "${OUTPUT}" "${MP3OUTPUT}" + rm -f "${OUTPUT}" + fi +} + +tamil_tts_clean() { + rm -fr "${BUILD}" +} + +USAGE="[usage] + ${0} --clean + ${0} --setup + ${0} --run [--runid id] [--gen-mp3] [--output outputfile ] --source sourcefile + ${0} -h|--help +" + +ARGS=$(getopt -o h -l clean,setup,run,gen-mp3,runid:,source:,output:,help -n "${0}" -- "${@}") +if [[ ! "${?}" -eq 0 ]]; then + echo "failed parse options" 1>&2 + exit 1 +fi + +eval set -- "${ARGS}" +CLEAN=0 +SETUP=0 +RUN=0 +MP3=0 +RUNID="${$}" +SOURCE="" +OUTPUT="" + +while true; do + case "${1}" in + --clean) CLEAN=1; shift;; + --setup) SETUP=1; shift;; + --run) RUN=1; shift;; + --gen-mp3) MP3=1; shift;; + --runid) RUNID="${2}"; shift 2;; + --source) SOURCE="${2}"; shift 2;; + --output) OUTPUT="${2}"; shift 2;; + --) shift; break;; + *) echo "${USAGE}"; exit 1;; + esac +done + +if [[ "${CLEAN}" -eq 1 ]]; then + tamil_tts_clean +fi + +if [[ "${SETUP}" -eq 1 ]]; then + tamil_tts_setup +fi + +if [[ "${RUN}" -eq 1 ]]; then + tamil_tts_run +fi