1926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)/* 2926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * Copyright (C) 2013 Apple Computer, Inc. All rights reserved. 3926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 4926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 5926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * modification, are permitted provided that the following conditions 6926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * are met: 7926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 8926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 9926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 10926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 11926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * documentation and/or other materials provided with the distribution. 12926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 13926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) */ 25926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 26926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#include "config.h" 27a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 2809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "modules/speech/testing/PlatformSpeechSynthesizerMock.h" 29926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 30a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/speech/PlatformSpeechSynthesisUtterance.h" 31a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 32c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 33926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 345d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)PlatformSpeechSynthesizerMock* PlatformSpeechSynthesizerMock::create(PlatformSpeechSynthesizerClient* client) 35926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 365d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) PlatformSpeechSynthesizerMock* synthesizer = new PlatformSpeechSynthesizerMock(client); 37926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) synthesizer->initializeVoiceList(); 38bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) client->voicesDidChange(); 395d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) return synthesizer; 40926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 4102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 42926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)PlatformSpeechSynthesizerMock::PlatformSpeechSynthesizerMock(PlatformSpeechSynthesizerClient* client) 43926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) : PlatformSpeechSynthesizer(client) 44926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) , m_speakingFinishedTimer(this, &PlatformSpeechSynthesizerMock::speakingFinished) 45d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) , m_speakingErrorOccurredTimer(this, &PlatformSpeechSynthesizerMock::speakingErrorOccurred) 46926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 47926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 4802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 49926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)PlatformSpeechSynthesizerMock::~PlatformSpeechSynthesizerMock() 50926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 51926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_speakingFinishedTimer.stop(); 52d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) m_speakingErrorOccurredTimer.stop(); 53926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 54926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 55926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void PlatformSpeechSynthesizerMock::speakingFinished(Timer<PlatformSpeechSynthesizerMock>*) 56926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 57926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) ASSERT(m_utterance.get()); 58926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) client()->didFinishSpeaking(m_utterance); 59d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) m_utterance = nullptr; 60d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)} 61d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 62d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void PlatformSpeechSynthesizerMock::speakingErrorOccurred(Timer<PlatformSpeechSynthesizerMock>*) 63d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles){ 64d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) ASSERT(m_utterance.get()); 65d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) client()->speakingErrorOccurred(m_utterance); 66d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) m_utterance = nullptr; 67926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 6802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 69926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void PlatformSpeechSynthesizerMock::initializeVoiceList() 70926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 71926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_voiceList.clear(); 72926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.bruce"), String("bruce"), String("en-US"), true, true)); 73926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.clark"), String("clark"), String("en-US"), true, false)); 74926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_voiceList.append(PlatformSpeechSynthesisVoice::create(String("mock.voice.logan"), String("logan"), String("fr-CA"), true, true)); 75926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 76926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 775d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)void PlatformSpeechSynthesizerMock::speak(PlatformSpeechSynthesisUtterance* utterance) 78926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 79926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) ASSERT(!m_utterance); 80926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_utterance = utterance; 81926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) client()->didStartSpeaking(m_utterance); 8202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 83926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) // Fire a fake word and then sentence boundary event. 84926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) client()->boundaryEventOccurred(m_utterance, SpeechWordBoundary, 0); 85926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) client()->boundaryEventOccurred(m_utterance, SpeechSentenceBoundary, m_utterance->text().length()); 8602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 87926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) // Give the fake speech job some time so that pause and other functions have time to be called. 88d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) m_speakingFinishedTimer.startOneShot(.1, FROM_HERE); 89926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 9002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 91926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void PlatformSpeechSynthesizerMock::cancel() 92926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 93926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) if (!m_utterance) 94926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return; 9502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 96926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_speakingFinishedTimer.stop(); 97d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) m_speakingErrorOccurredTimer.startOneShot(.1, FROM_HERE); 98926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 99926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 100926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void PlatformSpeechSynthesizerMock::pause() 101926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 102926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) client()->didPauseSpeaking(m_utterance); 103926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 104926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 105926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void PlatformSpeechSynthesizerMock::resume() 106926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 107926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) client()->didResumeSpeaking(m_utterance); 108926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 109926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 1105d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)void PlatformSpeechSynthesizerMock::trace(Visitor* visitor) 1115d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles){ 1125d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) visitor->trace(m_utterance); 1135d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) PlatformSpeechSynthesizer::trace(visitor); 1145d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)} 11502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 116c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 117