void SpeechSynthesis::speak(SpeechSynthesisUtterance* utterance, ExceptionState& exceptionState) { if (!utterance) { exceptionState.throwTypeError("Invalid utterance argument"); return; } m_utteranceQueue.append(utterance); // If the queue was empty, speak this immediately. if (m_utteranceQueue.size() == 1) startSpeakingImmediately(); }
void SpeechSynthesis::speak(SpeechSynthesisUtterance* utterance) { if (!utterance) return; // Like Audio, we should require that the user interact to start a speech synthesis session. #if PLATFORM(IOS) if (ScriptController::processingUserGesture()) removeBehaviorRestriction(RequireUserGestureForSpeechStartRestriction); else if (userGestureRequiredForSpeechStart()) return; #endif m_utteranceQueue.append(utterance); // If the queue was empty, speak this immediately and add it to the queue. if (m_utteranceQueue.size() == 1) startSpeakingImmediately(utterance); }
void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance* utterance, bool errorOccurred) { ASSERT(utterance); ASSERT(m_currentSpeechUtterance); m_currentSpeechUtterance = 0; fireEvent(errorOccurred ? eventNames().errorEvent : eventNames().endEvent, utterance, 0, String()); if (m_utteranceQueue.size()) { RefPtr<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.first(); ASSERT(firstUtterance == utterance); if (firstUtterance == utterance) m_utteranceQueue.removeFirst(); // Start the next job if there is one pending. if (!m_utteranceQueue.isEmpty()) startSpeakingImmediately(m_utteranceQueue.first().get()); } }
void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance* utterance, bool errorOccurred) { ASSERT(utterance); bool shouldStartSpeaking = false; // If the utterance that completed was the one we're currently speaking, // remove it from the queue and start speaking the next one. if (utterance == currentSpeechUtterance()) { m_utteranceQueue.removeFirst(); shouldStartSpeaking = !!m_utteranceQueue.size(); } // Always fire the event, because the platform may have asynchronously // sent an event on an utterance before it got the message that we // canceled it, and we should always report to the user what actually // happened. fireEvent(errorOccurred ? EventTypeNames::error : EventTypeNames::end, utterance, 0, String()); // Start the next utterance if we just finished one and one was pending. if (shouldStartSpeaking && !m_utteranceQueue.isEmpty()) startSpeakingImmediately(); }