Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple Computer, Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 PlatformSpeechSynthesizerMock* PlatformSpeechSynthesizerMock::create(PlatformSpe echSynthesizerClient* client) | 34 PlatformSpeechSynthesizerMock* PlatformSpeechSynthesizerMock::create(PlatformSpe echSynthesizerClient* client) |
| 35 { | 35 { |
| 36 PlatformSpeechSynthesizerMock* synthesizer = new PlatformSpeechSynthesizerMo ck(client); | 36 PlatformSpeechSynthesizerMock* synthesizer = new PlatformSpeechSynthesizerMo ck(client); |
| 37 synthesizer->initializeVoiceList(); | 37 synthesizer->initializeVoiceList(); |
| 38 client->voicesDidChange(); | 38 client->voicesDidChange(); |
| 39 return synthesizer; | 39 return synthesizer; |
| 40 } | 40 } |
| 41 | 41 |
| 42 PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynth esizerClient* client) | 42 PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynth esizerClient* client) |
| 43 : PlatformSpeechSynthesizer(client) | 43 : PlatformSpeechSynthesizer(client) |
| 44 , m_speakingErrorOccurredTimer(this, &PlatformSpeechSynthesizerMock::speakin gErrorOccurred) | |
| 44 , m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFini shed) | 45 , m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFini shed) |
| 45 , m_speakingErrorOccurredTimer(this, &PlatformSpeechSynthesizerMock::speakin gErrorOccurred) | 46 , m_speakingNextTimer(this, &PlatformSpeechSynthesizerMock::speakingNext) |
|
haraken
2015/01/31 01:38:03
Why do we need to speakNow here? In the previous c
sof
2015/01/31 06:06:19
I don't understand, the ctor just initializes the
| |
| 46 { | 47 { |
| 47 } | 48 } |
| 48 | 49 |
| 49 PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock() | 50 PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock() |
| 50 { | 51 { |
| 51 m_speakingFinishedTimer.stop(); | 52 } |
| 52 m_speakingErrorOccurredTimer.stop(); | 53 |
| 54 void PlatformSpeechSynthesizerMock::speakingErrorOccurred(Timer<PlatformSpeechSy nthesizerMock>*) | |
| 55 { | |
| 56 ASSERT(m_currentUtterance); | |
| 57 // Per spec, removes all utterances from the queue. | |
| 58 m_queuedUtterances.clear(); | |
| 59 | |
| 60 client()->speakingErrorOccurred(m_currentUtterance); | |
| 61 speakNext(); | |
| 53 } | 62 } |
| 54 | 63 |
| 55 void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthes izerMock>*) | 64 void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthes izerMock>*) |
| 56 { | 65 { |
| 57 ASSERT(m_utterance.get()); | 66 ASSERT(m_currentUtterance); |
| 58 client()->didFinishSpeaking(m_utterance); | 67 client()->didFinishSpeaking(m_currentUtterance); |
| 59 m_utterance = nullptr; | 68 speakNext(); |
| 60 } | 69 } |
| 61 | 70 |
| 62 void PlatformSpeechSynthesizerMock::speakingErrorOccurred(Timer<PlatformSpeechSy nthesizerMock>*) | 71 void PlatformSpeechSynthesizerMock::speakingNext(Timer<PlatformSpeechSynthesizer Mock>*) |
| 63 { | 72 { |
| 64 ASSERT(m_utterance.get()); | 73 ASSERT(m_currentUtterance); |
| 65 client()->speakingErrorOccurred(m_utterance); | 74 speakNow(); |
| 66 m_utterance = nullptr; | 75 } |
| 76 | |
| 77 void PlatformSpeechSynthesizerMock::speakNext() | |
| 78 { | |
| 79 if (m_speakingErrorOccurredTimer.isActive()) | |
| 80 return; | |
| 81 | |
| 82 if (m_queuedUtterances.isEmpty()) { | |
| 83 m_currentUtterance = nullptr; | |
| 84 return; | |
| 85 } | |
| 86 m_currentUtterance = m_queuedUtterances.takeFirst(); | |
| 87 // Give others a look in before starting with next. | |
| 88 m_speakingNextTimer.startOneShot(.2, FROM_HERE); | |
|
haraken
2015/01/31 01:38:03
I don't know if .2 is good or not though :)
dmazzoni
2015/01/31 06:51:11
Do we need a delay between the end of one utteranc
sof
2015/01/31 07:24:24
ok, will align with that.
sof
2015/01/31 07:36:19
Done, removing the "next" timer that was previousl
| |
| 67 } | 89 } |
| 68 | 90 |
| 69 void PlatformSpeechSynthesizerMock::initializeVoiceList() | 91 void PlatformSpeechSynthesizerMock::initializeVoiceList() |
| 70 { | 92 { |
| 71 m_voiceList.clear(); | 93 m_voiceList.clear(); |
| 72 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.b ruce"), String("bruce"), String("en-US"), true, true)); | 94 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.b ruce"), String("bruce"), String("en-US"), true, true)); |
| 73 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.c lark"), String("clark"), String("en-US"), true, false)); | 95 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.c lark"), String("clark"), String("en-US"), true, false)); |
| 74 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.l ogan"), String("logan"), String("fr-CA"), true, true)); | 96 m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.l ogan"), String("logan"), String("fr-CA"), true, true)); |
| 75 } | 97 } |
| 76 | 98 |
| 77 void PlatformSpeechSynthesizerMock::speak(PlatformSpeechSynthesisUtterance* utte rance) | 99 void PlatformSpeechSynthesizerMock::speak(PlatformSpeechSynthesisUtterance* utte rance) |
| 78 { | 100 { |
| 79 ASSERT(!m_utterance); | 101 if (!m_currentUtterance) { |
| 80 m_utterance = utterance; | 102 m_currentUtterance = utterance; |
| 81 client()->didStartSpeaking(m_utterance); | 103 speakNow(); |
| 104 return; | |
| 105 } | |
| 106 m_queuedUtterances.append(utterance); | |
| 107 } | |
| 108 | |
| 109 void PlatformSpeechSynthesizerMock::speakNow() | |
| 110 { | |
| 111 ASSERT(m_currentUtterance); | |
| 112 client()->didStartSpeaking(m_currentUtterance); | |
| 82 | 113 |
| 83 // Fire a fake word and then sentence boundary event. | 114 // Fire a fake word and then sentence boundary event. |
| 84 client()->boundaryEventOccurred(m_utterance, SpeechWordBoundary, 0); | 115 client()->boundaryEventOccurred(m_currentUtterance, SpeechWordBoundary, 0); |
| 85 client()->boundaryEventOccurred(m_utterance, SpeechSentenceBoundary, m_utter ance->text().length()); | 116 client()->boundaryEventOccurred(m_currentUtterance, SpeechSentenceBoundary, m_currentUtterance->text().length()); |
| 86 | 117 |
| 87 // Give the fake speech job some time so that pause and other functions have time to be called. | 118 // Give the fake speech job some time so that pause and other functions have time to be called. |
| 88 m_speakingFinishedTimer.startOneShot(.1, FROM_HERE); | 119 m_speakingFinishedTimer.startOneShot(.1, FROM_HERE); |
| 89 } | 120 } |
| 90 | 121 |
| 91 void PlatformSpeechSynthesizerMock::cancel() | 122 void PlatformSpeechSynthesizerMock::cancel() |
|
dmazzoni
2015/01/31 06:51:11
This should remove all utterances from the queue,
sof
2015/01/31 07:24:24
It should, but doesn't it suffice to do it in spea
dmazzoni
2015/01/31 07:43:30
I don't think that's right. If I call cancel() and
sof
2015/01/31 07:56:50
That makes good sense - switched to that behavior
| |
| 92 { | 123 { |
| 93 if (!m_utterance) | 124 if (!m_currentUtterance) |
| 94 return; | 125 return; |
| 95 | 126 |
| 96 m_speakingFinishedTimer.stop(); | 127 m_speakingFinishedTimer.stop(); |
| 128 m_speakingNextTimer.stop(); | |
| 97 m_speakingErrorOccurredTimer.startOneShot(.1, FROM_HERE); | 129 m_speakingErrorOccurredTimer.startOneShot(.1, FROM_HERE); |
| 98 } | 130 } |
| 99 | 131 |
| 100 void PlatformSpeechSynthesizerMock::pause() | 132 void PlatformSpeechSynthesizerMock::pause() |
| 101 { | 133 { |
| 102 client()->didPauseSpeaking(m_utterance); | 134 client()->didPauseSpeaking(m_currentUtterance); |
| 103 } | 135 } |
| 104 | 136 |
| 105 void PlatformSpeechSynthesizerMock::resume() | 137 void PlatformSpeechSynthesizerMock::resume() |
| 106 { | 138 { |
| 107 client()->didResumeSpeaking(m_utterance); | 139 client()->didResumeSpeaking(m_currentUtterance); |
| 108 } | 140 } |
| 109 | 141 |
| 110 void PlatformSpeechSynthesizerMock::trace(Visitor* visitor) | 142 void PlatformSpeechSynthesizerMock::trace(Visitor* visitor) |
| 111 { | 143 { |
| 112 visitor->trace(m_utterance); | 144 visitor->trace(m_currentUtterance); |
| 145 visitor->trace(m_queuedUtterances); | |
| 113 PlatformSpeechSynthesizer::trace(visitor); | 146 PlatformSpeechSynthesizer::trace(visitor); |
| 114 } | 147 } |
| 115 | 148 |
| 116 } // namespace blink | 149 } // namespace blink |
| OLD | NEW |