Maryspeak a command line wrapper for MaryTTS

This project and the documentation from my blog is now hosted on GitHub the links in the post have been changed accordingly.

What is Maryspeak

I’ve been inspired by Ken Fallon via Hacker Public Radio to write maryspeak; a small java program  to make the core features of Mary Text To Speech  readily accessible as a shell command. The aim of maryspeak is to reduce the friction for Linux shell users to use MaryTTS. It accepts text input via the command line, via a file or via stdin, processes it using MaryTTS, then outputs speech via sound, to a file, or to stdout. It also allows for the selection of a voice and/or a MaryTTS server.

MaryTTS is written in Java and the UI is not transparently accessible to the Linux command line. maryspeak is a wrapper around the MaryInterface classes used by the MaryTTS Java and http clients. Because its written in Java there is no reason this cannot also be on a Windows system, but the command switches are closer to the GNU conventions.

Installing Maryspeak

This installation assumes Debian but the same principles will apply to other distros.

  • Install MaryTTS (see my previous post Marytts Voice Synthesizer How-To for Debian)
  • Download the maryspeak.jar from here or download the source to build it for yourself here
  • Copy the maryspeak.jar file to the MaryTTS library
    $ sudo cp maryspeak.jar /opt/marytts-5.1/lib
  • Create an alias to provide a nice clean usable command. In Debian add the following line to the .bash_aliases file, create the file if it does not already exist.
    alias maryspeak='java -cp "/opt/marytts-5.1/lib/*" -Dmary.base=/opt/marytts-5.1 maryspeak.Maryspeak'
  • Log out of your session and log back in to pick up the new alias, alternately you can source the .bashrc to refresh the session
    $ source ~/.bashrc

Using Maryspeak

You can use maryspeak standalone or against a MaryTTS server.

  • For the simplest demonstration of maryspeak working, it can speak an internal default phrase by using the –default parameter
  • $ maryspeak --default
  • Say what you want by just appending your text to the command. The full stop at the end is required, else for some reason the speech is too slow.
    $ maryspeak This is a short statement from your computer.
  • If you wish to process the speech on a MaryTTS server use the –host=servername parameter. If your server is on the local machine you can just use –host. It is even possible use the MaryTTS demo server with –host=mary.dfki.de
    $ maryspeak --host You will need to run the MaryTTS Server locally to hear this spoken.
  • Show the full Maryspeak usage instructions with -h or –help
    $ maryspeak --help

Further Exploration/Exploitation of MaryTTS

Maryspeak only offers a subset of the functionality of MaryTTS. Maryspeak is also not using the streaming capabilities of the MaryTTS library, so processes things in series: gather input, process the input, then output audio.

MaryTTS has a rich depth of functionality beyond that used by Maryspeak. For serious use I would recommend investigating this.

MaryTTS can be used directly from command line if required via:

$ java -cp "classpath" [properties] marytts.client.http.MaryHttpClient [inputfile]

Assuming MaryTTS is installed as per my previous post, the instructions for usage of this class can be obtained by compiling and running the following java class:

public class ShowUsage {
    public static void main(String[] args) {
    marytts.client.http.MaryHttpClient.usage();
    }
}

For your convenience I have done this, for MaryTTS version 5.1, this is the output:

usage:
 java [properties] marytts.client.http.MaryHttpClient [inputfile]
Properties are: -Dinput.type=INPUTTYPE
                -Doutput.type=OUTPUTTYPE
                -Dlocale=LOCALE
                -Daudio.type=AUDIOTYPE
                -Dvoice.default=male|female|de1|de2|de3|...
                -Dserver.host=HOSTNAME
                -Dserver.port=PORTNUMBER
 where INPUTTYPE is one of TEXT, RAWMARYXML, TOKENS, WORDS, POS,
 PHONEMES, INTONATION, ALLOPHONES, ACOUSTPARAMS or MBROLA,
 OUTPUTTYPE is one of TOKENS, WORDS, POS, PHONEMES,
 INTONATION, ALLOPHONES, ACOUSTPARAMS, MBROLA, or AUDIO,
 LOCALE is the language and/or the country (e.g., de, en_US);
 and AUDIOTYPE is one of AIFF, AU, WAVE, MP3, and Vorbis.
 The default values for input.type and output.type are TEXT and AUDIO,
 respectively; default locale is en_US; the default audio.type is WAVE.
inputfile must be of type input.type.
 If no inputfile is given, the program will read from standard input.
The output is written to standard output, so redirect or pipe as appropriate.

So for a quick demo try putting some text into a file test.txt (use a full stop at the end of your text or Mary speaks slowly for some reason) then run:

$ java -cp "/opt/marytts-5.1/lib/*" marytts.client.http.MaryHttpClient test.txt | aplay

Note: that the output is piped into aplay which can play back a .wav stream. If you don’t have aplay installed you can > output to a file.wav to play later.

Much more can be done using the full MaryTTS libraries within a Java program.

One thought on “Maryspeak a command line wrapper for MaryTTS

Leave a Reply

Your email address will not be published. Required fields are marked *