MaryTTS to playSample

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

Ria09
New User
Posts: 9
Joined: Fri Apr 14, 2017 3:38 pm

MaryTTS to playSample

Postby Ria09 » Sun May 14, 2017 6:37 pm

I wrote a remote program which is run from a PC. It should say "I am a robot!" using MaryTTS, but I am having trouble playing the sound using playSample. Here's the code:

Code: Select all

package test;
import java.io.InputStream;
import java.util.Set;
import java.util.logging.Logger;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;

import org.apache.commons.io.IOUtils;
import org.jfree.util.Log;

import marytts.LocalMaryInterface;
import marytts.MaryInterface;
import marytts.util.data.audio.AudioPlayer;
import lejos.*;
import lejos.remote.ev3.RMIRemoteAudio;
import lejos.remote.ev3.RemoteEV3;
import lejos.hardware.BrickFinder;
import lejos.hardware.Sound;
public class Txt2Wav {

   public static RemoteEV3 ev3 = (RemoteEV3) BrickFinder.getDefault();
   public static void main(String[] args) throws Exception {
      
      MaryInterface marytts = new LocalMaryInterface();
      Set<String> voices = marytts.getAvailableVoices();
      marytts.setVoice(voices.iterator().next());
        System.out.println("Start");
      InputStream audio = marytts.generateAudio("I am a robot!");
      byte[] baudio = IOUtils.toByteArray(audio);
      Sound.playSample(baudio, 0, baudio.length, 15000, 100);
        System.out.println("Stop");
      System.exit(0);
   }
   
}

User avatar
gloomyandy
leJOS Team Member
Posts: 5899
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: MaryTTS to playSample

Postby gloomyandy » Sun May 14, 2017 7:57 pm

So what happens? What format will the audio be generated in? How large is the output array? Note that only 8bit samples are supported by playSample. Also note that I no idea if this call is supported by the remote interface.

Oh and when asking for help, please be sure to tell us what version of leJOS you are using, also in the case of remote programs please provide details of how the EV3 is connected to your PC.
leJOS news https://lejosnews.wordpress.com/

Ria09
New User
Posts: 9
Joined: Fri Apr 14, 2017 3:38 pm

Re: MaryTTS to playSample

Postby Ria09 » Mon May 15, 2017 4:55 am

Sorry, I didn't know that I have to tell my leJOS version. My version is:
  • leJOS version:9.0.1-beta
  • Menu version: 0.9.1
And the EV3 is connected to PC using Edimax N150 Nano Adapter(a WIFI adapter).
1) Nothing
2) Don't know, but now I converted it:

Code: Select all

AudioInputStream audio = marytts.generateAudio("I am a robot!");
        AudioFormat aformat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 8000, 8, 1, 1, 8000, false);
        AudioInputStream lowResAIS = AudioSystem.getAudioInputStream(aformat, audio);
        AudioPlayer player = new AudioPlayer(lowResAIS);
      player.start();
      player.join();
      

And tested it on my PC and it works, so the Audio format is not corrupt.
3) The audio array is "I am a robot!", so I think it is 12.
4)This works:

Code: Select all

package test;
import java.io.InputStream;
import java.util.Set;
import java.util.logging.Logger;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;

import org.apache.commons.io.IOUtils;
import org.jfree.util.Log;

import marytts.LocalMaryInterface;
import marytts.MaryInterface;
import marytts.util.data.audio.AudioPlayer;
import lejos.*;
import lejos.remote.ev3.RMIRemoteAudio;
import lejos.remote.ev3.RemoteEV3;
import lejos.hardware.BrickFinder;
import lejos.hardware.Sound;
public class Txt2Wav {

   public static RemoteEV3 ev3 = (RemoteEV3) BrickFinder.getDefault();
   public static void main(String[] args) throws Exception {
      Sound.twoBeeps(); //This Works
      System.exit(0);
   }

}

So it's not the PC-EV3 a communication problem, and Sound.twoBeeps(); works so I think it is supported by leJOS.
I think the problem is the conversion to byte array. I made a few modifications:

Code: Select all

package test;

import java.io.InputStream;
import java.util.Set;
import java.util.logging.Logger;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;

import org.apache.commons.io.IOUtils;
import org.jfree.util.Log;

import marytts.LocalMaryInterface;
import marytts.MaryInterface;
import marytts.util.data.audio.AudioPlayer;
import lejos.*;
import lejos.remote.ev3.RMIRemoteAudio;
import lejos.remote.ev3.RemoteEV3;
import lejos.utility.Delay;
import lejos.hardware.BrickFinder;
import lejos.hardware.Sound;

public class Txt2Wav
{

   public static RemoteEV3 ev3 = (RemoteEV3) BrickFinder.getDefault();

   public static void main(String[] args) throws Exception
   {

      MaryInterface marytts = new LocalMaryInterface();
      Set<String> voices = marytts.getAvailableVoices();
      marytts.setVoice(voices.iterator().next());
      AudioInputStream audio = marytts.generateAudio("I am a robot!");
      AudioFormat aformat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 8000, 8, 1, 1, 8000, false);
      AudioInputStream lowResAIS = AudioSystem.getAudioInputStream(aformat, audio);
      System.out.println("PC Start");
      AudioPlayer player = new AudioPlayer(lowResAIS);
      player.start();
      player.join();
      System.out.println("PC Stop");
      Delay.msDelay(1000);
      System.out.println("EV3 Start");
      byte[] baudio = IOUtils.toByteArray(lowResAIS);
      Sound.playSample(baudio, 0, baudio.length, 15000, 100);
      System.out.println("EV3 Stop");
      Delay.msDelay(1000);
      System.out.println("EV3 Audio Test Start");
      Sound.twoBeeps(); // This Works
      System.out.println("EV3 Audio Test Stop");
   }

}

User avatar
gloomyandy
leJOS Team Member
Posts: 5899
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: MaryTTS to playSample

Postby gloomyandy » Mon May 15, 2017 7:50 am

I was asking how big the array of samples is (in your original code this was baudio), are you actually getting any samples to play?

Just because twoBeeps works does not mean that there is not some sort of remote API issue. In the case of beep very little data needs to be transferred, in the case of playSample the sample array will need to be transferred and this is likely to be make thousands of bytes (15,000 per second of audio).

Looking at your new code, you seem to be encoding the output with 8000 samples per sec, but when you ask the EV3 to play it back you specify 15000 samples per second. I doubt if this is your problem but it will not help. Your code also seems to be reusing the the stream lowResAIS once to play it back and then again to turn it into a byte array, can you do this? Normally a stream has the notion of a current position and so playing it will move that position to the end. I think the first thing you need to do is check to see if your call to toByteArray is actually returning any actual samples.
leJOS news https://lejosnews.wordpress.com/

Ria09
New User
Posts: 9
Joined: Fri Apr 14, 2017 3:38 pm

Re: MaryTTS to playSample

Postby Ria09 » Tue Jun 20, 2017 7:51 pm

Sorry that I haven't replied faster (I was busy with finals), but I've managed to bypass this problem by connecting the PC to a phone and streaming audio to the phone. This assures better quality and it's easier to hear TTS voice over the engine noise.


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest