org.jvoicexml.SpeakableText - java examples

Here are the examples of the java api org.jvoicexml.SpeakableText taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

88 Examples 7

19 View Complete Implementation : SynthesisQueue.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notifies the MarySynthesizedOutput that output has ended.
 *
 * @param speakable
 *            the current speakable.
 */
private void fireOutputEnded(final SpeakableText speakable) {
    final SynthesizedOutputEvent event = new OutputEndedEvent(output, null, speakable);
    fireOutputEvent(event);
}

19 View Complete Implementation : MobicentsSynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notifies all listeners that output has started.
 * @param speakable the current speakable.
 */
private void fireOutputStarted(final SpeakableText speakable) {
    final SynthesizedOutputEvent event = new OutputStartedEvent(this, null, speakable);
    fireOutputEvent(event);
}

19 View Complete Implementation : Jsapi20SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void waitNonBargeInPlayed() {
    synchronized (queuedSpeakables) {
        final SpeakableText speakable = queuedSpeakables.peek();
        if (speakable == null) {
            return;
        }
        if (!speakable.isBargeInEnabled(BargeInType.SPEECH) && !speakable.isBargeInEnabled(BargeInType.HOTWORD)) {
            return;
        }
    }
    waitQueueEmpty();
}

19 View Complete Implementation : SynthesisQueue.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notifies the MarySynthesizedOutput that output has started.
 *
 * @param speakable
 *            the current speakable.
 */
private void fireOutputStarted(final SpeakableText speakable) {
    final SynthesizedOutputEvent event = new OutputStartedEvent(output, null, speakable);
    fireOutputEvent(event);
}

19 View Complete Implementation : TestJsapi20SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Test method for {@link Jsapi20SynthesizedOutput#waitQueueEmpty()}.
 * @throws JVoiceXMLEvent
 *         test failed
 * @throws Exception
 *         test failed
 * @since 0.7.5
 */
@Test
public void testWaitQueueEmpty() throws JVoiceXMLEvent, Exception {
    final SsmlDoreplacedent ssml = new SsmlDoreplacedent();
    final Speak speak = ssml.getSpeak();
    speak.addText("this is a test");
    final SpeakableText speakable1 = new SpeakableSsmlText(ssml);
    output.queueSpeakable(speakable1, sessionId, doreplacedentServer);
    output.waitQueueEmpty();
    replacedert.replacedertFalse("output should be busy", output.isBusy());
}

19 View Complete Implementation : Jsapi10SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notifies all listeners that output has started.
 *
 * @param speakable
 *            the current speakable.
 */
private void fireOutputStarted(final SpeakableText speakable) {
    final SynthesizedOutputEvent event = new OutputStartedEvent(this, null, speakable);
    fireOutputEvent(event);
}

19 View Complete Implementation : MobicentsSynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * @param call
 * @Override
 */
public void onStatusChanged(Call call) {
    try {
        MgcpCallTerminal term = (MgcpCallTerminal) call;
        LOGGER.debug("current is " + call.toString() + " \n queuedSpeakables:" + queuedSpeakables);
        if ((Call.Status.COMPLETED == call.getStatus() || Call.Status.IN_PROGRESS == call.getStatus()) && term.getIVREndPointState() == MgcpIvrEndpoint.IDLE && (term.getIVREndPointOldState() == MgcpIvrEndpoint.PLAY || term.getIVREndPointOldState() == MgcpIvrEndpoint.PLAY_COLLECT || term.getIVREndPointOldState() == MgcpIvrEndpoint.PLAY_RECORD)) {
            if (doreplacedentServer == null) {
                LOGGER.error("  doreplacedentServer is null");
            } else {
                // must check the speaker is already play, before ended the speaker.
                List<URI> listURI = term.getCurrentAnnouncements();
                if (listURI != null && !listURI.isEmpty()) {
                    final SpeakableText speakable;
                    synchronized (queuedSpeakables) {
                        speakable = queuedSpeakables.peek();
                    }
                    if (queuedSpeakables.isEmpty() || speakable == null)
                        return;
                    for (URI uri : listURI) {
                        if (speakable.getSpeakableText().indexOf(uri.toString()) != -1) {
                            // if a speaker is already playing, it's will be ended by endedEvent
                            final SpeakableEvent event = new SpeakableEvent(doreplacedentServer, SpeakableEvent.SPEAKABLE_ENDED);
                            speakableEnded(event);
                        }
                    }
                } else {
                    LOGGER.warn("  wrong mapping ended event");
                    return;
                }
            }
        }
    } catch (Exception ex) {
        ExLog.exception(LOGGER, ex);
    }
}

19 View Complete Implementation : MockImplementationPlatform.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void renderPrompts(final String sessionId, final DoreplacedentServer server, final CallControlProperties callProps) throws BadFetchError, NoresourceError, ConnectionDisconnectHangupEvent {
    if (prompts == null) {
        return;
    }
    final SystemOutput out = getSystemOutput();
    for (SpeakableText speakable : prompts) {
        out.queueSpeakable(speakable, sessionId, server);
    }
    prompts = null;
}

19 View Complete Implementation : Mrcpv2SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notifies all listeners that output has started.
 *
 * @param speakable
 *            the current speakable.
 */
private void fireOutputStarted(final SpeakableText speakable) {
    final SynthesizedOutputEvent event = new OutputStartedEvent(this, null, speakable);
    synchronized (listeners) {
        final Collection<SynthesizedOutputListener> copy = new java.util.ArrayList<SynthesizedOutputListener>(listeners);
        for (SynthesizedOutputListener current : copy) {
            current.outputStatusChanged(event);
        }
    }
}

19 View Complete Implementation : MockSynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void waitNonBargeInPlayed() {
    SpeakableText speakable;
    do {
        speakable = speakables.peek();
        if (speakable != null) {
            if (!speakable.isBargeInEnabled(BargeInType.SPEECH)) {
                return;
            }
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                return;
            }
        }
    } while (speakable != null);
}

19 View Complete Implementation : MarySynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Gets the events fired from SynthesisQueue thread and it forwards them. to
 * ImplementationPlatform it also sets the appropriate flags
 *
 * @param event
 *            the event.
 */
public void outputStatusChanged(final SynthesizedOutputEvent event) {
    if (event.isType(OutputStartedEvent.EVENT_TYPE)) {
        final OutputStartedEvent outputStartedEvent = (OutputStartedEvent) event;
        final SpeakableText startedSpeakable = outputStartedEvent.getSpeakable();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("output started " + startedSpeakable);
        }
        isBusy = true;
        fireOutputStarted(startedSpeakable);
    } else if (event.isType(OutputEndedEvent.EVENT_TYPE)) {
        final OutputEndedEvent outputEndedEvent = (OutputEndedEvent) event;
        final SpeakableText endedSpeakable = outputEndedEvent.getSpeakable();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("audio playing ended");
        }
        isBusy = false;
        fireOutputEnded(endedSpeakable);
    } else if (event.isType(QueueEmptyEvent.EVENT_TYPE)) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("output queue is empty");
        }
        speakableQueueEmpty = true;
        fireQueueEmpty();
        synchronized (emptyLock) {
            emptyLock.notifyAll();
        }
    }
}

19 View Complete Implementation : SpeakableQueue.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Adds the given speakable with the given id to the queue.
 * @param speakable the speakable
 */
public void offer(final SpeakableText speakable) {
    synchronized (queue) {
        ++seq;
        final String id = "JVoiceXMLTrack " + seq;
        final QueuedSpeakable elem = new QueuedSpeakable(id, speakable);
        queue.add(elem);
    }
}

19 View Complete Implementation : Jsapi10SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 *
 * Checks the type of the given speakable and forwards it either as for SSML
 * output or for plain text output.
 */
@Override
public void queueSpeakable(final SpeakableText speakable, final String id, final DoreplacedentServer server) throws NoresourceError, BadFetchError {
    if (synthesizer == null) {
        throw new NoresourceError("no synthesizer: cannot speak");
    }
    sessionId = id;
    doreplacedentServer = server;
    synchronized (queuedSpeakables) {
        queuedSpeakables.offer(speakable);
        // Do not process the speakable if there is some ongoing processing
        if (queuedSpeakables.size() > 1) {
            return;
        }
    }
    // Otherwise process the added speakable asynchronous.
    final Runnable runnable = new Runnable() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void run() {
            try {
                processNextSpeakable();
            } catch (NoresourceError e) {
                notifyError(e);
            } catch (BadFetchError e) {
                notifyError(e);
            }
        }
    };
    final Thread thread = new Thread(runnable);
    thread.start();
}

19 View Complete Implementation : SynthesisQueue.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * The queueSpeakable method simply offers a speakable to the queue. it
 * notifies the synthesisQueue Thread and then it returns
 *
 * @param speakable
 *            the speakable to offer
 */
public void queueSpeakables(final SpeakableText speakable) {
    synchronized (queuedSpeakables) {
        queuedSpeakables.offer(speakable);
        queuedSpeakables.notify();
    }
}

19 View Complete Implementation : TestJVoiceXmlPromptAccumulator.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Test of getLastSpeakableText method, of clreplaced JVoiceXmlPromptAcreplacedulator.
 * @exception Exception
 *            test failed
 */
@Test
public void testGetLastSpeakableText() throws Exception {
    replacedert.replacedertNull(acreplacedulator.getLastSpeakableText());
    final SsmlDoreplacedent ssml1 = new SsmlDoreplacedent();
    final Speak speak1 = ssml1.getSpeak();
    speak1.addText("this is a test");
    final SpeakableText speakable1 = new SpeakableSsmlText(ssml1);
    acreplacedulator.queuePrompt(speakable1);
    replacedert.replacedertEquals(speakable1, acreplacedulator.getLastSpeakableText());
    final SsmlDoreplacedent ssml2 = new SsmlDoreplacedent();
    final Speak speak2 = ssml2.getSpeak();
    speak2.addText("this is another test");
    final SpeakableText speakable2 = new SpeakableSsmlText(ssml2);
    acreplacedulator.queuePrompt(speakable2);
    replacedert.replacedertEquals(speakable2, acreplacedulator.getLastSpeakableText());
}

19 View Complete Implementation : MobicentsSynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 *
 * Checks the type of the given speakable and forwards it either as for SSML
 * output or for plain text output.
 */
@Override
public void queueSpeakable(final SpeakableText speakable, final String id, final DoreplacedentServer server) throws NoresourceError, BadFetchError {
    if (synthesizer == null) {
        throw new NoresourceError("no synthesizer: cannot speak");
    }
    sessionId = id;
    synchronized (queuedSpeakables) {
        queuedSpeakables.offer(speakable);
    }
    LOGGER.debug("\t offered a speakable:" + speakable + " \n id :" + id + " \n current queuedSpeakables:" + queuedSpeakables);
    doreplacedentServer = server;
    // Do not process the speakable if there is some ongoing processing
    synchronized (queuedSpeakables) {
        if (queuedSpeakables.size() > 1) {
            LOGGER.error("Do not process the speakable if there is some ongoing processing:" + queuedSpeakables);
            return;
        }
    }
    outputCanceled = false;
    // Otherwise process the added speakable asynchronous.
    final Runnable runnable = new Runnable() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void run() {
            try {
                processNextSpeakable();
            } catch (NoresourceError e) {
                notifyError(e);
            } catch (BadFetchError e) {
                notifyError(e);
            }
        }
    };
    final Thread thread = new Thread(runnable);
    thread.start();
}

19 View Complete Implementation : Jsapi10SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Processes the next speakable in the queue.
 *
 * @throws NoresourceError
 *             error processing the speakable.
 * @throws BadFetchError
 *             error processing the speakable.
 * @since 0.7.1
 */
private synchronized void processNextSpeakable() throws NoresourceError, BadFetchError {
    // Check if there are more speakables to process
    final SpeakableText speakable;
    synchronized (queuedSpeakables) {
        // Reset all flags of the previous output.
        bargeInType = null;
        bargein = false;
        outputCanceled = false;
        if (queuedSpeakables.isEmpty()) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("no more speakables to process");
            }
            fireQueueEmpty();
            synchronized (emptyLock) {
                emptyLock.notifyAll();
            }
            return;
        }
        speakable = queuedSpeakables.peek();
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("processing next speakable :" + speakable);
    }
    // Really process the next speakable
    fireOutputStarted(speakable);
    if (speakable instanceof SpeakableSsmlText) {
        final SpeakableSsmlText ssml = (SpeakableSsmlText) speakable;
        synchronized (queuedSpeakables) {
            bargein = ssml.isBargeInEnabled(BargeInType.SPEECH) || ssml.isBargeInEnabled(BargeInType.HOTWORD);
            bargeInType = ssml.getBargeInType();
        }
        speakSSML(ssml, doreplacedentServer);
    } else {
        LOGGER.warn("unsupported speakable: " + speakable);
    }
    // remove the topmost element from the queue and notify the listeners
    // that we are done with it
    synchronized (queuedSpeakables) {
        queuedSpeakables.poll();
    }
    fireOutputEnded(speakable);
    // recursivly call this method until the queue is empty
    try {
        processNextSpeakable();
    } catch (NoresourceError e) {
        notifyError(e);
    } catch (BadFetchError e) {
        notifyError(e);
    }
}

19 View Complete Implementation : MobicentsSynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notifies all listeners that output has ended.
 * @param speakable the current speakable.
 */
private void fireOutputEnded(final SpeakableText speakable) {
    final SynthesizedOutputEvent event = new OutputEndedEvent(this, null, speakable);
    fireOutputEvent(event);
    synchronized (endplayLock) {
        endplayLock.notifyAll();
    }
}

19 View Complete Implementation : JVoiceXmlPromptAccumulator.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void renderPrompts(final String sessionId, final DoreplacedentServer server, final CallControlProperties callProps) throws BadFetchError, NoresourceError, ConnectionDisconnectHangupEvent {
    final CallControl call = platform.getCallControl();
    if (!call.isCallActive()) {
        throw new NoresourceError("cannot render prompts. call is no longer active");
    }
    final SystemOutput output = platform.getSystemOutput();
    for (SpeakableText speakable : prompts) {
        if (speakable instanceof SpeakableSsmlText) {
            final SpeakableSsmlText ssmlSpeakable = (SpeakableSsmlText) speakable;
            final long currentTimeout = ssmlSpeakable.getTimeout();
            if (currentTimeout >= 0) {
                timeout = currentTimeout;
            }
        }
        try {
            call.play(output, callProps);
        } catch (IOException e) {
            throw new BadFetchError("error playing to calling device", e);
        }
        output.queueSpeakable(speakable, sessionId, server);
    }
    // Cleanup after rendering has been completed
    prompts.clear();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("timeout after prompt queuing: " + timeout);
    }
}

