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 23 Dec 2013, 23:01 PM
Tags: Robot,Java