Changeset 144220 in webkit


Ignore:
Timestamp:
Feb 27, 2013 12:14:45 PM (11 years ago)
Author:
Chris Fleizach
Message:

WebSpeech: Support pause/resume ability
https://bugs.webkit.org/show_bug.cgi?id=107345

Reviewed by Beth Dakin.

Source/WebCore:

Add in the pause/resume functionality to SpeechSynthesis. Also hook up
the callback events.

Test: platform/mac/fast/speechsynthesis/speech-synthesis-pause-resume.html

  • Modules/speech/SpeechSynthesis.cpp:

(WebCore::SpeechSynthesis::SpeechSynthesis):
(WebCore::SpeechSynthesis::pending):
(WebCore::SpeechSynthesis::paused):
(WebCore::SpeechSynthesis::startSpeakingImmediately):
(WebCore::SpeechSynthesis::pause):
(WebCore::SpeechSynthesis::resume):
(WebCore):
(WebCore::SpeechSynthesis::didPauseSpeaking):
(WebCore::SpeechSynthesis::didResumeSpeaking):

  • Modules/speech/SpeechSynthesis.h:

(SpeechSynthesis):

  • platform/PlatformSpeechSynthesizer.h:

(PlatformSpeechSynthesizerClient):
(PlatformSpeechSynthesizer):

  • platform/mac/PlatformSpeechSynthesizerMac.mm:

(-[WebSpeechSynthesisWrapper speakUtterance:WebCore::]):
(-[WebSpeechSynthesisWrapper pause]):
(-[WebSpeechSynthesisWrapper resume]):
(-[WebSpeechSynthesisWrapper speechSynthesizer:didFinishSpeaking:]):
(WebCore::PlatformSpeechSynthesizer::pause):
(WebCore):
(WebCore::PlatformSpeechSynthesizer::resume):