19 View Complete Implementation : Mrcpv2SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 *
 * Checks the type of the given speakable and forwards it either as for SSML
 * output or for plain text output.
 */
@Override
public void queueSpeakable(final SpeakableText speakable, final String sessionId, final DoreplacedentServer doreplacedentServer) throws NoresourceError, BadFetchError {
    String speakText = null;
    boolean urlPrompt = false;
    queueCount++;
    LOGGER.info("Queue count incremented,, now " + queueCount);
    try {
        // TODO Preplaced on the entire SSML doc (and remove the code that
        // extracts the text)
        // The following code extract the text from the SSML since
        // the mrcp server (cairo) does not support SSML yet
        // (really the tts engine needs to support it i.e freetts)
        if (speakable instanceof SpeakableSsmlText) {
            InputStream is = null;
            String temp = speakable.getSpeakableText();
            byte[] b = temp.getBytes();
            is = new ByteArrayInputStream(b);
            InputSource src = new InputSource(is);
            SsmlDoreplacedent ssml = new SsmlDoreplacedent(src);
            speakText = ssml.getSpeak().getTextContent();
            LOGGER.info("Text content is " + speakText);
            // TODO Implement a better way of detecting and extracting
            // audio URLs
            DoreplacedentBuilderFactory factory = DoreplacedentBuilderFactory.newInstance();
            DoreplacedentBuilder builder = factory.newDoreplacedentBuilder();
            Doreplacedent doreplacedent = builder.parse(new InputSource(new StringReader(temp)));
            NodeList list = doreplacedent.getElementsByTagName("audio");
            if (list != null && list.getLength() > 0) {
                Element audioTag = (Element) list.item(0);
                String url = audioTag.getAttribute("src");
                try {
                    new URI(url);
                    speakText = url;
                    urlPrompt = true;
                } catch (URISyntaxException e) {
                    LOGGER.error("'src' attribute is not a valid URI");
                }
            }
        }
        if (urlPrompt) {
            LOGGER.info(String.format("Using URL: %s", speakText));
            // HALEF Event logging
            final String hevent = String.format("INSERT INTO haleflogs" + " (databasedate, machineIP, machinedate, clreplaced, level," + " message) VALUES(%s, \"%s\", %s," + " \"%s\", \"%s\", \"%s\")", "now()", System.getenv("IP"), "now()", "implementation.mrcpv2.Mrcpv2SynthesizedOutput", "INFO", "Using URL!: " + speakText);
            HalefDbWriter.execute(hevent);
        } else {
            LOGGER.info(String.format("Using TTS!: %s", speakText));
            // HALEF Event logging
            final String hevent = String.format("INSERT INTO haleflogs" + " (databasedate, machineIP, machinedate, clreplaced, level," + " message) VALUES(%s, \"%s\", %s," + " \"%s\", \"%s\", \"%s\")", "now()", System.getenv("IP"), "now()", "implementation.mrcpv2.Mrcpv2SynthesizedOutput", "INFO", "Using TTS!: " + speakText);
            HalefDbWriter.execute(hevent);
        }
        speechClient.queuePrompt(urlPrompt, speakText);
    } catch (ParserConfigurationException e) {
        throw new NoresourceError(e.getMessage(), e);
    } catch (SAXException e) {
        throw new NoresourceError(e.getMessage(), e);
    } catch (MrcpInvocationException e) {
        throw new NoresourceError(e.getMessage(), e);
    } catch (IOException e) {
        throw new NoresourceError(e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new NoresourceError(e.getMessage(), e);
    } catch (NoMediaControlChannelException e) {
        throw new NoresourceError(e.getMessage(), e);
    }
}

19 View Complete Implementation : TestJsapi20SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Test method for {@link Jsapi20SynthesizedOutput#queueSpeakable(SpeakableText, boolean, org.jvoicexml.DoreplacedentServer)}.
 * @throws JVoiceXMLEvent
 *         test failed.
 * @throws Exception
 *         test failed
 */
@Test
public void testQueueMultipleSpeakables() throws JVoiceXMLEvent, Exception {
    final int max = 10;
    for (int i = 0; i < max; i++) {
        final SpeakableText speakable;
        final SsmlDoreplacedent ssml = new SsmlDoreplacedent();
        final Speak speak = ssml.getSpeak();
        speak.setXmlLang(Locale.US);
        speak.addText("this is test " + i);
        speakable = new SpeakableSsmlText(ssml);
        output.queueSpeakable(speakable, sessionId, doreplacedentServer);
    }
    output.waitQueueEmpty();
    replacedert.replacedertFalse(output.isBusy());
    listener.waitSize(2 * max + 1, TIMEOUT);
    int started = 0;
    int ended = 0;
    int emptied = 0;
    for (int i = 0; i < listener.size(); i++) {
        final SynthesizedOutputEvent event = listener.get(i);
        if (event.isType(OutputStartedEvent.EVENT_TYPE)) {
            ++started;
        } else if (event.isType(OutputEndedEvent.EVENT_TYPE)) {
            ++ended;
        } else if (event.isType(QueueEmptyEvent.EVENT_TYPE)) {
            ++emptied;
        } else {
            replacedert.fail("unknown event " + event.getEventType());
        }
    }
    replacedert.replacedertEquals(max, started);
    replacedert.replacedertEquals(max, ended);
}

19 View Complete Implementation : TestJsapi20SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Test method for {@link Jsapi20SynthesizedOutput#cancelOutput()}.
 * @throws JVoiceXMLEvent
 *         test failed
 * @throws Exception
 *         test failed
 * @since 0.7.5
 */
@Test
public void testCancelSpeakable() throws JVoiceXMLEvent, Exception {
    SsmlDoreplacedent ssml = new SsmlDoreplacedent();
    Speak speak = ssml.getSpeak();
    speak.setXmlLang(Locale.US);
    speak.addText("this is a test to interrupt the Text" + " to Speech Engine it is a very long sentence it really" + " is long very long longer than longcat");
    final SpeakableText speakable1 = new SpeakableSsmlText(ssml, true, BargeInType.SPEECH);
    output.queueSpeakable(speakable1, sessionId, doreplacedentServer);
    Thread.sleep(1500);
    output.cancelOutput(BargeInType.SPEECH);
    final int size = 2;
    listener.waitSize(size, TIMEOUT);
    replacedert.replacedertEquals(size, listener.size());
    SynthesizedOutputEvent start = listener.get(0);
    replacedert.replacedertEquals(OutputStartedEvent.EVENT_TYPE, start.getEventType());
    OutputStartedEvent startedEvent = (OutputStartedEvent) start;
    replacedert.replacedertEquals(speakable1, startedEvent.getSpeakable());
    SynthesizedOutputEvent empty = listener.get(1);
    replacedert.replacedertEquals(QueueEmptyEvent.EVENT_TYPE, empty.getEventType());
}

19 View Complete Implementation : JVoiceXmlSystemOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
public void queueSpeakable(final SpeakableText speakable, final String sessionId, final DoreplacedentServer doreplacedentServer) throws NoresourceError, BadFetchError {
    synthesizedOutput.queueSpeakable(speakable, sessionId, doreplacedentServer);
}

19 View Complete Implementation : QueuedSpeakable.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * A queued speakable with the {@link SpeakableQueue}.
 * @author Dirk Schnelle-Walka
 * @version $Revision$
 * @since 0.7.7
 */
clreplaced QueuedSpeakable {

    /**
     * A unique identifier of the speakable.
     */
    private final String id;

    /**
     * The queued speakable.
     */
    private final SpeakableText speakable;

    /**
     * Constructs a new object.
     * @param identifier a unique identifier for the speakable
     * @param speakableText the speakable
     */
    public QueuedSpeakable(final String identifier, final SpeakableText speakableText) {
        id = identifier;
        speakable = speakableText;
    }

    /**
     * Retrieves the identifier for this speakable.
     * @return the identifier for the speakable
     */
    public String getId() {
        return id;
    }

    /**
     * Retrieves the speakable.
     * @return the speakable
     */
    public SpeakableText getSpeakable() {
        return speakable;
    }
}

19 View Complete Implementation : MockSystemOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void queueSpeakable(final SpeakableText speakableText, final String id, final DoreplacedentServer doreplacedentServer) throws NoresourceError, BadFetchError {
    speakable = speakableText;
    sessionId = id;
    final SynthesizedOutputEvent event = new OutputStartedEvent(null, sessionId, speakable);
    fireOutputEvent(event);
}

19 View Complete Implementation : MarySynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc} The queueSpeakable method simply offers a speakable to the
 * queue. it notifies the synthesisQueue Thread and then it returns
 *
 * @throws NoresourceError
 *             if no MaryClient has been created
 */
@Override
public void queueSpeakable(final SpeakableText speakable, final String sessionId, final DoreplacedentServer server) throws NoresourceError {
    if (processor == null) {
        throw new NoresourceError("no synthesizer: cannot speak");
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("queued speakable: " + speakable);
    }
    synthesisQueue.queueSpeakables(speakable);
    speakableQueueEmpty = false;
}

19 View Complete Implementation : QueuedSpeakable.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * A queued speakable with the {@link SpeakableQueue}.
 * @author Dirk Schnelle-Walka
 * @version $Revision$
 * @since 0.7.5
 */
clreplaced QueuedSpeakable {

    /**
     * A unique identifier of the speakable.
     */
    private final String id;

    /**
     * The queued speakable.
     */
    private final SpeakableText speakable;

    /**
     * Constructs a new object.
     * @param identifier a unique identifier for the speakable
     * @param speakableText the speakable
     */
    public QueuedSpeakable(final String identifier, final SpeakableText speakableText) {
        id = identifier;
        speakable = speakableText;
    }

    /**
     * Retrieves the identifier for this speakable.
     * @return the identifier for the speakable
     */
    public String getId() {
        return id;
    }

    /**
     * Retrieves the speakable.
     * @return the speakable
     */
    public SpeakableText getSpeakable() {
        return speakable;
    }
}

19 View Complete Implementation : JsonExtensionNotificationDataConverter.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public Object convertSynthesizedOutputEvent(final SynthesizedOutputEvent event) throws ConversionException {
    if (event instanceof OutputStartedEvent) {
        final OutputStartedEvent started = (OutputStartedEvent) event;
        final SpeakableText speakable = started.getSpeakable();
        return toJson(speakable);
    } else if (event instanceof OutputEndedEvent) {
        final OutputEndedEvent ended = (OutputEndedEvent) event;
        final SpeakableText speakable = ended.getSpeakable();
        return toJson(speakable);
    }
    LOGGER.info("not sending synthesized output event: " + event);
    return null;
}

19 View Complete Implementation : MarySynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notifies all listeners that output has ended.
 *
 * @param speakable
 *            the current speakable.
 */
private void fireOutputEnded(final SpeakableText speakable) {
    final SynthesizedOutputEvent event = new OutputEndedEvent(this, null, speakable);
    fireOutputEvent(event);
}

19 View Complete Implementation : TestJVoiceXmlPromptAccumulator.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Test of renderPrompts method, of clreplaced JVoiceXmlPromptAcreplacedulator.
 * @exception Exception
 *            test failed
 * @exception JVoiceXMLEvent
 *            test failed
 */
@Test
public void testRenderPrompts() throws Exception, JVoiceXMLEvent {
    final SsmlDoreplacedent ssml1 = new SsmlDoreplacedent();
    final Speak speak1 = ssml1.getSpeak();
    speak1.addText("this is a test");
    final SpeakableText speakable1 = new SpeakableSsmlText(ssml1);
    acreplacedulator.queuePrompt(speakable1);
    final SsmlDoreplacedent ssml2 = new SsmlDoreplacedent();
    final Speak speak2 = ssml2.getSpeak();
    speak2.addText("this is another test");
    final SpeakableSsmlText speakable2 = new SpeakableSsmlText(ssml2);
    final long timeout = 40;
    speakable2.setTimeout(timeout);
    acreplacedulator.queuePrompt(speakable2);
    final CallControlProperties props = new CallControlProperties();
    acreplacedulator.renderPrompts(null, null, props);
    replacedert.replacedertEquals(timeout, acreplacedulator.getPromptTimeout());
}

19 View Complete Implementation : SynthesisQueue.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Stops the currently playing output if barge-in is enabled and. Removes
 * from the queue the speakables for which barge-in is enabled
 * @param bargeInType the type of bargein to cancel
 */
public void cancelOutput(final BargeInType bargeInType) {
    if ((queuedSpeakable == null) || !queuedSpeakable.isBargeInEnabled(bargeInType)) {
        return;
    }
    if (out != null) {
        out.cancel();
    }
    synchronized (queuedSpeakables) {
        final Collection<SpeakableText> skipped = new java.util.ArrayList<SpeakableText>();
        for (SpeakableText speakable : queuedSpeakables) {
            if (speakable.isBargeInEnabled(bargeInType)) {
                skipped.add(speakable);
            } else {
                break;
            }
        }
        queuedSpeakables.removeAll(skipped);
    }
}

19 View Complete Implementation : Jsapi10SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void cancelOutput(final BargeInType type) throws NoresourceError {
    if (synthesizer == null) {
        throw new NoresourceError("No synthesizer: Cannot cancel output");
    }
    if (!bargein || (type != bargeInType)) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("bargein not active for current output");
        }
        return;
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("cancelling current output...");
    }
    outputCanceled = true;
    synchronized (queuedSpeakables) {
        try {
            synthesizer.cancelAll();
        } catch (EngineStateError ee) {
            throw new NoresourceError(ee);
        }
        final Collection<SpeakableText> skipped = new java.util.ArrayList<SpeakableText>();
        for (SpeakableText speakable : queuedSpeakables) {
            if (speakable.isBargeInEnabled(type)) {
                skipped.add(speakable);
            } else {
                // Stop iterating after the first non-bargein speakable
                // has been detected
                break;
            }
        }
        queuedSpeakables.removeAll(skipped);
        if (queuedSpeakables.isEmpty()) {
            fireQueueEmpty();
            synchronized (emptyLock) {
                emptyLock.notifyAll();
            }
        } else {
            final Runnable runnable = new Runnable() {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public void run() {
                    try {
                        outputCanceled = false;
                        processNextSpeakable();
                    } catch (NoresourceError e) {
                        notifyError(e);
                    } catch (BadFetchError e) {
                        notifyError(e);
                    }
                }
            };
            final Thread thread = new Thread(runnable);
            thread.start();
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("...output cancelled.");
    }
}

19 View Complete Implementation : SynthesisQueue.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * The method that actually preplacedes the speakable to Mary. According to the
 * speakable Type it calls the process method of the MaryClient with
 * inputType set to "TEXT" or "SSML" as appropriate It gets the answer from
 * the server at ByteArrayOutputStream out and then it calls queueAudio
 * method of MaryAudioFileOutput to play the audio. This method also fires
 * the events OutputStarted and OutputEnded to MarySynthesizedOutput as well
 * as error Events that inform the Browser that some exception occurred
 * either at process or queueAudio processes This method does not return
 * until the audio playing has completed during the process
 *
 * @param speakable
 *            the speakable to be preplaceded to Mary server
 * @throws BadFetchError
 *             if an error occurs while playing
 * @throws IOException
 *             error communicating with Mary
 */
private void preplacedSpeakableToMary(final SpeakableText speakable) throws BadFetchError, IOException {
    fireOutputStarted(speakable);
    out = new LineAudioFormatOutputStream();
    try {
        if (speakable instanceof SpeakableSsmlText) {
            final SpeakableSsmlText ssml = (SpeakableSsmlText) speakable;
            speakSsml(ssml, out);
            fireOutputEnded(speakable);
        } else {
            throw new BadFetchError("Unsupported Speakable type: '" + speakable.getClreplaced() + "'");
        }
    } finally {
        out.close();
        out = null;
    }
}

19 View Complete Implementation : JVoiceXmlPromptAccumulator.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void queuePrompt(final SpeakableText speakable) {
    prompts.add(speakable);
}

19 View Complete Implementation : SynthesisQueue.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * SynthesisQueue extends Thead and is responsible for getting the speakables.
 * from the queue in which they are stored by MarySynthesizedOutput and preplacedes
 * them to Mary server and to TextOutput if text output is enabled After getting
 * the processed data from the server it calls queueAudio method of
 * MaryAudioFileOutput to play the sound
 *
 * @author Dirk Schnelle-Walka
 * @author Giannis replacediouras
 */
final clreplaced SynthesisQueue extends Thread {

    /**
     * Logger for this clreplaced.
     */
    private static final Logger LOGGER = Logger.getLogger(SynthesisQueue.clreplaced);

    /**
     * Timeout for requests to the Mary server.
     */
    private static final int SERVER_TIMEOUT = 5000;

    /**
     * The queue of speakables.
     */
    private final Queue<SpeakableText> queuedSpeakables;

    /**
     * The system output listener.
     */
    private SynthesizedOutputListener listener;

    /**
     * The Mary synthesized output resource.
     */
    private final MarySynthesizedOutput output;

    /**
     * The Mary client used to send requests to Mary server .
     */
    private MaryClient processor;

    /**
     * Reference to the SpeakableText object that is currently played back. This
     * can be either a SpeakablePlainText or a SpeakableSsmlText.
     */
    private SpeakableText queuedSpeakable;

    /**
     * The HashTable that contains Mary synthesis request parameters. e.g
     * audioType,voiceName,voiceEffects and their value
     */
    private Map<String, String> maryRequestParameters;

    /**
     * The line output stream.
     */
    private LineAudioFormatOutputStream out;

    /**
     * Constructs a new SynthesisQueue object. .
     * @param synthesizedOutput reference to the parent
     */
    SynthesisQueue(final MarySynthesizedOutput synthesizedOutput) {
        queuedSpeakables = new java.util.LinkedList<SpeakableText>();
        output = synthesizedOutput;
        setDaemon(true);
        setName("SynthesisQueueThread");
    }

    /**
     * Thread's run method:If the queue is Empty it fires a QueueEmpty Event to
     * MarySynthesizedOutput and from there to the Voice Browser. Otherwise it
     * removes the first speakable and preplacedes it to the Mary server.
     */
    @Override
    public void run() {
        while (processor != null && !isInterrupted()) {
            synchronized (queuedSpeakables) {
                if (queuedSpeakables.isEmpty()) {
                    fireQueueEmpty();
                    try {
                        queuedSpeakables.wait();
                    } catch (InterruptedException e) {
                        return;
                    }
                }
                queuedSpeakable = queuedSpeakables.remove();
            }
            if (processor != null) {
                try {
                    preplacedSpeakableToMary(queuedSpeakable);
                } catch (BadFetchError e) {
                    listener.outputError(e);
                } catch (IOException e) {
                    LOGGER.error(e.getMessage(), e);
                    final BadFetchError error = new BadFetchError(e.getMessage(), e);
                    listener.outputError(error);
                }
            }
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("synthesis queue terminated");
        }
    }

    /**
     * The method that actually preplacedes the speakable to Mary. According to the
     * speakable Type it calls the process method of the MaryClient with
     * inputType set to "TEXT" or "SSML" as appropriate It gets the answer from
     * the server at ByteArrayOutputStream out and then it calls queueAudio
     * method of MaryAudioFileOutput to play the audio. This method also fires
     * the events OutputStarted and OutputEnded to MarySynthesizedOutput as well
     * as error Events that inform the Browser that some exception occurred
     * either at process or queueAudio processes This method does not return
     * until the audio playing has completed during the process
     *
     * @param speakable
     *            the speakable to be preplaceded to Mary server
     * @throws BadFetchError
     *             if an error occurs while playing
     * @throws IOException
     *             error communicating with Mary
     */
    private void preplacedSpeakableToMary(final SpeakableText speakable) throws BadFetchError, IOException {
        fireOutputStarted(speakable);
        out = new LineAudioFormatOutputStream();
        try {
            if (speakable instanceof SpeakableSsmlText) {
                final SpeakableSsmlText ssml = (SpeakableSsmlText) speakable;
                speakSsml(ssml, out);
                fireOutputEnded(speakable);
            } else {
                throw new BadFetchError("Unsupported Speakable type: '" + speakable.getClreplaced() + "'");
            }
        } finally {
            out.close();
            out = null;
        }
    }

    /**
     * Speaks the given SSML doreplacedent.
     *
     * @param ssml
     *            the SSML doreplacedent to be synthesized by Mary
     * @param responseStream
     *            the output buffer to store Mary's response
     * @exception IOException
     *                error communicating with Mary
     */
    private void speakSsml(final SpeakableSsmlText ssml, final OutputStream responseStream) throws IOException {
        final SsmlDoreplacedent doreplacedent = ssml.getDoreplacedent();
        final Speak speak = doreplacedent.getSpeak();
        final String lang = speak.getXmlLang();
        final String text = doreplacedent.toXml();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("synthesizing '" + text + "'");
        }
        processor.process(text, "SSML", "AUDIO", lang, maryRequestParameters.get("audioType"), maryRequestParameters.get("voiceName"), responseStream, SERVER_TIMEOUT);
    }

    /**
     * All the notification events are preplaceded initially. SynthesizedOutput and
     * from there to VoiceBrowser
     *
     * @param outputListener
     *            the MarySynthesizedOutput object
     */
    public void addListener(final SynthesizedOutputListener outputListener) {
        listener = outputListener;
    }

    /**
     * Removes the listener for system output events.
     *
     * @param outputListener
     *            the MarySynthesizedOutput object to remove.
     */
    public void removeListener(final SynthesizedOutputListener outputListener) {
        synchronized (listener) {
            listener = null;
        }
    }

    /**
     * Notifies the Listener that output queue is empty.
     */
    private void fireQueueEmpty() {
        final SynthesizedOutputEvent event = new QueueEmptyEvent(output, null);
        fireOutputEvent(event);
    }

    /**
     * Notifies the MarySynthesizedOutput about the given event.
     *
     * @param event
     *            the event.
     */
    private void fireOutputEvent(final SynthesizedOutputEvent event) {
        listener.outputStatusChanged(event);
    }

    /**
     * Notifies the MarySynthesizedOutput that output has started.
     *
     * @param speakable
     *            the current speakable.
     */
    private void fireOutputStarted(final SpeakableText speakable) {
        final SynthesizedOutputEvent event = new OutputStartedEvent(output, null, speakable);
        fireOutputEvent(event);
    }

    /**
     * Notifies the MarySynthesizedOutput that output has ended.
     *
     * @param speakable
     *            the current speakable.
     */
    private void fireOutputEnded(final SpeakableText speakable) {
        final SynthesizedOutputEvent event = new OutputEndedEvent(output, null, speakable);
        fireOutputEvent(event);
    }

    /**
     * Sets the MaryClient object that will be used bu this Thread. to send
     * requests to Mary server
     *
     * @param maryClient
     *            the connection to Mary.
     */
    public void setProcessor(final MaryClient maryClient) {
        processor = maryClient;
    }

    /**
     * The queueSpeakable method simply offers a speakable to the queue. it
     * notifies the synthesisQueue Thread and then it returns
     *
     * @param speakable
     *            the speakable to offer
     */
    public void queueSpeakables(final SpeakableText speakable) {
        synchronized (queuedSpeakables) {
            queuedSpeakables.offer(speakable);
            queuedSpeakables.notify();
        }
    }

    /**
     * Removes all the speakables from the queue.
     */
    public void clearQueue() {
        synchronized (queuedSpeakables) {
            queuedSpeakables.clear();
        }
    }

    /**
     * Stops the currently playing output if barge-in is enabled and. Removes
     * from the queue the speakables for which barge-in is enabled
     * @param bargeInType the type of bargein to cancel
     */
    public void cancelOutput(final BargeInType bargeInType) {
        if ((queuedSpeakable == null) || !queuedSpeakable.isBargeInEnabled(bargeInType)) {
            return;
        }
        if (out != null) {
            out.cancel();
        }
        synchronized (queuedSpeakables) {
            final Collection<SpeakableText> skipped = new java.util.ArrayList<SpeakableText>();
            for (SpeakableText speakable : queuedSpeakables) {
                if (speakable.isBargeInEnabled(bargeInType)) {
                    skipped.add(speakable);
                } else {
                    break;
                }
            }
            queuedSpeakables.removeAll(skipped);
        }
    }

    /**
     * Stops the currently playing output if barge-in is enabled.
     */
    public void cancelAudioOutput() {
        if ((queuedSpeakable != null) && (queuedSpeakable.isBargeInEnabled(BargeInType.SPEECH) || queuedSpeakable.isBargeInEnabled(BargeInType.HOTWORD))) {
            return;
        }
        if (out != null) {
            out.cancel();
        }
    }

    /**
     * Sets the parameters e.g AudioType, VoiceName, VoiceEffects required by
     * MaryClient to make a synthesis request to MaryServer.
     *
     * @param parameters
     *            The HashTable that contains synthesis parameters and their
     *            values
     */
    public void setRequestParameters(final Map<String, String> parameters) {
        maryRequestParameters = parameters;
    }
}

