[mary-users] client Java application

Ingmar Steiner ingmar.steiner at inria.fr
Wed Feb 22 09:38:53 CET 2012


Dear Nikolai,

further to Marc's response, here is some general advice to solve issues 
like this.

You should set the Mary server's logging level to DEBUG and pay close 
attention to what is logged when you send your request, since that will 
allow you to understand exactly what is going wrong.

To take it a step further, I would recommend debugging it in your IDE. 
You should be able to start both your application and the Mary server 
with a debugger attached, and inspect the relevant variables at 
well-placed breakpoints in either thread (see stacktrace).

Best wishes,

-Ingmar

On 22.02.2012 09:36, Marc Schroeder wrote:
> Hi,
>
> make sure to ask for a locale + voice that is actually installed on your
> local MARY TTS server.
>
> Best,
> Marc
>
> On 22.02.12 05:40, Nikolai Kouznetsov wrote:
>>
>> Hello,
>>
>> I am trying to see how I can run the TTS engine from within my Java
>> application. To do this, I started with an example provided on MARy's
>> website. When cling.dfki.uni-sb.de server is psecified, the clients
>> works - it generates an utterance and plays it. When I use localhost, it
>> does not work for me. When I run the provide maryclient from the bin
>> directory it prodeuces the following:
>>
>> java version "1.6.0_30"
>> Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
>> Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)
>> Mary TTS client 4.3.0 (impl. 20101220)
>> Connected to localhost:59125, Mary TTS server 4.3.0 (impl. 20101220)
>>
>>
>> So, it looks like the maryclient can work with the localhost.
>>
>>
>>
>>
>> Please see the code and the generated output below.
>>
>> ========================== modified code code ===================
>>
>> import java.io.ByteArrayInputStream;
>> import java.io.ByteArrayOutputStream;
>> import javax.sound.sampled.AudioInputStream;
>> import javax.sound.sampled.AudioSystem;
>> import javax.sound.sampled.LineEvent;
>> import javax.sound.sampled.LineListener;
>>
>> import marytts.client.MaryClient;
>> import marytts.client.http.Address;
>> import marytts.util.data.audio.AudioPlayer;
>>
>>
>> public class MaryTTSClientExample {
>>
>> public static void main(String[] args) throws Exception
>> {
>> String serverHost = System.getProperty("server.host", "localhost");
>> int serverPort = Integer.getInteger("server.port", 59125).intValue();
>> MaryClient mary = MaryClient.getMaryClient(new Address(serverHost,
>> serverPort));
>> String text = "Willkommen in der Welt der Sprachsynthese!";
>> String locale = "de"; // or US English (en-US), Telugu (te), Turkish
>> (tr), ...
>> String inputType = "TEXT";
>> String outputType = "AUDIO";
>> String audioType = "WAVE";
>> String defaultVoiceName = null;
>> ByteArrayOutputStream baos = new ByteArrayOutputStream();
>> mary.process(text, inputType, outputType, locale, audioType,
>> defaultVoiceName, baos);
>> // The byte array constitutes a full wave file, including the headers.
>> // And now, play the audio data:
>> AudioInputStream ais = AudioSystem.getAudioInputStream(
>> new ByteArrayInputStream(baos.toByteArray()));
>> LineListener lineListener = new LineListener() {
>> public void update(LineEvent event) {
>> if (event.getType() == LineEvent.Type.START) {
>> System.err.println("Audio started playing.");
>> } else if (event.getType() == LineEvent.Type.STOP) {
>> System.err.println("Audio stopped playing.");
>> } else if (event.getType() == LineEvent.Type.OPEN) {
>> System.err.println("Audio line opened.");
>> } else if (event.getType() == LineEvent.Type.CLOSE) {
>> System.err.println("Audio line closed.");
>> }
>> }
>> };
>>
>> AudioPlayer ap = new AudioPlayer(ais, lineListener);
>> ap.start();
>> }
>>
>> }
>>
>> ===================== the end of modified code
>> =================================
>>
>>
>> %%%%%%%%%%%%%%%%%%%% output %%%%%%%%%%%%%%%%%%%%
>>
>> C:\JavaCenter\JavaProjects\MaryTTSExample>java MaryTTSClientExample
>> Mary TTS client 4.3.0 (impl. 20101220)
>> Connected to localhost:59125, Mary TTS server 4.3.0 (impl. 20101220)
>> Exception in thread "main" java.io.IOException: Server returned HTTP
>> response code: 500 for URL: http://localhost:59125/process
>> at
>> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
>>
>> at
>> marytts.client.http.MaryHttpClient.requestInputStream(MaryHttpClient.java:435)
>>
>> at marytts.client.http.MaryHttpClient._process(MaryHttpClient.java:481)
>> at marytts.client.MaryClient.process(MaryClient.java:661)
>> at marytts.client.MaryClient.process(MaryClient.java:668)
>> at MaryTTSClientExample.main(MaryTTSClientExample.java:29)
>>
>>
>>
>>
>>
>> =================== original code =========================
>> import java.io.ByteArrayInputStream;
>> import java.io.ByteArrayOutputStream;
>>
>> import javax.sound.sampled.AudioInputStream;
>> import javax.sound.sampled.AudioSystem;
>> import javax.sound.sampled.LineEvent;
>> import javax.sound.sampled.LineListener;
>>
>> import marytts.client.MaryClient;
>> import marytts.client.http.Address;
>> import marytts.util.data.audio.AudioPlayer;
>>
>>
>> public class MaryTTSClientExample {
>>
>> public static void main(String[] args) throws Exception
>> {
>> String serverHost = System.getProperty("server.host",
>> "cling.dfki.uni-sb.de");
>> //String serverHost = System.getProperty("server.host", "localhost");
>> int serverPort = Integer.getInteger("server.port", 59125).intValue();
>> MaryClient mary = MaryClient.getMaryClient(new Address(serverHost,
>> serverPort));
>> String text = "Willkommen in der Welt der Sprachsynthese!";
>> String locale = "de"; // or US English (en-US), Telugu (te), Turkish
>> (tr), ...
>> String inputType = "TEXT";
>> String outputType = "AUDIO";
>> String audioType = "WAVE";
>> String defaultVoiceName = null;
>> ByteArrayOutputStream baos = new ByteArrayOutputStream();
>> mary.process(text, inputType, outputType, locale, audioType,
>> defaultVoiceName, baos);
>> // The byte array constitutes a full wave file, including the headers.
>> // And now, play the audio data:
>> AudioInputStream ais = AudioSystem.getAudioInputStream(
>> new ByteArrayInputStream(baos.toByteArray()));
>> LineListener lineListener = new LineListener() {
>> public void update(LineEvent event) {
>> if (event.getType() == LineEvent.Type.START) {
>> System.err.println("Audio started playing.");
>> } else if (event.getType() == LineEvent.Type.STOP) {
>> System.err.println("Audio stopped playing.");
>> } else if (event.getType() == LineEvent.Type.OPEN) {
>> System.err.println("Audio line opened.");
>> } else if (event.getType() == LineEvent.Type.CLOSE) {
>> System.err.println("Audio line closed.");
>> }
>> }
>> };
>>
>> AudioPlayer ap = new AudioPlayer(ais, lineListener);
>> ap.start();
>> }
>>
>> }
>>
>> ==================== the end of the original code
>> =============================
>>
>>
>>
>> %%%%%%%%%%%%%% output %%%%%%%%%%%%%%%%%%%%%
>>
>> C:\JavaCenter\JavaProjects\MaryTTSExample>java MaryTTSClientExample
>> Mary TTS client 4.3.0 (impl. 20101220)
>> Connected to cling.dfki.uni-sb.de:59125, Mary TTS server 4.3.0 (impl.
>> 20101220)
>> Audio line opened.
>> Audio started playing.
>> Audio stopped playing.
>> Audio line closed.
>>
>> Please advise. I would like to understand why you client code does not
>> work if I specify localhost as the name of the sever.
>>
>> My best regards,
>> Nikolai
>>
>>
>>
>

-- 
Ingmar Steiner
Postdoctoral Researcher

LORIA Speech Group, Nancy, France
National Institute for Research in
Computer Science and Control (INRIA)


More information about the Mary-users mailing list