Page 1 of 1

Automatic Dubbing Shell Script

Posted: Mon Feb 19, 2018 9:56 pm
by Gustavo6046
I've been lately working in a cool shell script that automatically batch converts a folder full of text (.txt) files into wave (.wav) files using SVOX' Pico TTS, or rather, its Linux distribution (which doesn't sound any natural either).

ADSS (Automatic Dubbing Shell Script) was made for a structured, user-friendliness-aimed Text-To-Speech conversion of many different "dubs" at once, in a Linux environment, with the only dependency being the libttspico-utils package (and its subdependencies if any).

Code: Select all

#!/bin/bash
# (C)2018 Gustavo 'Gustavo6046' Rehermann. The MIT license.
# (C) SVOX. All rights reserved.    (right?)

echo # Blank lines are good for the eye!

depcheckees=("pico2wave")
dependencies=("libttspico-utils") # used for dependency check

checkpkg() {
    if [[ $(dpkg-query -W -f='${Status}' $1) == "ok installed" ]]; then
        return 0

    else
        return 1

    fi
}

installdeps() {
    echo "At least one dependency was not found!"
    echo "Do you want to install them automatically"
    echo "using apt-get? (y/n)"
    read -p ":" -n1 -r
    echo
    echo

    if [[ $REPLY =~ ^[Yy]$ ]]; then
        echo "  > Updating package list..."
        echo
        apt-get update -y

        echo
        echo
        echo "  > Done. Installing missing dependencies..."
        echo

        for dep in "${dependencies}"; do
            if ! checkpkg $dep; then
                echo " + ${dep}"
                apt-get install -y $dep

            fi
        done

    else
        echo "Missing dependencies: aborting."
        exit

    fi
}

depcheck() {
    for dep in "${depcheckees}"; do
        if ! which $dep >/dev/null; then
            installdeps
            break

        fi
    done
}

depcheck

convert() {
    if [[ -f "$1" ]]; then
        fn=$(basename $1 | sed "s/\.[^.]*$//")
        pico2wave -l=en-US -w="./out/${fn}.wav" "$(<"$1")"
        echo "$1 converted to ./out/${fn}.wav successfully."

    else
        echo "$1 not found! Ignoring."

    fi
}

forcehelp() {
    (
        echo "ADSS (Automatic Dubbing Shell Script) is a simple"
        echo "script program that automatizes text to"
        echo "speech, by taking a dubbing list (dubs.txt"
        echo "in the current directory), and convert all"
        echo "the listed dubs into WAV files in the output"
        echo "folder."
        echo
        echo "Using it isn't too difficult:"
        echo
        echo "   1.  Create two folders which you want to"
        echo "       set up:"
        echo
        echo "       * ./dubs/ contains all the text files"
        echo "         you want to convert."
        echo "       * ./out/ will contain all the audio"
        echo "         output you'll eventually get."
        echo
        echo "   2.  Place all the text files you want to"
        echo "       convert into the dubs/ folder, and"
        echo "       list all of their filenames (without"
        echo "       extension!!) into dubs.txt (in the"
        echo "       current folder). You might want to"
        echo "       use a listing command like ls for"
        echo "       this."
        echo
        echo "   3. Run this script!"
        echo
        echo "You can also modify the text files later on"
        echo "and rerun this script just fine."
        echo
        echo "Alternatively to creating the dubs.txt list,"
        echo "you can simply convert all the files inside the"
        echo "input folder!"
        echo
        echo "(C)2018 Gustavo 'Gustavo6046' Rehermann. The MIT license."
        echo "(C) SVOX. All rights reserved.   (right?)"
        echo

    ) | more
}

help() {
    if [[ -t 1 ]]; then
        echo "Do you want help? (y/n)"
        read -p ":" -n1 -r
        echo

        if [[ $REPLY =~ ^[Yy]$ ]]; then
            forcehelp

        fi
    fi
}

errhelp() {
    echo "$1"
    echo
    help
}

if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
    forcehelp
    exit

fi

if [[ ! -d "./dubs/" ]] || [[ ! -d "./out/" ]]; then
    echo "Either the input (dubs/) or output (out/)"
    echo "directory is missing! Do you want the script"
    echo "to make them for you? (y/n)"
    read -p ":" -n1 -r
    echo
    echo

    if [[ $REPLY =~ ^[Yy]$ ]]; then
        mkdir -p dubs
        mkdir -p out

        echo "Directories were succesfully created."
        echo "Consider re-running the script once"
        echo "you're set up (accept some help for"
        echo "more details!)."

    fi

    echo
    help
    exit
fi

if [[ ! -f dubs.txt ]]; then
    echo "No dubbing list found!"
    echo
    echo "Do you want the script to convert all the files"
    echo "inside the input folder automatically for you? (y/n)"
    read -p ":" -n1 -r
    echo
    echo

    if [[ $REPLY =~ ^[Yy]$ ]]; then
        echo "Converting every input file."

        for p in ./dubs/*; do if [[ -f "$p" ]]; then
            convert "$p"

        fi; done

    else
        help
        exit

    fi

else
    while read -r p; do
        convert "./dubs/$p"

    done <dubs.txt

fi

echo
I have attached a few examples, enjoy!

Re: Automatic Dubbing Shell Script

Posted: Mon Feb 19, 2018 11:19 pm
by papercoffee
Uhm... and what does it have to do with UT?

Re: Automatic Dubbing Shell Script

Posted: Mon Feb 19, 2018 11:46 pm
by OjitroC
Not a lot but one of the examples is a few lines from the UT announcer converted from text to speech.

Re: Automatic Dubbing Shell Script

Posted: Tue Feb 20, 2018 12:14 am
by papercoffee
I'm undecided if this belongs here or into off-topic ...or coding. :noidea

Re: Automatic Dubbing Shell Script

Posted: Tue Feb 20, 2018 12:43 am
by OjitroC
papercoffee wrote:I'm undecided if this belongs here or into off-topic ...or coding. :noidea
Certainly not coding - possibly here as it does have something to do with UT Sounds or possibly (more appropriate?) off-topic as only one of the 11 examples actually contains UT sounds (the rest are from other games).

Re: Automatic Dubbing Shell Script

Posted: Tue Feb 20, 2018 1:00 am
by Gustavo6046
I've been measuring the value of such an utility in the Unreal Tournament modding scenario, creating new voices for the announcer, characters, and other game events. It isn't large, but it is considerable, and would be helpful oftentimes.

Re: Automatic Dubbing Shell Script

Posted: Tue Feb 20, 2018 1:16 pm
by Feralidragon
A text-to-speech is useful and sounds great if well used.

I already used text-to-speech myself in NW3 for instance: the female "nuclear warning" announcer that you hear, announcing the nuclear level threat and all, was made through a text-to-speech app.
Although back then I put an abnormal amount of punctuation (lots of commas and all) so I could really get the tone and pauses in speech that I wanted, and adding to this I edited the generated sound itself afterwards to sound more natural and UT-announcer-like.

Re: Automatic Dubbing Shell Script

Posted: Fri Mar 02, 2018 6:24 pm
by Aldebaran
Thank you for your shell script, Gustavo6046.
Can i switch between male and female voice?
Also the sound quality isn't that good. How can I record them better?
I found out that if you put these two parameters into the text file you can manipulate volume and pitch:
<volume level='50'><pitch level='110'>

Re: Automatic Dubbing Shell Script

Posted: Sun May 27, 2018 5:46 pm
by Gustavo6046
Aldebaran wrote:Can I switch between male and female voice?
I am planning to add -g/--gender, but first I need to figure out how to do so with libttspico.