f0d6893a21c5683f81e5a82da5ab68f5213d1c9a
[WebKit-https.git] / Source / WebCore / platform / PlatformSpeechSynthesizer.h
1 /*
2  * Copyright (C) 2013 Apple Computer, Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef PlatformSpeechSynthesizer_h
27 #define PlatformSpeechSynthesizer_h
28
29 #if ENABLE(SPEECH_SYNTHESIS)
30
31 #include "PlatformSpeechSynthesisVoice.h"
32 #include <wtf/PassOwnPtr.h>
33 #include <wtf/Vector.h>
34
35 #if PLATFORM(MAC)
36 #include <wtf/RetainPtr.h>
37 OBJC_CLASS WebSpeechSynthesisWrapper;
38 #endif
39
40 #if PLATFORM(CHROMIUM)
41 namespace WebKit {
42 class WebSpeechSynthesizer;
43 class WebSpeechSynthesizerClient;
44 }
45 #endif
46
47 namespace WebCore {
48
49 enum SpeechBoundary {
50     SpeechWordBoundary,
51     SpeechSentenceBoundary
52 };
53
54 class PlatformSpeechSynthesisUtterance;
55
56 class PlatformSpeechSynthesizerClient {
57 public:
58     virtual void didStartSpeaking(PassRefPtr<PlatformSpeechSynthesisUtterance>) = 0;
59     virtual void didFinishSpeaking(PassRefPtr<PlatformSpeechSynthesisUtterance>) = 0;
60     virtual void didPauseSpeaking(PassRefPtr<PlatformSpeechSynthesisUtterance>) = 0;
61     virtual void didResumeSpeaking(PassRefPtr<PlatformSpeechSynthesisUtterance>) = 0;
62     virtual void speakingErrorOccurred(PassRefPtr<PlatformSpeechSynthesisUtterance>) = 0;
63     virtual void boundaryEventOccurred(PassRefPtr<PlatformSpeechSynthesisUtterance>, SpeechBoundary, unsigned charIndex) = 0;
64     virtual void voicesDidChange() = 0;
65 protected:
66     virtual ~PlatformSpeechSynthesizerClient() { }
67 };
68     
69 class PlatformSpeechSynthesizer {
70 public:
71     static PassOwnPtr<PlatformSpeechSynthesizer> create(PlatformSpeechSynthesizerClient*);
72
73     virtual ~PlatformSpeechSynthesizer();
74     
75     const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& voiceList() const { return m_voiceList; }
76     virtual void speak(PassRefPtr<PlatformSpeechSynthesisUtterance>);
77     virtual void pause();
78     virtual void resume();
79     virtual void cancel();
80     
81     PlatformSpeechSynthesizerClient* client() const { return m_speechSynthesizerClient; }
82
83     void setVoiceList(Vector<RefPtr<PlatformSpeechSynthesisVoice> >&);
84
85 protected:
86     virtual void initializeVoiceList();
87     explicit PlatformSpeechSynthesizer(PlatformSpeechSynthesizerClient*);
88     Vector<RefPtr<PlatformSpeechSynthesisVoice> > m_voiceList;
89     
90 private:
91     PlatformSpeechSynthesizerClient* m_speechSynthesizerClient;
92     
93 #if PLATFORM(MAC)
94     RetainPtr<WebSpeechSynthesisWrapper> m_platformSpeechWrapper;
95 #endif
96 #if PLATFORM(CHROMIUM)
97     OwnPtr<WebKit::WebSpeechSynthesizer> m_webSpeechSynthesizer;
98     OwnPtr<WebKit::WebSpeechSynthesizerClient> m_webSpeechSynthesizerClient;
99 #endif
100 };
101     
102 } // namespace WebCore
103
104 #endif // ENABLE(SPEECH_SYNTHESIS)
105
106 #endif // PlatformSpeechSynthesizer_h