19 View Complete Implementation : Jsapi10SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void waitNonBargeInPlayed() {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("waiting until all non-barge-in has been played...");
    }
    if (!bargein) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("bargein not active for current output");
        }
        return;
    }
    boolean stopWaiting = false;
    while (!stopWaiting) {
        synchronized (endplayLock) {
            try {
                endplayLock.wait(WAIT_EMPTY_TIMEINTERVALL);
            } catch (InterruptedException e) {
                return;
            }
        }
        synchronized (queuedSpeakables) {
            if (queuedSpeakables.isEmpty()) {
                stopWaiting = true;
            } else {
                final SpeakableText speakable = queuedSpeakables.peek();
                if (speakable instanceof SpeakableSsmlText) {
                    final SpeakableSsmlText ssml = (SpeakableSsmlText) speakable;
                    stopWaiting = ssml.getBargeInType() == null;
                }
            }
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("...all non barge-in has been played");
    }
}

19 View Complete Implementation : MobicentsSynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
public void cancelOutput() throws NoresourceError {
    if (synthesizer == null) {
        throw new NoresourceError("No synthesizer: Cannot cancel output");
    }
    if (!bargein) {
        LOGGER.debug("bargein not active for current output");
        return;
    }
    LOGGER.debug("cancelling current output with bargein is active...");
    outputCanceled = true;
    synchronized (queuedSpeakables) {
        try {
            synthesizer.cancelAll();
        } catch (EngineStateError ee) {
            throw new NoresourceError(ee);
        }
        final Collection<SpeakableText> skipped = new java.util.ArrayList<SpeakableText>();
        for (SpeakableText speakable : queuedSpeakables) {
            if (speakable.isBargeInEnabled()) {
                skipped.add(speakable);
            } else {
                // Stop iterating after the first non-bargein speakable
                // has been detected
                break;
            }
        }
        LOGGER.debug("removing all skipped:" + skipped);
        queuedSpeakables.removeAll(skipped);
        if (queuedSpeakables.isEmpty()) {
            fireQueueEmpty();
            synchronized (emptyLock) {
                emptyLock.notifyAll();
            }
        } else {
            final Runnable runnable = new Runnable() {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public void run() {
                    try {
                        outputCanceled = false;
                        processNextSpeakable();
                    } catch (NoresourceError e) {
                        notifyError(e);
                    } catch (BadFetchError e) {
                        notifyError(e);
                    }
                }
            };
            final Thread thread = new Thread(runnable);
            thread.start();
        }
    }
    // reset handle
    handler = null;
    LOGGER.debug("...output cancelled. queuedSpeakables:" + queuedSpeakables + " reset handler:" + handler + " this:" + this);
}

