Title: [172956] trunk
Revision
172956
Author
k.cz...@samsung.com
Date
2014-08-26 04:25:49 -0700 (Tue, 26 Aug 2014)

Log Message

[EFL] Utilize espeak as a synthesizer back-end for WebSpeech
https://bugs.webkit.org/show_bug.cgi?id=136127

Reviewed by Gyuyoung Kim.

.:

Add build support for espeak.

* Source/cmake/FindEspeak.cmake: Added.
* Source/cmake/OptionsEfl.cmake: Add Espeak dependency.

Source/WebCore:

Utilize espeak API to have support for speak, cancel and initializeVoiceList.

* PlatformEfl.cmake:
* platform/efl/PlatformSpeechSynthesisProviderEfl.cpp:
(WebCore::PlatformSpeechSynthesisProviderEfl::PlatformSpeechSynthesisProviderEfl):
(WebCore::PlatformSpeechSynthesisProviderEfl::convertRateToEspeakValue):
(WebCore::PlatformSpeechSynthesisProviderEfl::convertVolumeToEspeakValue):
(WebCore::PlatformSpeechSynthesisProviderEfl::convertPitchToEspeakValue):
(WebCore::PlatformSpeechSynthesisProviderEfl::voiceName):
(WebCore::PlatformSpeechSynthesisProviderEfl::engineInit):
(WebCore::PlatformSpeechSynthesisProviderEfl::currentVoice):
(WebCore::PlatformSpeechSynthesisProviderEfl::initializeVoiceList):
(WebCore::PlatformSpeechSynthesisProviderEfl::speak):
(WebCore::PlatformSpeechSynthesisProviderEfl::cancel):
(WebCore::PlatformSpeechSynthesisProviderEfl::fireSpeechEvent):
* platform/efl/PlatformSpeechSynthesisProviderEfl.h:
* platform/efl/PlatformSpeechSynthesizerEfl.cpp:
(WebCore::PlatformSpeechSynthesizer::PlatformSpeechSynthesizer):
(WebCore::PlatformSpeechSynthesizer::initializeVoiceList):
(WebCore::PlatformSpeechSynthesizer::pause):
(WebCore::PlatformSpeechSynthesizer::resume):
(WebCore::PlatformSpeechSynthesizer::speak):
(WebCore::PlatformSpeechSynthesizer::cancel):

Tools:

Add espeak dependency.

* efl/install-dependencies:

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (172955 => 172956)


--- trunk/ChangeLog	2014-08-26 11:18:10 UTC (rev 172955)
+++ trunk/ChangeLog	2014-08-26 11:25:49 UTC (rev 172956)
@@ -1,3 +1,15 @@
+2014-08-26  Krzysztof Czech  <k.cz...@samsung.com>
+
+        [EFL] Utilize espeak as a synthesizer back-end for WebSpeech
+        https://bugs.webkit.org/show_bug.cgi?id=136127
+
+        Reviewed by Gyuyoung Kim.
+
+        Add build support for espeak.
+
+        * Source/cmake/FindEspeak.cmake: Added.
+        * Source/cmake/OptionsEfl.cmake: Add Espeak dependency.
+
 2014-08-26  Ryuan Choi  <ryuan.c...@samsung.com>
 
         [EFL] Build break using clang

Modified: trunk/Source/WebCore/ChangeLog (172955 => 172956)


