summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/speech
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/Modules/speech
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/Modules/speech')
-rw-r--r--Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.cpp81
-rw-r--r--Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.h55
-rw-r--r--Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.idl31
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesis.cpp242
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesis.h100
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesis.idl39
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesisEvent.cpp48
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesisEvent.h54
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesisEvent.idl32
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesisUtterance.cpp70
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesisUtterance.h84
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesisUtterance.idl45
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesisVoice.cpp45
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesisVoice.h57
-rw-r--r--Source/WebCore/Modules/speech/SpeechSynthesisVoice.idl35
15 files changed, 1018 insertions, 0 deletions
diff --git a/Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.cpp b/Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.cpp
new file mode 100644
index 000000000..5ef87234a
--- /dev/null
+++ b/Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DOMWindowSpeechSynthesis.h"
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+#include "DOMWindow.h"
+
+namespace WebCore {
+
+DOMWindowSpeechSynthesis::DOMWindowSpeechSynthesis(DOMWindow* window)
+ : DOMWindowProperty(window->frame())
+{
+}
+
+DOMWindowSpeechSynthesis::~DOMWindowSpeechSynthesis()
+{
+}
+
+const char* DOMWindowSpeechSynthesis::supplementName()
+{
+ return "DOMWindowSpeechSynthesis";
+}
+
+// static
+DOMWindowSpeechSynthesis* DOMWindowSpeechSynthesis::from(DOMWindow* window)
+{
+ DOMWindowSpeechSynthesis* supplement = static_cast<DOMWindowSpeechSynthesis*>(Supplement<DOMWindow>::from(window, supplementName()));
+ if (!supplement) {
+ auto newSupplement = std::make_unique<DOMWindowSpeechSynthesis>(window);
+ supplement = newSupplement.get();
+ provideTo(window, supplementName(), WTFMove(newSupplement));
+ }
+ return supplement;
+}
+
+// static
+SpeechSynthesis* DOMWindowSpeechSynthesis::speechSynthesis(DOMWindow& window)
+{
+ return DOMWindowSpeechSynthesis::from(&window)->speechSynthesis();
+}
+
+SpeechSynthesis* DOMWindowSpeechSynthesis::speechSynthesis()
+{
+ if (!m_speechSynthesis && frame())
+ m_speechSynthesis = SpeechSynthesis::create();
+ return m_speechSynthesis.get();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.h b/Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.h
new file mode 100644
index 000000000..a381093fd
--- /dev/null
+++ b/Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+#include "DOMWindowProperty.h"
+#include "SpeechSynthesis.h"
+#include "Supplementable.h"
+
+namespace WebCore {
+
+class DOMWindow;
+
+class DOMWindowSpeechSynthesis : public Supplement<DOMWindow>, public DOMWindowProperty {
+public:
+ explicit DOMWindowSpeechSynthesis(DOMWindow*);
+ virtual ~DOMWindowSpeechSynthesis();
+
+ WEBCORE_EXPORT static SpeechSynthesis* speechSynthesis(DOMWindow&);
+ static DOMWindowSpeechSynthesis* from(DOMWindow*);
+
+private:
+ SpeechSynthesis* speechSynthesis();
+ static const char* supplementName();
+
+ RefPtr<SpeechSynthesis> m_speechSynthesis;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.idl b/Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.idl
new file mode 100644
index 000000000..37040777e
--- /dev/null
+++ b/Source/WebCore/Modules/speech/DOMWindowSpeechSynthesis.idl
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+ Conditional=SPEECH_SYNTHESIS,
+] partial interface DOMWindow {
+
+ readonly attribute SpeechSynthesis speechSynthesis;
+};
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesis.cpp b/Source/WebCore/Modules/speech/SpeechSynthesis.cpp
new file mode 100644
index 000000000..9b632b24f
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesis.cpp
@@ -0,0 +1,242 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SpeechSynthesis.h"
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+#include "EventNames.h"
+#include "PlatformSpeechSynthesisVoice.h"
+#include "PlatformSpeechSynthesizer.h"
+#include "ScriptController.h"
+#include "SpeechSynthesisEvent.h"
+#include "SpeechSynthesisUtterance.h"
+#include <wtf/CurrentTime.h>
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore {
+
+Ref<SpeechSynthesis> SpeechSynthesis::create()
+{
+ return adoptRef(*new SpeechSynthesis);
+}
+
+SpeechSynthesis::SpeechSynthesis()
+ : m_currentSpeechUtterance(nullptr)
+ , m_isPaused(false)
+#if PLATFORM(IOS)
+ , m_restrictions(RequireUserGestureForSpeechStartRestriction)
+#endif
+{
+}
+
+void SpeechSynthesis::setPlatformSynthesizer(std::unique_ptr<PlatformSpeechSynthesizer> synthesizer)
+{
+ m_platformSpeechSynthesizer = WTFMove(synthesizer);
+ m_voiceList.clear();
+ m_currentSpeechUtterance = nullptr;
+ m_utteranceQueue.clear();
+ m_isPaused = false;
+}
+
+void SpeechSynthesis::voicesDidChange()
+{
+ m_voiceList.clear();
+}
+
+const Vector<Ref<SpeechSynthesisVoice>>& SpeechSynthesis::getVoices()
+{
+ if (m_voiceList.size())
+ return m_voiceList;
+
+ if (!m_platformSpeechSynthesizer)
+ m_platformSpeechSynthesizer = std::make_unique<PlatformSpeechSynthesizer>(this);
+
+ // If the voiceList is empty, that's the cue to get the voices from the platform again.
+ for (auto& voice : m_platformSpeechSynthesizer->voiceList())
+ m_voiceList.append(SpeechSynthesisVoice::create(*voice));
+
+ return m_voiceList;
+}
+
+bool SpeechSynthesis::speaking() const
+{
+ // If we have a current speech utterance, then that means we're assumed to be in a speaking state.
+ // This state is independent of whether the utterance happens to be paused.
+ return m_currentSpeechUtterance;
+}
+
+bool SpeechSynthesis::pending() const
+{
+ // This is true if there are any utterances that have not started.
+ // That means there will be more than one in the queue.
+ return m_utteranceQueue.size() > 1;
+}
+
+bool SpeechSynthesis::paused() const
+{
+ return m_isPaused;
+}
+
+void SpeechSynthesis::startSpeakingImmediately(SpeechSynthesisUtterance& utterance)
+{
+ ASSERT(!m_currentSpeechUtterance);
+ utterance.setStartTime(monotonicallyIncreasingTime());
+ m_currentSpeechUtterance = &utterance;
+ m_isPaused = false;
+
+ // Zero lengthed strings should immediately notify that the event is complete.
+ if (utterance.text().isEmpty()) {
+ handleSpeakingCompleted(utterance, false);
+ return;
+ }
+
+ if (!m_platformSpeechSynthesizer)
+ m_platformSpeechSynthesizer = std::make_unique<PlatformSpeechSynthesizer>(this);
+ m_platformSpeechSynthesizer->speak(utterance.platformUtterance());
+}
+
+void SpeechSynthesis::speak(SpeechSynthesisUtterance& utterance)
+{
+ // 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(m_utteranceQueue.first());
+}
+
+void SpeechSynthesis::cancel()
+{
+ // Remove all the items from the utterance queue.
+ // Hold on to the current utterance so the platform synthesizer can have a chance to clean up.
+ RefPtr<SpeechSynthesisUtterance> current = m_currentSpeechUtterance;
+ m_utteranceQueue.clear();
+ if (m_platformSpeechSynthesizer)
+ m_platformSpeechSynthesizer->cancel();
+ current = nullptr;
+
+ // The platform should have called back immediately and cleared the current utterance.
+ ASSERT(!m_currentSpeechUtterance);
+}
+
+void SpeechSynthesis::pause()
+{
+ if (!m_isPaused && m_platformSpeechSynthesizer)
+ m_platformSpeechSynthesizer->pause();
+}
+
+void SpeechSynthesis::resume()
+{
+ if (m_currentSpeechUtterance && m_platformSpeechSynthesizer)
+ m_platformSpeechSynthesizer->resume();
+}
+
+void SpeechSynthesis::fireEvent(const AtomicString& type, SpeechSynthesisUtterance& utterance, unsigned long charIndex, const String& name)
+{
+ utterance.dispatchEvent(SpeechSynthesisEvent::create(type, charIndex, (monotonicallyIncreasingTime() - utterance.startTime()), name));
+}
+
+void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance& utterance, bool errorOccurred)
+{
+ ASSERT(m_currentSpeechUtterance);
+ Ref<SpeechSynthesisUtterance> protect(utterance);
+
+ m_currentSpeechUtterance = nullptr;
+
+ fireEvent(errorOccurred ? eventNames().errorEvent : eventNames().endEvent, utterance, 0, String());
+
+ if (m_utteranceQueue.size()) {
+ Ref<SpeechSynthesisUtterance> firstUtterance = m_utteranceQueue.takeFirst();
+ ASSERT(&utterance == firstUtterance.ptr());
+
+ // Start the next job if there is one pending.
+ if (!m_utteranceQueue.isEmpty())
+ startSpeakingImmediately(m_utteranceQueue.first());
+ }
+}
+
+void SpeechSynthesis::boundaryEventOccurred(PlatformSpeechSynthesisUtterance& utterance, SpeechBoundary boundary, unsigned charIndex)
+{
+ static NeverDestroyed<const String> wordBoundaryString(ASCIILiteral("word"));
+ static NeverDestroyed<const String> sentenceBoundaryString(ASCIILiteral("sentence"));
+
+ ASSERT(utterance.client());
+
+ switch (boundary) {
+ case SpeechWordBoundary:
+ fireEvent(eventNames().boundaryEvent, static_cast<SpeechSynthesisUtterance&>(*utterance.client()), charIndex, wordBoundaryString);
+ break;
+ case SpeechSentenceBoundary:
+ fireEvent(eventNames().boundaryEvent, static_cast<SpeechSynthesisUtterance&>(*utterance.client()), charIndex, sentenceBoundaryString);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+}
+
+void SpeechSynthesis::didStartSpeaking(PlatformSpeechSynthesisUtterance& utterance)
+{
+ if (utterance.client())
+ fireEvent(eventNames().startEvent, static_cast<SpeechSynthesisUtterance&>(*utterance.client()), 0, String());
+}
+
+void SpeechSynthesis::didPauseSpeaking(PlatformSpeechSynthesisUtterance& utterance)
+{
+ m_isPaused = true;
+ if (utterance.client())
+ fireEvent(eventNames().pauseEvent, static_cast<SpeechSynthesisUtterance&>(*utterance.client()), 0, String());
+}
+
+void SpeechSynthesis::didResumeSpeaking(PlatformSpeechSynthesisUtterance& utterance)
+{
+ m_isPaused = false;
+ if (utterance.client())
+ fireEvent(eventNames().resumeEvent, static_cast<SpeechSynthesisUtterance&>(*utterance.client()), 0, String());
+}
+
+void SpeechSynthesis::didFinishSpeaking(PlatformSpeechSynthesisUtterance& utterance)
+{
+ if (utterance.client())
+ handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), false);
+}
+
+void SpeechSynthesis::speakingErrorOccurred(PlatformSpeechSynthesisUtterance& utterance)
+{
+ if (utterance.client())
+ handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance&>(*utterance.client()), true);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesis.h b/Source/WebCore/Modules/speech/SpeechSynthesis.h
new file mode 100644
index 000000000..d46c3181c
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesis.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+#include "PlatformExportMacros.h"
+#include "PlatformSpeechSynthesisUtterance.h"
+#include "PlatformSpeechSynthesizer.h"
+#include "SpeechSynthesisUtterance.h"
+#include "SpeechSynthesisVoice.h"
+#include <wtf/Deque.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class PlatformSpeechSynthesizerClient;
+class SpeechSynthesisVoice;
+
+class SpeechSynthesis : public PlatformSpeechSynthesizerClient, public RefCounted<SpeechSynthesis> {
+public:
+ static Ref<SpeechSynthesis> create();
+
+ bool pending() const;
+ bool speaking() const;
+ bool paused() const;
+
+ void speak(SpeechSynthesisUtterance&);
+ void cancel();
+ void pause();
+ void resume();
+
+ const Vector<Ref<SpeechSynthesisVoice>>& getVoices();
+
+ // Used in testing to use a mock platform synthesizer
+ WEBCORE_EXPORT void setPlatformSynthesizer(std::unique_ptr<PlatformSpeechSynthesizer>);
+
+private:
+ SpeechSynthesis();
+
+ // PlatformSpeechSynthesizerClient override methods.
+ void voicesDidChange() override;
+ void didStartSpeaking(PlatformSpeechSynthesisUtterance&) override;
+ void didPauseSpeaking(PlatformSpeechSynthesisUtterance&) override;
+ void didResumeSpeaking(PlatformSpeechSynthesisUtterance&) override;
+ void didFinishSpeaking(PlatformSpeechSynthesisUtterance&) override;
+ void speakingErrorOccurred(PlatformSpeechSynthesisUtterance&) override;
+ void boundaryEventOccurred(PlatformSpeechSynthesisUtterance&, SpeechBoundary, unsigned charIndex) override;
+
+ void startSpeakingImmediately(SpeechSynthesisUtterance&);
+ void handleSpeakingCompleted(SpeechSynthesisUtterance&, bool errorOccurred);
+ void fireEvent(const AtomicString& type, SpeechSynthesisUtterance&, unsigned long charIndex, const String& name);
+
+#if PLATFORM(IOS)
+ // Restrictions to change default behaviors.
+ enum BehaviorRestrictionFlags {
+ NoRestrictions = 0,
+ RequireUserGestureForSpeechStartRestriction = 1 << 0,
+ };
+ typedef unsigned BehaviorRestrictions;
+
+ bool userGestureRequiredForSpeechStart() const { return m_restrictions & RequireUserGestureForSpeechStartRestriction; }
+ void removeBehaviorRestriction(BehaviorRestrictions restriction) { m_restrictions &= ~restriction; }
+#endif
+ std::unique_ptr<PlatformSpeechSynthesizer> m_platformSpeechSynthesizer;
+ Vector<Ref<SpeechSynthesisVoice>> m_voiceList;
+ SpeechSynthesisUtterance* m_currentSpeechUtterance;
+ Deque<Ref<SpeechSynthesisUtterance>> m_utteranceQueue;
+ bool m_isPaused;
+#if PLATFORM(IOS)
+ BehaviorRestrictions m_restrictions;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesis.idl b/Source/WebCore/Modules/speech/SpeechSynthesis.idl
new file mode 100644
index 000000000..025003e4c
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesis.idl
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+ Conditional=SPEECH_SYNTHESIS,
+ NoInterfaceObject,
+] interface SpeechSynthesis {
+ readonly attribute boolean pending;
+ readonly attribute boolean speaking;
+ readonly attribute boolean paused;
+
+ void speak(SpeechSynthesisUtterance utterance);
+ void cancel();
+ void pause();
+ void resume();
+ sequence<SpeechSynthesisVoice> getVoices();
+};
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesisEvent.cpp b/Source/WebCore/Modules/speech/SpeechSynthesisEvent.cpp
new file mode 100644
index 000000000..ec4a7f7b1
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesisEvent.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SpeechSynthesisEvent.h"
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+namespace WebCore {
+
+Ref<SpeechSynthesisEvent> SpeechSynthesisEvent::create(const AtomicString& type, unsigned charIndex, float elapsedTime, const String& name)
+{
+ return adoptRef(*new SpeechSynthesisEvent(type, charIndex, elapsedTime, name));
+}
+
+SpeechSynthesisEvent::SpeechSynthesisEvent(const AtomicString& type, unsigned charIndex, float elapsedTime, const String& name)
+ : Event(type, false, false)
+ , m_charIndex(charIndex)
+ , m_elapsedTime(elapsedTime)
+ , m_name(name)
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesisEvent.h b/Source/WebCore/Modules/speech/SpeechSynthesisEvent.h
new file mode 100644
index 000000000..6e7204b2b
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesisEvent.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+#include "Event.h"
+
+namespace WebCore {
+
+class SpeechSynthesisEvent : public Event {
+public:
+ static Ref<SpeechSynthesisEvent> create(const AtomicString& type, unsigned charIndex, float elapsedTime, const String& name);
+
+ unsigned long charIndex() const { return m_charIndex; }
+ float elapsedTime() const { return m_elapsedTime; }
+ const String& name() const { return m_name; }
+
+ virtual EventInterface eventInterface() const { return SpeechSynthesisEventInterfaceType; }
+
+private:
+ SpeechSynthesisEvent(const AtomicString& type, unsigned charIndex, float elapsedTime, const String& name);
+
+ unsigned long m_charIndex;
+ float m_elapsedTime;
+ String m_name;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesisEvent.idl b/Source/WebCore/Modules/speech/SpeechSynthesisEvent.idl
new file mode 100644
index 000000000..8403f1398
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesisEvent.idl
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+ Conditional=SPEECH_SYNTHESIS
+] interface SpeechSynthesisEvent : Event {
+ readonly attribute unsigned long charIndex;
+ readonly attribute unrestricted float elapsedTime;
+ readonly attribute DOMString name;
+};
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesisUtterance.cpp b/Source/WebCore/Modules/speech/SpeechSynthesisUtterance.cpp
new file mode 100644
index 000000000..6746f4ef4
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesisUtterance.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SpeechSynthesisUtterance.h"
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+namespace WebCore {
+
+Ref<SpeechSynthesisUtterance> SpeechSynthesisUtterance::create(ScriptExecutionContext& context, const String& text)
+{
+ return adoptRef(*new SpeechSynthesisUtterance(context, text));
+}
+
+SpeechSynthesisUtterance::SpeechSynthesisUtterance(ScriptExecutionContext& context, const String& text)
+ : ContextDestructionObserver(&context)
+ , m_platformUtterance(PlatformSpeechSynthesisUtterance::create(*this))
+{
+ m_platformUtterance->setText(text);
+}
+
+SpeechSynthesisUtterance::~SpeechSynthesisUtterance()
+{
+ m_platformUtterance->setClient(nullptr);
+}
+
+SpeechSynthesisVoice* SpeechSynthesisUtterance::voice() const
+{
+ return m_voice.get();
+}
+
+void SpeechSynthesisUtterance::setVoice(SpeechSynthesisVoice* voice)
+{
+ if (!voice)
+ return;
+
+ // Cache our own version of the SpeechSynthesisVoice so that we don't have to do some lookup
+ // to go from the platform voice back to the speech synthesis voice in the read property.
+ m_voice = voice;
+
+ if (voice)
+ m_platformUtterance->setVoice(voice->platformVoice());
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesisUtterance.h b/Source/WebCore/Modules/speech/SpeechSynthesisUtterance.h
new file mode 100644
index 000000000..b5cb52002
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesisUtterance.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+#include "ContextDestructionObserver.h"
+#include "EventTarget.h"
+#include "PlatformSpeechSynthesisUtterance.h"
+#include "SpeechSynthesisVoice.h"
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class SpeechSynthesisUtterance final : public PlatformSpeechSynthesisUtteranceClient, public RefCounted<SpeechSynthesisUtterance>, public ContextDestructionObserver, public EventTargetWithInlineData {
+public:
+ static Ref<SpeechSynthesisUtterance> create(ScriptExecutionContext&, const String&);
+
+ virtual ~SpeechSynthesisUtterance();
+
+ const String& text() const { return m_platformUtterance->text(); }
+ void setText(const String& text) { m_platformUtterance->setText(text); }
+
+ const String& lang() const { return m_platformUtterance->lang(); }
+ void setLang(const String& lang) { m_platformUtterance->setLang(lang); }
+
+ SpeechSynthesisVoice* voice() const;
+ void setVoice(SpeechSynthesisVoice*);
+
+ float volume() const { return m_platformUtterance->volume(); }
+ void setVolume(float volume) { m_platformUtterance->setVolume(volume); }
+
+ float rate() const { return m_platformUtterance->rate(); }
+ void setRate(float rate) { m_platformUtterance->setRate(rate); }
+
+ float pitch() const { return m_platformUtterance->pitch(); }
+ void setPitch(float pitch) { m_platformUtterance->setPitch(pitch); }
+
+ double startTime() const { return m_platformUtterance->startTime(); }
+ void setStartTime(double startTime) { m_platformUtterance->setStartTime(startTime); }
+
+ using RefCounted::ref;
+ using RefCounted::deref;
+
+ PlatformSpeechSynthesisUtterance* platformUtterance() const { return m_platformUtterance.get(); }
+
+private:
+ SpeechSynthesisUtterance(ScriptExecutionContext&, const String&);
+
+ ScriptExecutionContext* scriptExecutionContext() const final { return ContextDestructionObserver::scriptExecutionContext(); }
+ EventTargetInterface eventTargetInterface() const final { return SpeechSynthesisUtteranceEventTargetInterfaceType; }
+ void refEventTarget() final { ref(); }
+ void derefEventTarget() final { deref(); }
+
+ RefPtr<PlatformSpeechSynthesisUtterance> m_platformUtterance;
+ RefPtr<SpeechSynthesisVoice> m_voice;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesisUtterance.idl b/Source/WebCore/Modules/speech/SpeechSynthesisUtterance.idl
new file mode 100644
index 000000000..e781f5244
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesisUtterance.idl
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+ Conditional=SPEECH_SYNTHESIS,
+ ConstructorCallWith=ScriptExecutionContext,
+ Constructor(optional DOMString text)
+] interface SpeechSynthesisUtterance : EventTarget {
+ attribute DOMString text;
+ attribute DOMString lang;
+ attribute SpeechSynthesisVoice? voice; // FIXME: should not be nullable.
+ attribute unrestricted float volume;
+ attribute unrestricted float rate;
+ attribute unrestricted float pitch;
+
+ attribute EventHandler onstart;
+ attribute EventHandler onend;
+ attribute EventHandler onerror;
+ attribute EventHandler onpause;
+ attribute EventHandler onresume;
+ attribute EventHandler onmark;
+ attribute EventHandler onboundary;
+};
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesisVoice.cpp b/Source/WebCore/Modules/speech/SpeechSynthesisVoice.cpp
new file mode 100644
index 000000000..fccd7fd64
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesisVoice.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "SpeechSynthesisVoice.h"
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+namespace WebCore {
+
+Ref<SpeechSynthesisVoice> SpeechSynthesisVoice::create(PlatformSpeechSynthesisVoice& voice)
+{
+ return adoptRef(*new SpeechSynthesisVoice(voice));
+}
+
+SpeechSynthesisVoice::SpeechSynthesisVoice(PlatformSpeechSynthesisVoice& voice)
+ : m_platformVoice(voice)
+{
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesisVoice.h b/Source/WebCore/Modules/speech/SpeechSynthesisVoice.h
new file mode 100644
index 000000000..7fade0d1d
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesisVoice.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(SPEECH_SYNTHESIS)
+
+#include "PlatformSpeechSynthesisVoice.h"
+#include <wtf/RefCounted.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class SpeechSynthesisVoice : public RefCounted<SpeechSynthesisVoice> {
+public:
+ virtual ~SpeechSynthesisVoice() { }
+ static Ref<SpeechSynthesisVoice> create(PlatformSpeechSynthesisVoice&);
+
+ const String& voiceURI() const { return m_platformVoice->voiceURI(); }
+ const String& name() const { return m_platformVoice->name(); }
+ const String& lang() const { return m_platformVoice->lang(); }
+ bool localService() const { return m_platformVoice->localService(); }
+ bool isDefault() const { return m_platformVoice->isDefault(); }
+
+ PlatformSpeechSynthesisVoice* platformVoice() { return m_platformVoice.ptr(); }
+
+private:
+ explicit SpeechSynthesisVoice(PlatformSpeechSynthesisVoice&);
+
+ Ref<PlatformSpeechSynthesisVoice> m_platformVoice;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SPEECH_SYNTHESIS)
diff --git a/Source/WebCore/Modules/speech/SpeechSynthesisVoice.idl b/Source/WebCore/Modules/speech/SpeechSynthesisVoice.idl
new file mode 100644
index 000000000..9aa489e05
--- /dev/null
+++ b/Source/WebCore/Modules/speech/SpeechSynthesisVoice.idl
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+ NoInterfaceObject,
+ Conditional=SPEECH_SYNTHESIS
+] interface SpeechSynthesisVoice {
+ readonly attribute DOMString voiceURI;
+ readonly attribute DOMString name;
+ readonly attribute DOMString lang;
+ readonly attribute boolean localService;
+ [ImplementedAs=isDefault] readonly attribute boolean default;
+};