1926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)/* 2926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * Copyright (c) 2013 Google 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 are 6926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * met: 7926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 8926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * * Redistributions of source code must retain the above copyright 9926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 10926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * * Redistributions in binary form must reproduce the above 11926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 12926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * in the documentation and/or other materials provided with the 13926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * distribution. 14926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 15926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * contributors may be used to endorse or promote products derived from 16926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * this software without specific prior written permission. 17926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 18926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) */ 30926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 31926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#include "config.h" 3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/platform/PlatformSpeechSynthesizer.h" 33926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 3453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/platform/PlatformSpeechSynthesisUtterance.h" 3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/platform/PlatformSpeechSynthesisVoice.h" 3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/platform/chromium/support/WebSpeechSynthesizerClientImpl.h" 375267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "public/platform/Platform.h" 385267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "public/platform/WebSpeechSynthesisUtterance.h" 395267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "public/platform/WebSpeechSynthesizer.h" 405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "public/platform/WebSpeechSynthesizerClient.h" 417757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch#include "wtf/RetainPtr.h" 42926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 43926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)namespace WebCore { 44926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 45926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)PlatformSpeechSynthesizer::PlatformSpeechSynthesizer(PlatformSpeechSynthesizerClient* client) 46926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) : m_speechSynthesizerClient(client) 47926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 48926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_webSpeechSynthesizerClient = adoptPtr(new WebSpeechSynthesizerClientImpl(this, client)); 49926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_webSpeechSynthesizer = adoptPtr(WebKit::Platform::current()->createSpeechSynthesizer(m_webSpeechSynthesizerClient.get())); 50926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 51926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 52926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)PlatformSpeechSynthesizer::~PlatformSpeechSynthesizer() 53926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 54926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 55926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 56926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void PlatformSpeechSynthesizer::initializeVoiceList() 57926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 58926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) if (m_webSpeechSynthesizer.get()) 59926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_webSpeechSynthesizer->updateVoiceList(); 60926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 61926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 62926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void PlatformSpeechSynthesizer::speak(PassRefPtr<PlatformSpeechSynthesisUtterance> utterance) 63926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 64926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) if (!m_webSpeechSynthesizer || !m_webSpeechSynthesizerClient) 65926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return; 66926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 67926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_webSpeechSynthesizer->speak(WebKit::WebSpeechSynthesisUtterance(utterance)); 68926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 69926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 70926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void PlatformSpeechSynthesizer::pause() 71926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 72926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) if (m_webSpeechSynthesizer.get()) 73926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_webSpeechSynthesizer->pause(); 74926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 75926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 76926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void PlatformSpeechSynthesizer::resume() 77926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 78926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) if (m_webSpeechSynthesizer.get()) 79926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_webSpeechSynthesizer->resume(); 80926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 81926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 82926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)void PlatformSpeechSynthesizer::cancel() 83926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 84926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) if (m_webSpeechSynthesizer.get()) 85926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) m_webSpeechSynthesizer->cancel(); 86926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} 87926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 88926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)} // namespace WebCore 89