--- trunk/Source/WebCore/ChangeLog	2014-08-26 11:18:10 UTC (rev 172955)
+++ trunk/Source/WebCore/ChangeLog	2014-08-26 11:25:49 UTC (rev 172956)
@@ -1,3 +1,34 @@
+2014-08-26  Krzysztof Czech  <k.cz...@samsung.com>
+
+        [EFL] Utilize espeak as a synthesizer back-end for WebSpeech
+        https://bugs.webkit.org/show_bug.cgi?id=136127
+
+        Reviewed by Gyuyoung Kim.
+
+        Utilize espeak API to have support for speak, cancel and initializeVoiceList.
+
+        * PlatformEfl.cmake:
+        * platform/efl/PlatformSpeechSynthesisProviderEfl.cpp:
+        (WebCore::PlatformSpeechSynthesisProviderEfl::PlatformSpeechSynthesisProviderEfl):
+        (WebCore::PlatformSpeechSynthesisProviderEfl::convertRateToEspeakValue):
+        (WebCore::PlatformSpeechSynthesisProviderEfl::convertVolumeToEspeakValue):
+        (WebCore::PlatformSpeechSynthesisProviderEfl::convertPitchToEspeakValue):
+        (WebCore::PlatformSpeechSynthesisProviderEfl::voiceName):
+        (WebCore::PlatformSpeechSynthesisProviderEfl::engineInit):
+        (WebCore::PlatformSpeechSynthesisProviderEfl::currentVoice):
+        (WebCore::PlatformSpeechSynthesisProviderEfl::initializeVoiceList):
+        (WebCore::PlatformSpeechSynthesisProviderEfl::speak):
+        (WebCore::PlatformSpeechSynthesisProviderEfl::cancel):
+        (WebCore::PlatformSpeechSynthesisProviderEfl::fireSpeechEvent):
+        * platform/efl/PlatformSpeechSynthesisProviderEfl.h:
+        * platform/efl/PlatformSpeechSynthesizerEfl.cpp:
+        (WebCore::PlatformSpeechSynthesizer::PlatformSpeechSynthesizer):
+        (WebCore::PlatformSpeechSynthesizer::initializeVoiceList):
+        (WebCore::PlatformSpeechSynthesizer::pause):
+        (WebCore::PlatformSpeechSynthesizer::resume):
+        (WebCore::PlatformSpeechSynthesizer::speak):
+        (WebCore::PlatformSpeechSynthesizer::cancel):
+
 2014-08-26  Ryuan Choi  <ryuan.c...@samsung.com>
 
         [EFL] Build break using clang

Modified: trunk/Source/WebCore/PlatformEfl.cmake (172955 => 172956)


--- trunk/Source/WebCore/PlatformEfl.cmake	2014-08-26 11:18:10 UTC (rev 172955)
+++ trunk/Source/WebCore/PlatformEfl.cmake	2014-08-26 11:25:49 UTC (rev 172956)
@@ -481,6 +481,12 @@
 endif ()
 
 if (ENABLE_SPEECH_SYNTHESIS)
