Using MaryTTS or OpenMary in Java

So now I've started another project (Again). This ones called Aimie and happens to be a robot with an AI coded in Java.

For the voice portion of Aimie, I needed a voice synthesiser that sounded good but I also didnt want to reinvent the wheel, so I'm using a free TTS client/server called MaryTTS or OpenMary.

I've found there's not much documentation for getting a standalone mary server/client running in your own application. The good news? It's easier than you thought.

Take a look at the code below to get an idea of what I mean:

package Speech;

import javax.sound.sampled.AudioInputStream;
import marytts.LocalMaryInterface;
import marytts.MaryInterface;
import marytts.exceptions.MaryConfigurationException;
import marytts.exceptions.SynthesisException;
import marytts.util.data.audio.AudioPlayer;

public class Voice
{
    private MaryInterface marytts;
    private AudioPlayer ap;
            
    public Voice(String voiceName)
    {
        try
        {
            marytts = new LocalMaryInterface();
            marytts.setVoice(voiceName);
            ap = new AudioPlayer();
        }
        catch (MaryConfigurationException ex)
        {
            ex.printStackTrace();
        }
    }
    
    public void say(String input)
    {
        try
        {
            AudioInputStream audio = marytts.generateAudio(input);
            
            ap.setAudio(audio);
            ap.start();
        }
        catch (SynthesisException ex)
        {
            System.err.println("Error saying phrase.");
        }
    }
}

As you can see, you only have to set up a 'LocalMaryInterface' to get all the benefits of Mary.

Ignore all the people saying you need a server but beware, the startup time can be a few seconds.


Published at

Tags: Robot,Java

Luke Alderton

Comments

Danilo de sousa
how was the implementation of LocalMaryInterface, followed some kind of marytts?
22/04/2015
Luke
What do you mean by followed?
22/04/2015
Danilo
has adapted some MaryTTS class to create the LocalMaryInterface?
22/04/2015
Luke
Nope, it is part of marytts.
22/04/2015
Ben
Hi Luke, im playing around with the marytts runtime. everything is working well as it seemt to be for you. The only thing i cant get to work are setting different audioeffects like Robot or whisper. Can you help ? :)
28/11/2015
Luke
Hi Ben, unfortunately I haven't used audio effects within my setup, sorry.
29/11/2015
Ben
Oh, that is a pity. Thanks for your fast respond.
01/12/2015
Nietoperz
This requires a running Mary server.
29/09/2017
faiza
how can i setup LocalMaryInterface?
22/10/2017
Post a comment
Sit tight...
We're adding your comment.
Thank you.
Your comment has been added.
There's been a problem.
Please try again later.
Share with
Tags
Latest Comments
By Helenpaups on MVC forms in Umbraco
23 May 2018, 16:48 PM
By Helenpaups on MVC forms in Umbraco
23 May 2018, 13:46 PM
By AkikoTax on MVC forms in Umbraco
20 May 2018, 06:41 AM
By Klaus on MVC forms in Umbraco
17 May 2018, 10:47 AM
By Archie on MVC forms in Umbraco
16 May 2018, 18:52 PM
By w on JQuery Unobtrusive Validation for dynamically created elements
11 May 2018, 02:00 AM
By Luke on Umbraco using Global.asax to handle events before the Request Handler.
27 Apr 2018, 18:28 PM
By Janine Gardiola on Umbraco using Global.asax to handle events before the Request Handler.
26 Apr 2018, 11:18 AM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development