2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * 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.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 THE COPYRIGHT OWNER 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.
26 #ifndef SpeechRecognition_h
27 #define SpeechRecognition_h
29 #include "core/dom/ActiveDOMObject.h"
30 #include "core/page/PageLifecycleObserver.h"
31 #include "modules/EventTargetModules.h"
32 #include "modules/ModulesExport.h"
33 #include "modules/speech/SpeechGrammarList.h"
34 #include "modules/speech/SpeechRecognitionResult.h"
35 #include "platform/heap/Handle.h"
36 #include "public/platform/WebPrivatePtr.h"
37 #include "wtf/Compiler.h"
38 #include "wtf/text/WTFString.h"
43 class ExecutionContext
;
44 class MediaStreamTrack
;
45 class SpeechRecognitionController
;
46 class SpeechRecognitionError
;
48 class MODULES_EXPORT SpeechRecognition final
: public RefCountedGarbageCollectedEventTargetWithInlineData
<SpeechRecognition
>, public PageLifecycleObserver
, public ActiveDOMObject
{
49 REFCOUNTED_GARBAGE_COLLECTED_EVENT_TARGET(SpeechRecognition
);
50 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(SpeechRecognition
);
51 DEFINE_WRAPPERTYPEINFO();
53 static SpeechRecognition
* create(ExecutionContext
*);
54 ~SpeechRecognition() override
;
56 // SpeechRecognition.idl implemementation.
58 SpeechGrammarList
* grammars() { return m_grammars
; }
59 void setGrammars(SpeechGrammarList
* grammars
) { m_grammars
= grammars
; }
60 String
lang() { return m_lang
; }
61 void setLang(const String
& lang
) { m_lang
= lang
; }
62 String
serviceURI() { return m_serviceURI
; }
63 void setServiceURI(const String
& serviceURI
) { m_serviceURI
= serviceURI
; }
64 bool continuous() { return m_continuous
; }
65 void setContinuous(bool continuous
) { m_continuous
= continuous
; }
66 bool interimResults() { return m_interimResults
; }
67 void setInterimResults(bool interimResults
) { m_interimResults
= interimResults
; }
68 unsigned maxAlternatives() { return m_maxAlternatives
; }
69 void setMaxAlternatives(unsigned maxAlternatives
) { m_maxAlternatives
= maxAlternatives
; }
70 MediaStreamTrack
* audioTrack() { return m_audioTrack
; }
71 void setAudioTrack(MediaStreamTrack
* audioTrack
) { m_audioTrack
= audioTrack
; }
73 // Callable by the user.
74 void start(ExceptionState
&);
78 // Called by the SpeechRecognitionClient.
81 void didStartSpeech();
85 void didReceiveResults(const HeapVector
<Member
<SpeechRecognitionResult
>>& newFinalResults
, const HeapVector
<Member
<SpeechRecognitionResult
>>& currentInterimResults
);
86 void didReceiveNoMatch(SpeechRecognitionResult
*);
87 void didReceiveError(PassRefPtrWillBeRawPtr
<SpeechRecognitionError
>);
92 const AtomicString
& interfaceName() const override
;
93 ExecutionContext
* executionContext() const override
;
96 bool hasPendingActivity() const override
;
99 DEFINE_ATTRIBUTE_EVENT_LISTENER(audiostart
);
100 DEFINE_ATTRIBUTE_EVENT_LISTENER(soundstart
);
101 DEFINE_ATTRIBUTE_EVENT_LISTENER(speechstart
);
102 DEFINE_ATTRIBUTE_EVENT_LISTENER(speechend
);
103 DEFINE_ATTRIBUTE_EVENT_LISTENER(soundend
);
104 DEFINE_ATTRIBUTE_EVENT_LISTENER(audioend
);
105 DEFINE_ATTRIBUTE_EVENT_LISTENER(result
);
106 DEFINE_ATTRIBUTE_EVENT_LISTENER(nomatch
);
107 DEFINE_ATTRIBUTE_EVENT_LISTENER(error
);
108 DEFINE_ATTRIBUTE_EVENT_LISTENER(start
);
109 DEFINE_ATTRIBUTE_EVENT_LISTENER(end
);
111 DECLARE_VIRTUAL_TRACE();
113 // PageLifecycleObserver
114 void contextDestroyed() override
;
117 SpeechRecognition(Page
*, ExecutionContext
*);
119 Member
<SpeechGrammarList
> m_grammars
;
120 Member
<MediaStreamTrack
> m_audioTrack
;
124 bool m_interimResults
;
125 unsigned long m_maxAlternatives
;
127 RawPtrWillBeMember
<SpeechRecognitionController
> m_controller
;
128 bool m_stoppedByActiveDOMObject
;
131 HeapVector
<Member
<SpeechRecognitionResult
>> m_finalResults
;
136 #endif // SpeechRecognition_h