Changeset 144335 in webkit


Ignore:
Timestamp:
Feb 28, 2013 11:33:48 AM (11 years ago)
Author:
Chris Fleizach
Message:

WebSpeech: support the boundary event
https://bugs.webkit.org/show_bug.cgi?id=107350

Reviewed by Beth Dakin.

Source/WebCore:

Generate boundary events for speech synthesis and have them fire the appropriate events.
This implements for the Mac platform, as well as simulating these events in the mock
synthesizer for testing purposes.

Test: platform/mac/fast/speechsynthesis/speech-synthesis-boundary-events.html

  • Modules/speech/SpeechSynthesis.cpp:

(WebCore):
(WebCore::SpeechSynthesis::boundaryEventOccurred):

  • Modules/speech/SpeechSynthesis.h:

(SpeechSynthesis):

  • platform/PlatformSpeechSynthesizer.h:

(WebCore):
(PlatformSpeechSynthesizerClient):

  • platform/mac/PlatformSpeechSynthesizerMac.mm:

(-[WebSpeechSynthesisWrapper speechSynthesizer:willSpeakWord:ofString:]):

  • platform/mock/PlatformSpeechSynthesizerMock.cpp:

(WebCore::PlatformSpeechSynthesizerMock::speak):

LayoutTests:

  • platform/mac/fast/speechsynthesis/speech-synthesis-boundary-events-expected.txt: Added.
  • platform/mac/fast/speechsynthesis/speech-synthesis-boundary-events.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r144331 r144335  
     12013-02-28  Chris Fleizach  <cfleizach@apple.com>
     2
     3        WebSpeech: support the boundary event
     4        https://bugs.webkit.org/show_bug.cgi?id=107350
     5
     6        Reviewed by Beth Dakin.
     7
     8        * platform/mac/fast/speechsynthesis/speech-synthesis-boundary-events-expected.txt: Added.
     9        * platform/mac/fast/speechsynthesis/speech-synthesis-boundary-events.html: Added.
     10
    1112013-02-28  Adam Barth  <abarth@webkit.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r144330 r144335  
     12013-02-28  Chris Fleizach  <cfleizach@apple.com>
     2
     3        WebSpeech: support the boundary event
     4        https://bugs.webkit.org/show_bug.cgi?id=107350
     5
     6        Reviewed by Beth Dakin.
     7
     8        Generate boundary events for speech synthesis and have them fire the appropriate events.
     9        This implements for the Mac platform, as well as simulating these events in the mock
     10        synthesizer for testing purposes.
     11
     12        Test: platform/mac/fast/speechsynthesis/speech-synthesis-boundary-events.html
     13
     14        * Modules/speech/SpeechSynthesis.cpp:
     15        (WebCore):
     16        (WebCore::SpeechSynthesis::boundaryEventOccurred):
     17        * Modules/speech/SpeechSynthesis.h:
     18        (SpeechSynthesis):
     19        * platform/PlatformSpeechSynthesizer.h:
     20        (WebCore):
     21        (PlatformSpeechSynthesizerClient):
     22        * platform/mac/PlatformSpeechSynthesizerMac.mm:
     23        (-[WebSpeechSynthesisWrapper speechSynthesizer:willSpeakWord:ofString:]):
     24        * platform/mock/PlatformSpeechSynthesizerMock.cpp:
     25        (WebCore::PlatformSpeechSynthesizerMock::speak):
     26
    1272013-02-28  David Grogan  <dgrogan@chromium.org>
    228
  • trunk/Source/WebCore/Modules/speech/SpeechSynthesis.cpp

    r144244 r144335  
    152152    }
    153153}
     154   
     155void SpeechSynthesis::boundaryEventOccurred(const PlatformSpeechSynthesisUtterance* utterance, SpeechBoundary boundary, unsigned charIndex)
     156{
     157    DEFINE_STATIC_LOCAL(const String, wordBoundaryString, (ASCIILiteral("word")));
     158    DEFINE_STATIC_LOCAL(const String, sentenceBoundaryString, (ASCIILiteral("sentence")));
     159
     160    switch (boundary) {
     161    case SpeechWordBoundary:
     162        fireEvent(eventNames().boundaryEvent, static_cast<SpeechSynthesisUtterance*>(utterance->client()), charIndex, wordBoundaryString);
     163        break;
     164    case SpeechSentenceBoundary:
     165        fireEvent(eventNames().boundaryEvent, static_cast<SpeechSynthesisUtterance*>(utterance->client()), charIndex, sentenceBoundaryString);
     166        break;
     167    default:
     168        ASSERT_NOT_REACHED();
     169    }
     170}
    154171
    155172void SpeechSynthesis::didStartSpeaking(const PlatformSpeechSynthesisUtterance* utterance)
  • trunk/Source/WebCore/Modules/speech/SpeechSynthesis.h

    r144220 r144335  
    7171    virtual void didFinishSpeaking(const PlatformSpeechSynthesisUtterance*) OVERRIDE;
    7272    virtual void speakingErrorOccurred(const PlatformSpeechSynthesisUtterance*) OVERRIDE;
     73    virtual void boundaryEventOccurred(const PlatformSpeechSynthesisUtterance*, SpeechBoundary, unsigned charIndex) OVERRIDE;
    7374
    7475    void startSpeakingImmediately(SpeechSynthesisUtterance*);
  • trunk/Source/WebCore/platform/PlatformSpeechSynthesizer.h

    r144244 r144335  
    3939
    4040namespace WebCore {
    41    
     41
     42enum SpeechBoundary {
     43    SpeechWordBoundary,
     44    SpeechSentenceBoundary
     45};
     46
    4247class PlatformSpeechSynthesisUtterance;
    4348
     
    4954    virtual void didResumeSpeaking(const PlatformSpeechSynthesisUtterance*) = 0;
    5055    virtual void speakingErrorOccurred(const PlatformSpeechSynthesisUtterance*) = 0;
    51    
     56    virtual void boundaryEventOccurred(const PlatformSpeechSynthesisUtterance*, SpeechBoundary, unsigned charIndex) = 0;
    5257    virtual void voicesDidChange() = 0;
    5358protected:
  • trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm

    r144244 r144335  
    158158}
    159159
     160- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender willSpeakWord:(NSRange)characterRange ofString:(NSString *)string
     161{
     162    ASSERT(m_utterance);
     163    UNUSED_PARAM(sender);
     164    UNUSED_PARAM(string);
     165
     166    // Mac platform only supports word boundaries.
     167    m_synthesizerObject->client()->boundaryEventOccurred(m_utterance, WebCore::SpeechWordBoundary, characterRange.location);
     168}
     169
    160170@end
    161171
  • trunk/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp

    r144244 r144335  
    2626#include "config.h"
    2727#include "PlatformSpeechSynthesizerMock.h"
     28#include "PlatformSpeechSynthesisUtterance.h"
    2829
    2930#if ENABLE(SPEECH_SYNTHESIS)
     
    6768    client()->didStartSpeaking(m_utterance);
    6869   
     70    // Fire a fake word and then sentence boundary event.
     71    client()->boundaryEventOccurred(m_utterance, SpeechWordBoundary, 0);
     72    client()->boundaryEventOccurred(m_utterance, SpeechSentenceBoundary, m_utterance->text().length());
     73   
    6974    // Give the fake speech job some time so that pause and other functions have time to be called.
    7075    m_speakingFinishedTimer.startOneShot(.1);
Note: See TracChangeset for help on using the changeset viewer.