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
ever tried to change the audioeffects? Like Robot ?`
28/11/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 jack of ass on Replacing the Xamarin Header/Navigation bar with a custom view/template
16 Feb 2019, 03:13 AM
By Zal on Xamarin MasterDetailPage has large margin/padding at top
7 Feb 2019, 12:20 PM
By AndrewEcopE1 on MVC forms in Umbraco
7 Feb 2019, 01:16 AM
By AndrewEcopE1 on MVC forms in Umbraco
4 Feb 2019, 23:53 PM
By Ramachandran on Reducing Umbraco memory usage by enabling 32-bit applications
4 Feb 2019, 17:39 PM
By encoderu9 on MVC forms in Umbraco
4 Feb 2019, 10:51 AM
By AndrewEcopE1 on MVC forms in Umbraco
28 Jan 2019, 19:48 PM
By Luca Ziegler on Xamarin Forms app not updating after deploy
25 Jan 2019, 11:00 AM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development