1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_nsSpeechTask_h
8 #define mozilla_dom_nsSpeechTask_h
10 #include "SpeechSynthesisUtterance.h"
11 #include "AudioChannelAgent.h"
12 #include "nsISpeechService.h"
13 #include "nsWeakReference.h"
21 class SpeechSynthesisUtterance
;
22 class SpeechSynthesis
;
24 class nsSpeechTask
: public nsISpeechTask
,
25 public nsIAudioChannelAgentCallback
,
26 public nsSupportsWeakReference
{
28 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
29 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsSpeechTask
, nsISpeechTask
)
32 NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
34 explicit nsSpeechTask(SpeechSynthesisUtterance
* aUtterance
,
35 bool aShouldResistFingerprinting
);
36 nsSpeechTask(float aVolume
, const nsAString
& aText
,
37 bool aShouldResistFingerprinting
);
41 virtual void Resume();
43 virtual void Cancel();
45 virtual void ForceEnd();
47 void SetSpeechSynthesis(SpeechSynthesis
* aSpeechSynthesis
);
51 void SetChosenVoiceURI(const nsAString
& aUri
);
53 virtual void SetAudioOutputVolume(float aVolume
);
55 void ForceError(float aElapsedTime
, uint32_t aCharIndex
);
57 bool IsPreCanceled() { return mPreCanceled
; };
59 bool IsPrePaused() { return mPrePaused
; }
61 bool ShouldResistFingerprinting() { return mShouldResistFingerprinting
; }
63 enum { STATE_PENDING
, STATE_SPEAKING
, STATE_ENDED
};
65 uint32_t GetState() const { return mState
; }
67 bool IsSpeaking() const { return mState
== STATE_SPEAKING
; }
69 bool IsPending() const { return mState
== STATE_PENDING
; }
72 virtual ~nsSpeechTask();
74 nsresult
DispatchStartImpl();
76 virtual nsresult
DispatchStartImpl(const nsAString
& aUri
);
78 virtual nsresult
DispatchEndImpl(float aElapsedTime
, uint32_t aCharIndex
);
80 virtual nsresult
DispatchPauseImpl(float aElapsedTime
, uint32_t aCharIndex
);
82 virtual nsresult
DispatchResumeImpl(float aElapsedTime
, uint32_t aCharIndex
);
84 virtual nsresult
DispatchErrorImpl(float aElapsedTime
, uint32_t aCharIndex
);
86 virtual nsresult
DispatchBoundaryImpl(const nsAString
& aName
,
87 float aElapsedTime
, uint32_t aCharIndex
,
88 uint32_t aCharLength
, uint8_t argc
);
90 virtual nsresult
DispatchMarkImpl(const nsAString
& aName
, float aElapsedTime
,
93 RefPtr
<SpeechSynthesisUtterance
> mUtterance
;
108 void CreateAudioChannelAgent();
110 void DestroyAudioChannelAgent();
112 nsCOMPtr
<nsISpeechTaskCallback
> mCallback
;
114 RefPtr
<mozilla::dom::AudioChannelAgent
> mAudioChannelAgent
;
116 RefPtr
<SpeechSynthesis
> mSpeechSynthesis
;
118 nsString mChosenVoiceURI
;
120 bool mShouldResistFingerprinting
;
126 } // namespace mozilla