#ifndef SpeechSynthesis_h
#define SpeechSynthesis_h
#if ENABLE(SPEECH_SYNTHESIS)
#include "PlatformSpeechSynthesisUtterance.h"
#include "PlatformSpeechSynthesizer.h"
#include "SpeechSynthesisUtterance.h"
#include "SpeechSynthesisVoice.h"
#include <wtf/Deque.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class PlatformSpeechSynthesizerClient;
class SpeechSynthesisVoice;
class SpeechSynthesis : public PlatformSpeechSynthesizerClient, public RefCounted<SpeechSynthesis> {
public:
static PassRefPtr<SpeechSynthesis> create();
bool pending() const;
bool speaking() const;
bool paused() const;
void speak(SpeechSynthesisUtterance*);
void cancel();
void pause();
void resume();
const Vector<RefPtr<SpeechSynthesisVoice>>& getVoices();
void setPlatformSynthesizer(std::unique_ptr<PlatformSpeechSynthesizer>);
private:
SpeechSynthesis();
virtual void voicesDidChange() override;
virtual void didStartSpeaking(PassRefPtr<PlatformSpeechSynthesisUtterance>) override;
virtual void didPauseSpeaking(PassRefPtr<PlatformSpeechSynthesisUtterance>) override;
virtual void didResumeSpeaking(PassRefPtr<PlatformSpeechSynthesisUtterance>) override;
virtual void didFinishSpeaking(PassRefPtr<PlatformSpeechSynthesisUtterance>) override;
virtual void speakingErrorOccurred(PassRefPtr<PlatformSpeechSynthesisUtterance>) override;
virtual void boundaryEventOccurred(PassRefPtr<PlatformSpeechSynthesisUtterance>, SpeechBoundary, unsigned charIndex) override;
void startSpeakingImmediately(SpeechSynthesisUtterance*);
void handleSpeakingCompleted(SpeechSynthesisUtterance*, bool errorOccurred);
void fireEvent(const AtomicString& type, SpeechSynthesisUtterance*, unsigned long charIndex, const String& name);
#if PLATFORM(IOS)
enum BehaviorRestrictionFlags {
NoRestrictions = 0,
RequireUserGestureForSpeechStartRestriction = 1 << 0,
};
typedef unsigned BehaviorRestrictions;
bool userGestureRequiredForSpeechStart() const { return m_restrictions & RequireUserGestureForSpeechStartRestriction; }
void removeBehaviorRestriction(BehaviorRestrictions restriction) { m_restrictions &= ~restriction; }
#endif
std::unique_ptr<PlatformSpeechSynthesizer> m_platformSpeechSynthesizer;
Vector<RefPtr<SpeechSynthesisVoice>> m_voiceList;
SpeechSynthesisUtterance* m_currentSpeechUtterance;
Deque<RefPtr<SpeechSynthesisUtterance>> m_utteranceQueue;
bool m_isPaused;
#if PLATFORM(IOS)
BehaviorRestrictions m_restrictions;
#endif
};
}
#endif // ENABLE(SPEECH_SYNTHESIS)
#endif // SpeechSynthesisEvent_h