19 View Complete Implementation : MockImplementationPlatform.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void queuePrompt(final SpeakableText speakable) {
    if (prompts == null) {
        prompts = new java.util.ArrayList<SpeakableText>();
    }
    prompts.add(speakable);
}

19 View Complete Implementation : MobicentsSynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
public void speakableEnded(final SpeakableEvent event) {
    LOGGER.debug("... with event:" + event);
    final Object source = event.getSource();
    if (source instanceof SsmlDoreplacedent) {
        queueingSsml = false;
        LOGGER.debug("ending Synthesis of an SSML doreplacedent started");
    }
    final boolean removeSpeakable = !queueingSsml;
    if (removeSpeakable) {
        // TODO this will fail if we end with an audio or break tag.
        final SpeakableText speakable;
        synchronized (queuedSpeakables) {
            speakable = queuedSpeakables.poll();
        }
        if (true) {
            if (speakable != null) {
                LOGGER.debug("speakable ended: " + speakable.getSpeakableText());
                if (handler != null) {
                    try {
                        URI uri = handler.getUriForNextSynthesisizedOutput(info);
                        if (speakable.getSpeakableText().indexOf(uri.toString()) != -1) {
                            LOGGER.debug("reset  handler: " + handler + " with uri:" + uri);
                            handler = null;
                        }
                    } catch (NoresourceError ex) {
                        ExLog.exception(LOGGER, ex);
                    }
                }
            }
        }
        // If streaming is supported, add the stream to the queue.
        if (streamBuffer != null) {
            final byte[] buffer = streamBuffer.toByteArray();
            final InputStream input = new ByteArrayInputStream(buffer);
            try {
                synthesizerStreams.put(input);
            } catch (InterruptedException e) {
                LOGGER.debug("unable to add a synthesizer stream", e);
            }
            streamBuffer = null;
        }
        if (speakable != null) {
            fireOutputEnded(speakable);
        }
        try {
            processNextSpeakable();
        } catch (NoresourceError e) {
            notifyError(e);
        } catch (BadFetchError e) {
            notifyError(e);
        }
    }
}

