PlatformSpeechSynthesizerMock.cpp [plain text]
#include "config.h"
#include "PlatformSpeechSynthesizerMock.h"
#include "PlatformSpeechSynthesisUtterance.h"
#if ENABLE(SPEECH_SYNTHESIS)
namespace WebCore {
PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynthesizerClient* client)
: PlatformSpeechSynthesizer(client)
, m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFinished)
{
}
PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock()
{
}
void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthesizerMock>*)
{
ASSERT(m_utterance.get());
RefPtr<PlatformSpeechSynthesisUtterance> protect(m_utterance);
m_utterance = 0;
client()->didFinishSpeaking(protect);
}
void PlatformSpeechSynthesizerMock::initializeVoiceList()
{
m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.bruce"), String("bruce"), String("en-US"), true, true));
m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.clark"), String("clark"), String("en-US"), true, false));
m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.logan"), String("logan"), String("fr-CA"), true, true));
}
void PlatformSpeechSynthesizerMock::speak(PassRefPtr<PlatformSpeechSynthesisUtterance> utterance)
{
ASSERT(!m_utterance);
m_utterance = utterance;
client()->didStartSpeaking(m_utterance);
client()->boundaryEventOccurred(m_utterance, SpeechWordBoundary, 0);
client()->boundaryEventOccurred(m_utterance, SpeechSentenceBoundary, m_utterance->text().length());
m_speakingFinishedTimer.startOneShot(.1);
}
void PlatformSpeechSynthesizerMock::cancel()
{
if (!m_utterance)
return;
m_speakingFinishedTimer.stop();
client()->speakingErrorOccurred(m_utterance);
m_utterance = 0;
}
void PlatformSpeechSynthesizerMock::pause()
{
client()->didPauseSpeaking(m_utterance);
}
void PlatformSpeechSynthesizerMock::resume()
{
client()->didResumeSpeaking(m_utterance);
}
}
#endif // ENABLE(SPEECH_SYNTHESIS)