[mary-users] Stopping playback of AudioPlayer

Alexander Koller koller at mmci.uni-saarland.de
Tue Oct 26 10:31:11 CEST 2010


Hi,

I'm using the Mary client in a Java program, basically in the same way as in the MaryClientUser example program. That is, I obtain a wave file using MaryClient#process and play it back with the AudioPlayer utility class. This all works fine.

But in my application, it can happen that a request comes in to speak a second string before speaking the first string is finished. This means that I have to stop the playback of the first string before starting the second; otherwise, two utterances are played back at the same time. My question is: What is the correct way to stop the playback of AudioPlayer?

So far, I have tried two things, both without complete success:

1. If I call audioPlayer.cancel(), the playback stops correctly. However, when I call audioPlayer.start() for the second string, the playback doesn't always start at the beginning; it starts somewhere in the middle of the wave file for the second string.

2. If I call audioPlayer.getLine().close(), the second string is played back correctly, but the playback of the first string is not always cancelled, so I get overlapping utterances again.

I have thought about waiting for an appropriate LineEvent after cancelling the first playback, but can't figure out whether to wait for CLOSE or STOP; neither seems to be delivered reliably, as far as I can tell. I create a new AudioPlayer object for each new audio stream that I get from Mary.

I would appreciate any help on this. For instance, if someone could show me how to cancel the playback in MaryClientUser.java and start a second playback, that would solve my problem.

Cheers,
Alexander.





More information about the Mary-users mailing list