19 View Complete Implementation : Jsapi10SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notifies all listeners that output has ended.
 *
 * @param speakable
 *            the current speakable.
 */
private void fireOutputEnded(final SpeakableText speakable) {
    final SynthesizedOutputEvent event = new OutputEndedEvent(this, null, speakable);
    fireOutputEvent(event);
    synchronized (endplayLock) {
        endplayLock.notifyAll();
    }
}

19 View Complete Implementation : MobicentsSynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Processes the next speakable in the queue.
 * @throws NoresourceError
 *         error processing the speakable.
 * @throws BadFetchError
 *         error processing the speakable.
 * @since 0.7.1
 */
private synchronized void processNextSpeakable() throws NoresourceError, BadFetchError {
    // Reset all flags of the previous output.
    queueingSsml = false;
    bargeInType = null;
    bargein = false;
    // Check if there are more speakables to process
    final SpeakableText speakable;
    synchronized (queuedSpeakables) {
        if (queuedSpeakables.isEmpty()) {
            LOGGER.debug("no more speakables to process");
            fireQueueEmpty();
            synchronized (emptyLock) {
                emptyLock.notifyAll();
            }
            return;
        }
        speakable = queuedSpeakables.peek();
    }
    LOGGER.debug("processing next speakable :" + speakable);
    // Really process the next speakable
    fireOutputStarted(speakable);
    if (speakable instanceof SpeakableSsmlText) {
        final SpeakableSsmlText ssml = (SpeakableSsmlText) speakable;
        bargein = ssml.isBargeInEnabled();
        bargeInType = ssml.getBargeInType();
        LOGGER.debug("bargein:" + bargein + " bargeInType:" + bargeInType);
        speakSSML(ssml, doreplacedentServer);
    } else {
        LOGGER.error("unsupported speakable: " + speakable);
    }
}

