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.


By Luke Alderton at 23 Dec 2013, 23:01 PM

Tags: Robot,Java

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 dipbleds on Raspberry Pi - Bluetooth using Bluecove on Raspbian
12 Dec 2017, 21:29 PM
By Ich on Replacing the Xamarin Header/Navigation bar with a custom view/template
26 Nov 2017, 17:11 PM
By Ravi Motha on My experience at Umbraco UK Festival 2017
12 Dec 2017, 08:39 AM
By Borges on How to add a Xamarin Forms Loading Screen/Overlay
7 Nov 2017, 19:11 PM
By Rutul Mehta on Auto/Custom height on Xamarin Forms WebView for Android and iOS
4 Nov 2017, 03:15 AM
By Pablo on Xamarin MasterDetailPage has large margin/padding at top
26 Oct 2017, 15:31 PM
By faiza on Using MaryTTS or OpenMary in Java
22 Oct 2017, 12:54 PM
By Nietoperz on Using MaryTTS or OpenMary in Java
29 Sep 2017, 14:34 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development