LayoutTests:

  • platform/mac/fast/speechsynthesis/speech-synthesis-pause-resume-expected.txt: Added.
  • platform/mac/fast/speechsynthesis/speech-synthesis-pause-resume.html: Added.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r144215 r144220  
     12013-02-27  Chris Fleizach  <cfleizach@apple.com>
     2
     3        WebSpeech: Support pause/resume ability
     4        https://bugs.webkit.org/show_bug.cgi?id=107345
     5
     6        Reviewed by Beth Dakin.
     7
     8        * platform/mac/fast/speechsynthesis/speech-synthesis-pause-resume-expected.txt: Added.
     9        * platform/mac/fast/speechsynthesis/speech-synthesis-pause-resume.html: Added.
     10
    1112013-02-27  Stephen Chenney  <schenney@chromium.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r144216 r144220  
     12013-02-27  Chris Fleizach  <cfleizach@apple.com>
     2
     3        WebSpeech: Support pause/resume ability
     4        https://bugs.webkit.org/show_bug.cgi?id=107345
     5
     6        Reviewed by Beth Dakin.
     7
     8        Add in the pause/resume functionality to SpeechSynthesis. Also hook up
     9        the callback events.
     10
     11        Test: platform/mac/fast/speechsynthesis/speech-synthesis-pause-resume.html
     12
     13        * Modules/speech/SpeechSynthesis.cpp:
     14        (WebCore::SpeechSynthesis::SpeechSynthesis):
     15        (WebCore::SpeechSynthesis::pending):
     16        (WebCore::SpeechSynthesis::paused):
     17        (WebCore::SpeechSynthesis::startSpeakingImmediately):
     18        (WebCore::SpeechSynthesis::pause):
     19        (WebCore::SpeechSynthesis::resume):
     20        (WebCore):
     21        (WebCore::SpeechSynthesis::didPauseSpeaking):
     22        (WebCore::SpeechSynthesis::didResumeSpeaking):
     23        * Modules/speech/SpeechSynthesis.h:
     24        (SpeechSynthesis):
     25        * platform/PlatformSpeechSynthesizer.h:
     26        (PlatformSpeechSynthesizerClient):
     27        (PlatformSpeechSynthesizer):
     28        * platform/mac/PlatformSpeechSynthesizerMac.mm:
     29        (-[WebSpeechSynthesisWrapper speakUtterance:WebCore::]):
     30        (-[WebSpeechSynthesisWrapper pause]):
     31        (-[WebSpeechSynthesisWrapper resume]):
     32        (-[WebSpeechSynthesisWrapper speechSynthesizer:didFinishSpeaking:]):
     33        (WebCore::PlatformSpeechSynthesizer::pause):
     34        (WebCore):
     35        (WebCore::PlatformSpeechSynthesizer::resume):
     36
    1372013-02-26  Alexey Proskuryakov  <ap@apple.com>
    238
  • trunk/Source/WebCore/Modules/speech/SpeechSynthesis.cpp

    r143136 r144220  
    4545    : m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this))
    4646    , m_currentSpeechUtterance(0)
     47    , m_isPaused(false)
    4748{
    4849}
     
    8182bool SpeechSynthesis::pending() const
    8283{
    83     return false;
     84    // This is true if there are any utterances that have not started.
     85    // That means there will be more than one in the queue.
     86    return m_utteranceQueue.size() > 1;
    8487}
    8588
    8689bool SpeechSynthesis::paused() const
    8790{
    88     return false;
     91    return m_isPaused;
    8992}
    9093
     
    9497    utterance->setStartTime(monotonicallyIncreasingTime());
    9598    m_currentSpeechUtterance = utterance;
     99    m_isPaused = false;
    96100    m_platformSpeechSynthesizer->speak(utterance->platformUtterance());
    97101}
     
    112116void SpeechSynthesis::pause()
    113117{
     118    if (!m_isPaused)
     119        m_platformSpeechSynthesizer->pause();
    114120}
    115121
    116122void SpeechSynthesis::resume()
    117123{
     124    m_platformSpeechSynthesizer->resume();
    118125}
    119126
     
    145152    fireEvent(eventNames().startEvent, static_cast<SpeechSynthesisUtterance*>(utterance->client()), 0, String());
    146153}
     154   
     155void SpeechSynthesis::didPauseSpeaking(const PlatformSpeechSynthesisUtterance* utterance)
     156{
     157    m_isPaused = true;
     158    fireEvent(eventNames().pauseEvent, static_cast<SpeechSynthesisUtterance*>(utterance->client()), 0, String());
     159}
     160
     161void SpeechSynthesis::didResumeSpeaking(const PlatformSpeechSynthesisUtterance* utterance)
     162{
     163    m_isPaused = false;
     164    fireEvent(eventNames().resumeEvent, static_cast<SpeechSynthesisUtterance*>(utterance->client()), 0, String());
     165}
    147166
    148167void SpeechSynthesis::didFinishSpeaking(const PlatformSpeechSynthesisUtterance* utterance)
  • trunk/Source/WebCore/Modules/speech/SpeechSynthesis.h

    r143136 r144220  
    6767    virtual void voicesDidChange() OVERRIDE;
    6868    virtual void didStartSpeaking(const PlatformSpeechSynthesisUtterance*) OVERRIDE;
     69    virtual void didPauseSpeaking(const PlatformSpeechSynthesisUtterance*) OVERRIDE;
     70    virtual void didResumeSpeaking(const PlatformSpeechSynthesisUtterance*) OVERRIDE;
    6971    virtual void didFinishSpeaking(const PlatformSpeechSynthesisUtterance*) OVERRIDE;
    7072    virtual void speakingErrorOccurred(const PlatformSpeechSynthesisUtterance*) OVERRIDE;
     
    7880    SpeechSynthesisUtterance* m_currentSpeechUtterance;
    7981    Deque<RefPtr<SpeechSynthesisUtterance> > m_utteranceQueue;
    80 
     82    bool m_isPaused;
    8183};
    8284   
  • trunk/Source/WebCore/platform/PlatformSpeechSynthesizer.h

    r143136 r144220  
    4646    virtual void didStartSpeaking(const PlatformSpeechSynthesisUtterance*) = 0;
    4747    virtual void didFinishSpeaking(const PlatformSpeechSynthesisUtterance*) = 0;
     48    virtual void didPauseSpeaking(const PlatformSpeechSynthesisUtterance*) = 0;
     49    virtual void didResumeSpeaking(const PlatformSpeechSynthesisUtterance*) = 0;
    4850    virtual void speakingErrorOccurred(const PlatformSpeechSynthesisUtterance*) = 0;
    4951   
     
    6163    const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& voiceList() const { return m_voiceList; }
    6264    virtual void speak(const PlatformSpeechSynthesisUtterance&);
     65    virtual void pause();
     66    virtual void resume();
    6367   
    6468    PlatformSpeechSynthesizerClient* client() const { return m_speechSynthesizerClient; }
  • trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm

    r142503 r144220  
    9999    }
    100100   
     101    NSString *voiceURI = nil;
    101102    if (utteranceVoiceByURI)
    102         [m_synthesizer setVoice:utteranceVoiceByURI->voiceURI()];
     103        voiceURI = utteranceVoiceByURI->voiceURI();
    103104    else if (utteranceVoiceByLanguage)
    104         [m_synthesizer setVoice:utteranceVoiceByLanguage->voiceURI()];
     105        voiceURI = utteranceVoiceByLanguage->voiceURI();
    105106    else
    106         [m_synthesizer setVoice:[NSSpeechSynthesizer defaultVoice]];
     107        voiceURI = [NSSpeechSynthesizer defaultVoice];
     108
     109    // Don't set the voice unless necessary. There's a bug in NSSpeechSynthesizer such that
     110    // setting the voice for the first time will cause the first speechDone callback to report it was unsuccessful.
     111    if (![[m_synthesizer voice] isEqualToString:voiceURI])
     112        [m_synthesizer setVoice:voiceURI];
    107113   
    108114    [m_synthesizer setRate:[self convertRateToWPM:utterance->rate()]];
     
    114120}
    115121
     122- (void)pause
     123{
     124    if (!m_utterance)
     125        return;
     126   
     127    [m_synthesizer pauseSpeakingAtBoundary:NSSpeechImmediateBoundary];
     128    m_synthesizerObject->client()->didPauseSpeaking(m_utterance);
     129}
     130
     131- (void)resume
     132{
     133    if (!m_utterance)
     134        return;
     135   
     136    [m_synthesizer continueSpeaking];
     137    m_synthesizerObject->client()->didResumeSpeaking(m_utterance);
     138}
     139
    116140- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)finishedSpeaking
    117141{
     142    ASSERT(m_utterance);
    118143    UNUSED_PARAM(sender);
    119144   
     
    154179}
    155180   
     181void PlatformSpeechSynthesizer::pause()
     182{
     183    [m_platformSpeechWrapper.get() pause];
     184}
     185
     186void PlatformSpeechSynthesizer::resume()
     187{
     188    [m_platformSpeechWrapper.get() resume];
     189}
     190   
    156191void PlatformSpeechSynthesizer::speak(const PlatformSpeechSynthesisUtterance& utterance)
    157192{
  • trunk/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.cpp

    r143136 r144220  
    6666    m_utterance = &utterance;
    6767    client()->didStartSpeaking(m_utterance);
    68     m_speakingFinishedTimer.startOneShot(0);
     68   
     69    // Give the fake speech job some time so that pause and other functions have time to be called.
     70    m_speakingFinishedTimer.startOneShot(.1);
    6971}
    7072
     73void PlatformSpeechSynthesizerMock::pause()
     74{
     75    client()->didPauseSpeaking(m_utterance);
     76}
     77
     78void PlatformSpeechSynthesizerMock::resume()
     79{
     80    client()->didResumeSpeaking(m_utterance);
     81}
     82
     83   
    7184} // namespace WebCore
    7285
  • trunk/Source/WebCore/platform/mock/PlatformSpeechSynthesizerMock.h

    r143136 r144220  
    4141    virtual ~PlatformSpeechSynthesizerMock();
    4242    virtual void speak(const PlatformSpeechSynthesisUtterance&);
     43    virtual void pause();
     44    virtual void resume();
    4345   
    4446private:
Note: See TracChangeset for help on using the changeset viewer.