Automatic Dubbing Shell Script

Search and find cool Voicepacks, Sounds and Music or show us your own ones!
Post Reply
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Automatic Dubbing Shell Script

Post 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!
Attachments
example.zip
An example of the TTS, with many infamous video game lines.
(1.3 MiB) Downloaded 68 times
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
papercoffee
Godlike
Posts: 10443
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Automatic Dubbing Shell Script

Post by papercoffee »

Uhm... and what does it have to do with UT?
User avatar
OjitroC
Godlike
Posts: 3605
Joined: Sat Sep 12, 2015 8:46 pm

Re: Automatic Dubbing Shell Script

Post by OjitroC »

Not a lot but one of the examples is a few lines from the UT announcer converted from text to speech.
User avatar
papercoffee
Godlike
Posts: 10443
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: Automatic Dubbing Shell Script

Post by papercoffee »

I'm undecided if this belongs here or into off-topic ...or coding. :noidea
User avatar
OjitroC
Godlike
Posts: 3605
Joined: Sat Sep 12, 2015 8:46 pm

Re: Automatic Dubbing Shell Script

Post 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).
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: Automatic Dubbing Shell Script

Post 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.
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
User avatar
Feralidragon
Godlike
Posts: 5489
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Automatic Dubbing Shell Script

Post 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.
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Automatic Dubbing Shell Script

Post 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'>
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Re: Automatic Dubbing Shell Script

Post 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.
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
Post Reply