19 View Complete Implementation : OutputStartedEvent.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notification that the output of a {@link SpeakableText} has started.
 *
 * @author Dirk Schnelle-Walka
 * @version $Revision$
 * @since 0.7.1
 */
@SuppressWarnings("serial")
public final clreplaced OutputStartedEvent extends SynthesizedOutputEvent {

    /**
     * The unsupported element.
     */
    public static final String DETAIL = "start";

    /**
     * The detail message.
     */
    public static final String EVENT_TYPE = SynthesizedOutputEvent.clreplaced.getCanonicalName() + "." + DETAIL;

    /**
     * The speakable.
     */
    private final SpeakableText speakable;

    /**
     * Constructs a new event with the event type as its detail message. The
     * cause is not initialized
     *
     * <p>
     * The {@link #DETAIL} is used to construct the event type.
     * </p>
     *
     * @see #getEventType()
     *
     * @param output
     *            object that caused the event.
     * @param sessionId
     *            the session id
     * @param speakableText
     *            the speakable that has ended
     */
    public OutputStartedEvent(final SynthesizedOutput output, final String sessionId, final SpeakableText speakableText) {
        super(output, DETAIL, sessionId);
        speakable = speakableText;
    }

    /**
     * Retrieves the speakable.
     *
     * @return the speakable
     */
    public SpeakableText getSpeakable() {
        return speakable;
    }
}

19 View Complete Implementation : Mrcpv2SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notifies all listeners that output has started.
 *
 * @param speakable
 *            the current speakable.
 */
private void fireOutputEnded(final SpeakableText speakable) {
    final SynthesizedOutputEvent event = new OutputEndedEvent(this, null, speakable);
    synchronized (listeners) {
        final Collection<SynthesizedOutputListener> copy = new java.util.ArrayList<SynthesizedOutputListener>(listeners);
        for (SynthesizedOutputListener current : copy) {
            current.outputStatusChanged(event);
        }
    }
}