+    list(APPEND WebCore_INCLUDE_DIRECTORIES
+        ${ESPEAK_INCLUDE_DIRS}
+    )
+    list(APPEND WebCore_LIBRARIES
+        ${ESPEAK_LIBRARIES}
+    )
     list(APPEND WebCore_SOURCES
         platform/efl/PlatformSpeechSynthesizerEfl.cpp
         platform/efl/PlatformSpeechSynthesisProviderEfl.cpp

Modified: trunk/Source/WebCore/platform/efl/PlatformSpeechSynthesisProviderEfl.cpp (172955 => 172956)


--- trunk/Source/WebCore/platform/efl/PlatformSpeechSynthesisProviderEfl.cpp	2014-08-26 11:18:10 UTC (rev 172955)
+++ trunk/Source/WebCore/platform/efl/PlatformSpeechSynthesisProviderEfl.cpp	2014-08-26 11:25:49 UTC (rev 172956)
@@ -32,11 +32,13 @@
 #include <PlatformSpeechSynthesisUtterance.h>
 #include <PlatformSpeechSynthesisVoice.h>
 #include <PlatformSpeechSynthesizer.h>
+#include <wtf/text/CString.h>
 
 namespace WebCore {
 
-PlatformSpeechSynthesisProviderEfl::PlatformSpeechSynthesisProviderEfl(PlatformSpeechSynthesizer* platformSpeechSynthesizer)
-    : m_platformSpeechSynthesizer(platformSpeechSynthesizer)
+PlatformSpeechSynthesisProviderEfl::PlatformSpeechSynthesisProviderEfl(PlatformSpeechSynthesizer* client)
+    : m_isEngineStarted(false)
+    , m_platformSpeechSynthesizer(client)
 {
 }
 
@@ -44,10 +46,86 @@
 {
 }
 
+int PlatformSpeechSynthesisProviderEfl::convertRateToEspeakValue(float rate) const
+{
+    // The normal value that Espeak expects is 175, minimum is 80 and maximum 450
+    return espeakRATE_NORMAL * rate;
+}
+
+int PlatformSpeechSynthesisProviderEfl::convertVolumeToEspeakValue(float volume) const
+{
+    // 0 = silence, 100 = normal, greater values may produce distortion
+    return volume * 100;
+}
+
+int PlatformSpeechSynthesisProviderEfl::convertPitchToEspeakValue(float pitch) const
+{
+    // 0 = minimum, 50 = normal, 100 = maximum
+    return pitch * 50;
+}
+
+String PlatformSpeechSynthesisProviderEfl::voiceName(PassRefPtr<PlatformSpeechSynthesisUtterance> utterance) const
+{
+    if (!m_platformSpeechSynthesizer)
+        return String();
+
+    if (!utterance->lang().isEmpty()) {
+        const String& language = utterance->lang();
+        const Vector<RefPtr<PlatformSpeechSynthesisVoice>>& voiceList = m_platformSpeechSynthesizer->voiceList();
+        for (const auto& voice : voiceList) {
+            // Espeak adds an empty character at the beginning of the language
+            unsigned length = voice->lang().length();
+            String lang = voice->lang().substring(1, length);
+            if (equalIgnoringCase(language, lang))
+                return voice->name();
+        }
+    }
+
+    espeak_VOICE* espeakVoice = currentVoice();
+    ASSERT(espeakVoice);
+    return ASCIILiteral(espeakVoice->name);
+}
+
+bool PlatformSpeechSynthesisProviderEfl::engineInit()
+{
+    if (!m_isEngineStarted) {
+        if (!(m_isEngineStarted = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, 0, 0) != EE_INTERNAL_ERROR))
+            return false;
+        espeak_SetVoiceByName("default");
+    }
+    return true;
+}
+
+espeak_VOICE* PlatformSpeechSynthesisProviderEfl::currentVoice() const
+{
+    return espeak_GetCurrentVoice();
+}
+
 void PlatformSpeechSynthesisProviderEfl::initializeVoiceList(Vector<RefPtr<PlatformSpeechSynthesisVoice>>& voiceList)
 {
-    UNUSED_PARAM(voiceList);
-    notImplemented();
+    if (!engineInit()) {
+        fireSpeechEvent(SpeechError);
+        return;
+    }
+
+    espeak_VOICE* espeakVoice = currentVoice();
+    ASSERT(espeakVoice);
+    String currentLanguage = ASCIILiteral(espeakVoice->languages);
+
+    const espeak_VOICE** voices = espeak_ListVoices(nullptr);
+    if (!voices) {
+        fireSpeechEvent(SpeechError);
+        return;
+    }
+
+    // Voices array is terminated by the nullptr
+    for (int i = 0; voices[i]; i++) {
+        const espeak_VOICE* voice = voices[i];
+        String id = ASCIILiteral(voice->identifier);
+        String name = ASCIILiteral(voice->name);
+        String language = ASCIILiteral(voice->languages);
+        voiceList.append(PlatformSpeechSynthesisVoice::create(id, name, language, true, language == currentLanguage));
+    }
 }
 
 void PlatformSpeechSynthesisProviderEfl::pause()
@@ -62,15 +140,65 @@
 
 void PlatformSpeechSynthesisProviderEfl::speak(PassRefPtr<PlatformSpeechSynthesisUtterance> utterance)
 {
-    UNUSED_PARAM(utterance);
-    notImplemented();
+    if (!engineInit() || !utterance) {
+        fireSpeechEvent(SpeechError);
+        return;
+    }
+
+    m_utterance = utterance;
+    String voice = voiceName(m_utterance);
+    espeak_SetVoiceByName(voice.utf8().data());
+    espeak_SetParameter(espeakRATE, convertRateToEspeakValue(m_utterance->rate()), 0);
+    espeak_SetParameter(espeakVOLUME, convertVolumeToEspeakValue(m_utterance->volume()), 0);
+    espeak_SetParameter(espeakPITCH, convertPitchToEspeakValue(m_utterance->pitch()), 0);
+
+    String textToRead = m_utterance->text();
+    espeak_ERROR err = espeak_Synth(textToRead.utf8().data(), textToRead.length(), 0, POS_CHARACTER, 0, espeakCHARS_AUTO, 0, nullptr);
+    if (err == EE_INTERNAL_ERROR) {
+        fireSpeechEvent(SpeechError);
+        m_utterance = nullptr;
+        return;
+    }
+
+    fireSpeechEvent(SpeechStart);
 }
 
 void PlatformSpeechSynthesisProviderEfl::cancel()
 {
-    notImplemented();
+    if (!m_isEngineStarted || !m_utterance)
+        return;
+
+    if (espeak_Cancel() == EE_INTERNAL_ERROR) {
+        fireSpeechEvent(SpeechError);
+        m_utterance = nullptr;
+        return;
+    }
+    fireSpeechEvent(SpeechCancel);
+    m_utterance = nullptr;
 }
 
+void PlatformSpeechSynthesisProviderEfl::fireSpeechEvent(SpeechEvent speechEvent)
+{
+    switch (speechEvent) {
+    case SpeechStart:
+        m_platformSpeechSynthesizer->client()->didStartSpeaking(m_utterance);
+        break;
+    case SpeechPause:
+        m_platformSpeechSynthesizer->client()->didPauseSpeaking(m_utterance);
+        break;
+    case SpeechResume:
+        m_platformSpeechSynthesizer->client()->didResumeSpeaking(m_utterance);
+        break;
+    case SpeechError:
+        m_isEngineStarted = false;
+    case SpeechCancel:
+        m_platformSpeechSynthesizer->client()->speakingErrorOccurred(m_utterance);
+        break;
+    default:
+        ASSERT_NOT_REACHED();
+    };
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/platform/efl/PlatformSpeechSynthesisProviderEfl.h (172955 => 172956)


--- trunk/Source/WebCore/platform/efl/PlatformSpeechSynthesisProviderEfl.h	2014-08-26 11:18:10 UTC (rev 172955)
+++ trunk/Source/WebCore/platform/efl/PlatformSpeechSynthesisProviderEfl.h	2014-08-26 11:25:49 UTC (rev 172956)
@@ -28,8 +28,10 @@
 
 #if ENABLE(SPEECH_SYNTHESIS)
 
+#include <speak_lib.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -39,6 +41,14 @@
 
 class PlatformSpeechSynthesisProviderEfl {
 public:
+    enum SpeechEvent {
+        SpeechError,
+        SpeechCancel,
+        SpeechPause,
+        SpeechResume,
+        SpeechStart
+    };
+
     explicit PlatformSpeechSynthesisProviderEfl(PlatformSpeechSynthesizer*);
     ~PlatformSpeechSynthesisProviderEfl();
 
@@ -48,7 +58,19 @@
     void speak(PassRefPtr<PlatformSpeechSynthesisUtterance>);
     void cancel();
 private:
+    bool engineInit();
+
+    int convertRateToEspeakValue(float) const;
+    int convertVolumeToEspeakValue(float) const;
+    int convertPitchToEspeakValue(float) const;
+
+    espeak_VOICE* currentVoice() const;
+    String voiceName(PassRefPtr<PlatformSpeechSynthesisUtterance>) const;
+    void fireSpeechEvent(SpeechEvent);
+
+    bool m_isEngineStarted;
     PlatformSpeechSynthesizer* m_platformSpeechSynthesizer;
+    RefPtr<PlatformSpeechSynthesisUtterance> m_utterance;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/efl/PlatformSpeechSynthesizerEfl.cpp (172955 => 172956)


--- trunk/Source/WebCore/platform/efl/PlatformSpeechSynthesizerEfl.cpp	2014-08-26 11:18:10 UTC (rev 172955)
+++ trunk/Source/WebCore/platform/efl/PlatformSpeechSynthesizerEfl.cpp	2014-08-26 11:25:49 UTC (rev 172956)
@@ -38,7 +38,6 @@
     : m_voiceListIsInitialized(false)
     , m_speechSynthesizerClient(client)
     , m_platformSpeechWrapper(std::make_unique<PlatformSpeechSynthesisProviderEfl>(this))
-
 {
 }
 
@@ -48,26 +47,31 @@
 
 void PlatformSpeechSynthesizer::initializeVoiceList()
 {
+    ASSERT(m_platformSpeechWrapper);
     m_platformSpeechWrapper->initializeVoiceList(m_voiceList);
 }
 
 void PlatformSpeechSynthesizer::pause()
 {
+    ASSERT(m_platformSpeechWrapper);
     m_platformSpeechWrapper->pause();
 }
 
 void PlatformSpeechSynthesizer::resume()
 {
+    ASSERT(m_platformSpeechWrapper);
     m_platformSpeechWrapper->resume();
 }
 
 void PlatformSpeechSynthesizer::speak(PassRefPtr<PlatformSpeechSynthesisUtterance> utterance)
 {
+    ASSERT(m_platformSpeechWrapper);
     m_platformSpeechWrapper->speak(utterance);
 }
 
 void PlatformSpeechSynthesizer::cancel()
 {
+    ASSERT(m_platformSpeechWrapper);
     m_platformSpeechWrapper->cancel();
 }
 

Added: trunk/Source/cmake/FindEspeak.cmake (0 => 172956)


--- trunk/Source/cmake/FindEspeak.cmake	                        (rev 0)
+++ trunk/Source/cmake/FindEspeak.cmake	2014-08-26 11:25:49 UTC (rev 172956)
@@ -0,0 +1,42 @@
+# - Try to find Espeak
+# Once done, this will define
+#
+#  ESPEAK_INCLUDE_DIRS - the Espeak include drectories
+#  ESPEAK_LIBRARIES - link these to use Espeak
+#
+# Copyright (C) 2014 Samsung Electronics
+#
+# 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 THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``A
+# 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 HOLDER OR ITS
+# 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.
+
+find_path(ESPEAK_INCLUDE_DIRS
+    NAMES speak_lib.h
+    PATH_SUFFIXES espeak
+)
+
+find_library(ESPEAK_LIBRARIES
+    NAMES espeak
+)
+
+mark_as_advanced(
+    ESPEAK_INCLUDE_DIRS
+    ESPEAK_LIBRARIES
+)

Modified: trunk/Source/cmake/OptionsEfl.cmake (172955 => 172956)


--- trunk/Source/cmake/OptionsEfl.cmake	2014-08-26 11:18:10 UTC (rev 172955)
+++ trunk/Source/cmake/OptionsEfl.cmake	2014-08-26 11:25:49 UTC (rev 172956)
@@ -312,6 +312,7 @@
 endif ()
 
 if (ENABLE_SPEECH_SYNTHESIS)
+    find_package(Espeak REQUIRED)
     add_definitions(-DENABLE_SPEECH_SYNTHESIS=1)
 endif ()
 

Modified: trunk/Tools/ChangeLog (172955 => 172956)


--- trunk/Tools/ChangeLog	2014-08-26 11:18:10 UTC (rev 172955)
+++ trunk/Tools/ChangeLog	2014-08-26 11:25:49 UTC (rev 172956)
@@ -1,3 +1,14 @@
+2014-08-26  Krzysztof Czech  <k.cz...@samsung.com>
+
+        [EFL] Utilize espeak as a synthesizer back-end for WebSpeech
+        https://bugs.webkit.org/show_bug.cgi?id=136127
+
+        Reviewed by Gyuyoung Kim.
+
+        Add espeak dependency.
+
+        * efl/install-dependencies:
+
 2014-08-25  Alexey Proskuryakov  <a...@apple.com>
 
         Remove a little more accidentally landed code from r172891.

Modified: trunk/Tools/efl/install-dependencies (172955 => 172956)


--- trunk/Tools/efl/install-dependencies	2014-08-26 11:18:10 UTC (rev 172955)
+++ trunk/Tools/efl/install-dependencies	2014-08-26 11:25:49 UTC (rev 172956)
@@ -39,6 +39,7 @@
         libc++abi-dev \
         libdbus-1-dev \
         libenchant-dev \
+        libespeak-dev \
         libfaad-dev \
         libffi-dev \
         libfreetype6-dev \
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to