[mary-users] client Java application

Marc Schroeder marc.schroeder at dfki.de
Wed Feb 22 09:36:10 CET 2012


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
>
>
>

-- 
Dr.-Ing. Dr. phil. Marc Schröder, Senior Researcher at DFKI GmbH
Homepage: http://www.dfki.de/~schroed
Email: marc.schroeder at dfki.de
Phone: +49-681-85775-5303
Postal address: DFKI GmbH, Campus D3_2, Stuhlsatzenhausweg 3, D-66123 
Saarbrücken, Germany
--
Official DFKI coordinates:
Deutsches Forschungszentrum fuer Kuenstliche Intelligenz GmbH
Trippstadter Strasse 122, D-67663 Kaiserslautern, Germany
Geschaeftsfuehrung:
Prof. Dr. Dr. h.c. mult. Wolfgang Wahlster (Vorsitzender)
Dr. Walter Olthoff
Vorsitzender des Aufsichtsrats: Prof. Dr. h.c. Hans A. Aukes
Amtsgericht Kaiserslautern, HRB 2313


More information about the Mary-users mailing list