19 View Complete Implementation : TestJsapi20SynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Test method for {@link Jsapi20SynthesizedOutput#cancelOutput()}.
 * @throws JVoiceXMLEvent
 *         test failed
 * @throws Exception
 *         test failed
 * @since 0.7.5
 */
@Test
public void testCancelSpeakableWithNoBargein() throws JVoiceXMLEvent, Exception {
    SsmlDoreplacedent ssml = new SsmlDoreplacedent();
    Speak speak = ssml.getSpeak();
    speak.setXmlLang(Locale.US);
    speak.addText("this is a test to interrupt the Text" + " to Speech Engine it is a very long sentence it really" + " is long very long longer than long");
    final SpeakableText speakable1 = new SpeakableSsmlText(ssml, true, BargeInType.SPEECH);
    output.queueSpeakable(speakable1, sessionId, doreplacedentServer);
    final SsmlDoreplacedent ssml2 = new SsmlDoreplacedent();
    final Speak speak2 = ssml2.getSpeak();
    speak2.addText("No bargein text");
    final SpeakableText speakable2 = new SpeakableSsmlText(ssml2, false, null);
    output.queueSpeakable(speakable2, sessionId, doreplacedentServer);
    Thread.sleep(1500);
    output.cancelOutput(BargeInType.SPEECH);
    final int size = 4;
    listener.waitSize(size, TIMEOUT);
    replacedert.replacedertEquals(size, listener.size());
    SynthesizedOutputEvent start1 = listener.get(0);
    replacedert.replacedertEquals(OutputStartedEvent.EVENT_TYPE, start1.getEventType());
    OutputStartedEvent started1Event = (OutputStartedEvent) start1;
    replacedert.replacedertEquals(speakable1, started1Event.getSpeakable());
    SynthesizedOutputEvent start2 = listener.get(1);
    replacedert.replacedertEquals(OutputStartedEvent.EVENT_TYPE, start2.getEventType());
    OutputStartedEvent started2Event = (OutputStartedEvent) start2;
    replacedert.replacedertEquals(speakable2, started2Event.getSpeakable());
    SynthesizedOutputEvent end2 = listener.get(2);
    replacedert.replacedertEquals(OutputEndedEvent.EVENT_TYPE, end2.getEventType());
    SynthesizedOutputEvent empty = listener.get(3);
    replacedert.replacedertEquals(QueueEmptyEvent.EVENT_TYPE, empty.getEventType());
    output.waitQueueEmpty();
}

19 View Complete Implementation : MockSynthesizedOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void queueSpeakable(final SpeakableText speakableText, final String sessionId, final DoreplacedentServer doreplacedentServer) throws NoresourceError, BadFetchError {
    id = sessionId;
    speakables.offer(speakableText);
    synchronized (thread) {
        thread.notify();
    }
}

19 View Complete Implementation : OutputEndedEvent.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Notification that the output of a {@link SpeakableText} has ended.
 *
 * @author Dirk Schnelle-Walka
 * @version $Revision$
 * @since 0.7.1
 */
@SuppressWarnings("serial")
public final clreplaced OutputEndedEvent extends SynthesizedOutputEvent {

    /**
     * The unsupported element.
     */
    public static final String DETAIL = "end";

    /**
     * The detail message.
     */
    public static final String EVENT_TYPE = SynthesizedOutputEvent.clreplaced.getCanonicalName() + "." + DETAIL;

    /**
     * The speakable.
     */
    private final SpeakableText speakable;

    /**
     * Constructs a new event with the event type as its detail message. The
     * cause is not initialized
     *
     * <p>
     * The {@link #DETAIL} is used to construct the event type.
     * </p>
     *
     * @see #getEventType()
     *
     * @param output
     *            object that caused the event.
     * @param sessionId
     *            the session id
     * @param speakableText
     *            the speakable that has ended
     */
    public OutputEndedEvent(final SynthesizedOutput output, final String sessionId, final SpeakableText speakableText) {
        super(output, DETAIL, sessionId);
        speakable = speakableText;
    }

    /**
     * Retrieves the speakable.
     *
     * @return the speakable
     */
    public SpeakableText getSpeakable() {
        return speakable;
    }
}

19 View Complete Implementation : JVoiceXmlImplementationPlatform.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * {@inheritDoc}
 */
@Override
public void queuePrompt(final SpeakableText speakable) {
    promptAcreplacedulator.queuePrompt(speakable);
}

19 View Complete Implementation : TestJVoiceXmlImplementationPlatform.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Test method for {@link JVoiceXmlImplementationPlatform#waitNonBargeInPlayed()}.
 * @exception JVoiceXMLEvent
 *            Test failed.
 * @exception Exception
 *            test failed
 * @since 0.7.3
 */
@Test(timeout = 5000)
public void testWaitNonBargeInPlayed() throws JVoiceXMLEvent, Exception {
    final SystemOutput output = platform.getSystemOutput();
    final SsmlDoreplacedent doc1 = new SsmlDoreplacedent();
    final Speak speak1 = doc1.getSpeak();
    speak1.addText("Test1");
    final SpeakableText text1 = new SpeakableSsmlText(doc1, true, BargeInType.HOTWORD);
    final SsmlDoreplacedent doc2 = new SsmlDoreplacedent();
    final Speak speak2 = doc2.getSpeak();
    speak2.addText("Test2");
    final SpeakableText text2 = new SpeakableSsmlText(doc2, true, BargeInType.SPEECH);
    final SsmlDoreplacedent doc3 = new SsmlDoreplacedent();
    final Speak speak3 = doc3.getSpeak();
    speak3.addText("Test3");
    final SpeakableText text3 = new SpeakableSsmlText(doc3);
    output.queueSpeakable(text1, null, null);
    output.queueSpeakable(text2, null, null);
    output.queueSpeakable(text3, null, null);
    platform.waitNonBargeInPlayed();
}

19 View Complete Implementation : MockSystemOutput.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * This clreplaced provides a dummy implementation of a {@link SystemOutput} for
 * testing purposes.
 *
 * @author Dirk Schnelle-Walka
 * @since 0.6
 */
public final clreplaced MockSystemOutput implements SystemOutput {

    /**
     * Registered output listener.
     */
    private final Collection<SynthesizedOutputListener> listener;

    /**
     * The current speakable.
     */
    private SpeakableText speakable;

    /**
     * The encapsulated synthesized output.
     */
    private final SynthesizedOutput output;

    /**
     * the session id.
     */
    private String sessionId;

    /**
     * Constructs a new object.
     */
    public MockSystemOutput() {
        this(null);
    }

    /**
     * Constructs a new object.
     * @param synthesizedOutput the encapsulated synthesized output.
     */
    public MockSystemOutput(final SynthesizedOutput synthesizedOutput) {
        listener = new java.util.ArrayList<SynthesizedOutputListener>();
        output = synthesizedOutput;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void cancelOutput(final BargeInType type) throws NoresourceError {
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void queueSpeakable(final SpeakableText speakableText, final String id, final DoreplacedentServer doreplacedentServer) throws NoresourceError, BadFetchError {
        speakable = speakableText;
        sessionId = id;
        final SynthesizedOutputEvent event = new OutputStartedEvent(null, sessionId, speakable);
        fireOutputEvent(event);
    }

    /**
     * Simulates the end of an output.
     */
    public void outputEnded() {
        final SynthesizedOutputEvent endedEvent = new OutputEndedEvent(null, sessionId, speakable);
        fireOutputEvent(endedEvent);
        speakable = null;
        final SynthesizedOutputEvent emptyEvent = new QueueEmptyEvent(null, sessionId);
        fireOutputEvent(emptyEvent);
    }

    /**
     * {@inheritDoc}
     */
    public void addListener(final SynthesizedOutputListener outputListener) {
        if (outputListener == null) {
            return;
        }
        synchronized (listener) {
            listener.add(outputListener);
        }
    }

    /**
     * {@inheritDoc}
     */
    public void removeListener(final SynthesizedOutputListener outputListener) {
        synchronized (listener) {
            listener.remove(outputListener);
        }
    }

    /**
     * Notifies all registered listeners about the given event.
     * @param event the event.
     * @since 0.6
     */
    private void fireOutputEvent(final SynthesizedOutputEvent event) {
        synchronized (listener) {
            final Collection<SynthesizedOutputListener> copy = new java.util.ArrayList<SynthesizedOutputListener>();
            copy.addAll(listener);
            for (SynthesizedOutputListener current : copy) {
                current.outputStatusChanged(event);
            }
        }
    }

    /**
     * {@inheritDoc}
     */
    public SynthesizedOutput getSynthesizedOutput() throws NoresourceError {
        return output;
    }
}

19 View Complete Implementation : TestMarcFeedback.java
Copyright GNU Lesser General Public License v2.1
Author : JVoiceXML
/**
 * Test method for
 * {@link org.jvoicexml.implementation.marc.MarcFeedback#run()}.
 *
 * @exception Exception
 *                test failed
 * @exception JVoiceXMLEvent
 *                test failed
 */
@Test
public void testRun() throws Exception, JVoiceXMLEvent {
    final MarcSynthesizedOutput output = new MarcSynthesizedOutput();
    output.connect(null);
    output.addListener(this);
    final SpeakableText speakable = new SpeakableSsmlText("test", Locale.US);
    final String sessionId = UUID.randomUUID().toString();
    output.queueSpeakable(speakable, sessionId, null);
    final MarcFeedback feedback = new MarcFeedback(output, 4011);
    final DatagramSocket server = new DatagramSocket(4012);
    feedback.start();
    Thread.sleep(1000);
    final String msg = "<event id=\"JVoiceXMLTrack:end\"/>";
    final byte[] buf = msg.getBytes();
    final InetAddress address = Inet4Address.getLocalHost();
    final DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 4011);
    server.send(packet);
    final String msg2 = "<event id=\"SpeechCommand:end\"/>";
    final byte[] buf2 = msg2.getBytes();
    final DatagramPacket packet2 = new DatagramPacket(buf2, buf2.length, address, 4011);
    server.send(packet2);
    synchronized (lock) {
        lock.wait();
    }
    replacedert.replacedertTrue(event instanceof OutputEndedEvent);
    final OutputEndedEvent endedEvent = (OutputEndedEvent) event;
    replacedert.replacedertEquals(speakable, endedEvent.getSpeakable());
}