00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #ifndef _AX_SPEECH_H_
00013 #define _AX_SPEECH_H_
00014
00021
00022
00023
00024
00025 #include "wx/event.h"
00026 #include "wx/dynarray.h"
00027
00028 #include "tts/tts.h"
00029 #include "ax/ax_menu.h"
00030
00031 class AxSpeechEvent;
00032 class AxSpeechEventHandler;
00033 class AxMenu;
00034 class AxMenuItem;
00035 class wxConfigBase;
00036 class AxSpeechEventArray;
00037
00038 enum {
00039 AxSpeechVerbosityLowest=1,
00040 AxSpeechVerbosityLow=2,
00041 AxSpeechVerbosityMedium=3,
00042 AxSpeechVerbosityHigh=4,
00043 AxSpeechVerbosityHighest=5
00044 };
00045
00046 typedef enum {
00047 AxSpeechMainChannel= 0,
00048 AxSpeechContentChannel= 1,
00049
00050 AxSpeechDefaultChannel= -1,
00051 AxSpeechAllChannels= -2
00052 };
00053
00054 typedef int AxSpeechChannel;
00055
00065 class AxSpeechPolicy: public wxObject
00066 {
00067 public:
00068 DECLARE_DYNAMIC_CLASS( AxSpeechPolicy )
00069
00070 AxSpeechPolicy() { Init(); }
00071 AxSpeechPolicy(const AxSpeechPolicy& policy) { Copy(policy); }
00072
00073 void Init();
00074
00075 void Copy(const AxSpeechPolicy& policy);
00076 void operator=(const AxSpeechPolicy& policy) { Copy(policy); }
00077
00079 void SetVerbosityLevel(int level) { m_verbosityLevel = level; }
00080
00082 int GetVerbosityLevel() const { return m_verbosityLevel; }
00083
00085 bool VerbosityAtLeast(int level) const { return m_verbosityLevel >= level; }
00086
00088 void EnableSpeech(bool enabled = true) { m_enableSpeech = enabled; }
00089
00091 bool IsSpeechEnabled() const { return m_enableSpeech; }
00092
00094 void EnableMultipleVoiceMode(bool enabled = true) { m_enableMultipleVoiceMode = enabled; }
00095
00097 bool IsMultipleVoiceModeEnabled() const { return m_enableMultipleVoiceMode; }
00098
00099 public:
00100
00101 bool m_enableSpeech;
00102 bool m_enableMultipleVoiceMode;
00103 int m_verbosityLevel;
00104 };
00105
00106 enum {
00107
00108 AxSpeechFlagsPurge=0x0001,
00109
00110
00111 AxSpeechFlagsPurgeAll=0x0002,
00112
00113
00114 AxSpeechFlagsInviolate=0x0004,
00115
00116
00117 AxSpeechFlagsImmediate=0x0008,
00118
00119
00120 AxSpeechFlagsContentChannel=0x0010
00121 };
00122
00134 class AxSpeechEvent: public wxNotifyEvent
00135 {
00136 public:
00137 DECLARE_DYNAMIC_CLASS( AxSpeechEvent )
00138
00139 AxSpeechEvent() { Init(); }
00140
00141 AxSpeechEvent(const wxString& eventType, const wxString& text = wxEmptyString,
00142 int verbosityLevel = 0)
00143 { Init(); m_speechEventType = eventType; m_text = text; m_verbosityLevel = verbosityLevel; }
00144 AxSpeechEvent(const AxSpeechEvent& event) { Init(); Copy(event); }
00145
00146 void Init();
00147
00148 void Copy(const AxSpeechEvent& event);
00149
00150 virtual wxEvent* Clone() const { return new AxSpeechEvent(*this); }
00151
00152 void SetSpeechEventType(const wxString& eventType) { m_speechEventType = eventType; }
00153 const wxString& GetSpeechEventType() const { return m_speechEventType; }
00154
00155 void SetText(const wxString& text) { m_text = text; }
00156 const wxString& GetText() const { return m_text; }
00157
00164 void SetVerbosityLevel(int level) { m_verbosityLevel = level; }
00165 int GetVerbosityLevel() const { return m_verbosityLevel; }
00166
00172 void SetVerbosityPolicy(int level) { m_verbosityPolicy = level; }
00173 int GetVerbosityPolicy() const { return m_verbosityPolicy; }
00174
00175 void SetNavigationHint(AxNavigationHint hint) { m_navigationHint = hint; }
00176 int GetNavigationHint() const { return m_navigationHint; }
00177
00178 void PurgeSpeech() { m_flags |= AxSpeechFlagsPurge; }
00179 void PurgeAllSpeech() { m_flags |= AxSpeechFlagsPurgeAll; }
00180 bool GetPurgeSpeech() const { return (m_flags & AxSpeechFlagsPurge) == AxSpeechFlagsPurge; }
00181 bool GetPurgeAllSpeech() const { return (m_flags & AxSpeechFlagsPurgeAll) == AxSpeechFlagsPurgeAll; }
00182
00183 void SetFlags(int flags) { m_flags = flags; }
00184 int GetFlags() const { return m_flags; }
00185
00186 void SetMenu(AxMenu* menu) { m_menu = menu; }
00187 AxMenu* GetMenu() const { return m_menu; }
00188
00189 void SetMenuItem(AxMenuItem* item) { m_menuItem = item; }
00190 AxMenuItem* GetMenuItem() const { return m_menuItem; }
00191
00192 AxSpeechChannel GetChannel() const { return m_flags & AxSpeechFlagsContentChannel ? AxSpeechContentChannel : AxSpeechMainChannel; }
00193
00194 protected:
00195 wxString m_speechEventType;
00196 wxString m_text;
00197 int m_verbosityLevel;
00198 int m_verbosityPolicy;
00199 int m_flags;
00200 AxMenu* m_menu;
00201 AxMenuItem* m_menuItem;
00202 AxNavigationHint m_navigationHint;
00203 };
00204
00205 WX_DEFINE_ARRAY_PTR(AxSpeechEvent*, AxSpeechEventArray);
00206
00207 class AxSpeechInfo
00208 {
00209 public:
00210 AxSpeechInfo();
00211
00212 wxTextToSpeech m_textToSpeech;
00213 wxTTSSpeechSettingsInfo m_speechSettingsInfo;
00214 wxString m_currentText;
00215 int m_freezeCount;
00216 int m_speechCounter;
00217 AxSpeechEventArray m_speechEvents;
00218 };
00219
00228 #define AxSpeechEventActivateItem wxT("ACTIVATEITEM")
00229 #define AxSpeechEventRefreshMenu wxT("REFRESHMENU")
00230 #define AxSpeechEventChangeSelection wxT("SELECTIONCHANGED")
00231 #define AxSpeechEventToggleSelection wxT("TOGGLESELECTION")
00232 #define AxSpeechEventChangeValue wxT("CHANGEVALUE")
00233 #define AxSpeechEventItemLabelChanged wxT("ITEMLABELCHANGED")
00234 #define AxSpeechEventTaskAdded wxT("TASKADDED")
00235 #define AxSpeechEventTaskDeleted wxT("TASKDELETED")
00236 #define AxSpeechEventTaskChanged wxT("TASKCHANGED")
00237 #define AxSpeechEventText wxT("TEXT")
00238 #define AxSpeechEventInitialView wxT("INITIALVIEW")
00239 #define AxSpeechEventDescribeContext wxT("DESCRIBECONTEXT")
00240 #define AxSpeechEventDescribeItem wxT("DESCRIBEITEM")
00241
00242 class AxSpeech: public wxEvtHandler
00243 {
00244 public:
00245 DECLARE_CLASS( AxSpeech )
00246
00247 public:
00248
00249
00250 AxSpeech();
00251 ~AxSpeech();
00252
00253
00254
00255 void Init();
00256
00258 bool Say(const wxString& text, int flags = AxSpeechFlagsPurge, int verbosity = 2);
00259
00261 bool EmitSpeech(AxSpeechEvent& event);
00262
00265 virtual bool ProcessSpeechEvent(AxSpeechEvent& event);
00266
00269 virtual bool Stop();
00270
00272 virtual bool Stop(AxSpeechChannel channel);
00273
00275 virtual bool PauseOrResume();
00276
00278 virtual bool PauseOrResume(AxSpeechChannel channel);
00279
00281 wxTextToSpeech& GetTextToSpeech(AxSpeechChannel channel = AxSpeechMainChannel, bool normalize = true) { return GetChannelInfo(channel, normalize).m_textToSpeech; }
00282 const wxTextToSpeech& GetTextToSpeech(AxSpeechChannel channel = AxSpeechMainChannel, bool normalize = true) const { return GetChannelInfo(channel, normalize).m_textToSpeech; }
00283
00285 void SetSpeechSettingsInfo(const wxTTSSpeechSettingsInfo& info, AxSpeechChannel channel = AxSpeechMainChannel, bool normalize = true) { GetChannelInfo(channel, normalize).m_speechSettingsInfo = info; }
00286
00288 const wxTTSSpeechSettingsInfo& GetSpeechSettingsInfo(AxSpeechChannel channel = AxSpeechMainChannel, bool normalize = true) const { return GetChannelInfo(channel, normalize).m_speechSettingsInfo; }
00289
00291 wxTTSSpeechSettingsInfo& GetSpeechSettingsInfo(AxSpeechChannel channel = AxSpeechMainChannel, bool normalize = true) { return GetChannelInfo(channel, normalize).m_speechSettingsInfo; }
00292
00295 const AxSpeechInfo& GetChannelInfo(AxSpeechChannel channel, bool normalize = true) const;
00296
00298 AxSpeechInfo& GetChannelInfo(AxSpeechChannel channel, bool normalize = true);
00299
00301 AxSpeechChannel NormalizeChannel(AxSpeechChannel channel) const;
00302
00304 void SetTransformer(wxTTSTransformer* transformer);
00305
00307 wxTTSTransformer* GetTransformer() const { return m_transformer; }
00308
00310 void SetPolicy(const AxSpeechPolicy& policy) { m_policy = policy; }
00311
00313 AxSpeechPolicy& GetPolicy() { return m_policy; }
00314
00316 const AxSpeechPolicy& GetPolicy() const { return m_policy; }
00317
00319 const wxString& GetCurrentText() const { return m_mainSpeechChannel.m_currentText; }
00320
00322 const wxString& GetCurrentContentText() const { return m_contentSpeechChannel.m_currentText; }
00323
00326 void SetCurrentText(const wxString& text, AxSpeechChannel channel = AxSpeechMainChannel) { GetChannelInfo(channel).m_currentText = text; }
00327
00329 bool IsFrozen(AxSpeechChannel channel = AxSpeechMainChannel) const;
00330
00332 bool Freeze(AxSpeechChannel channel = AxSpeechMainChannel);
00333
00335 bool Thaw(AxSpeechChannel channel = AxSpeechMainChannel);
00336
00339 int GetSpeechCounter(AxSpeechChannel channel = AxSpeechMainChannel) const { return GetChannelInfo(channel).m_speechCounter; }
00340
00343 bool Speak(const wxString& text, int speechChannel = AxSpeechMainChannel);
00344
00346 bool Push(AxSpeechEventHandler* handler);
00347
00349 bool PushEnd(AxSpeechEventHandler* handler);
00350
00352 bool Pop();
00353
00355 virtual bool InitialiseStandardSpeechHandlers();
00356
00358 virtual bool LoadSpeechSettings(wxConfigBase& config);
00359
00361 virtual bool SaveSpeechSettings(wxConfigBase& config);
00362
00364 virtual bool AreVoicesCompatible() const;
00365
00367 void SetupMultipleVoices();
00368
00370 AxSpeechEventArray& GetPendingSpeechEvents(AxSpeechChannel channel = AxSpeechMainChannel) { return GetChannelInfo(channel).m_speechEvents; }
00371
00373 void ScheduleSpeechEvent(AxSpeechEvent& event);
00374
00376 void ClearSpeechEvents(AxSpeechChannel channel = AxSpeechMainChannel);
00377
00379 void PurgeSpeechEvents(AxSpeechChannel channel = AxSpeechMainChannel);
00380
00382 void ProcessPendingSpeechEvents();
00383
00384 protected:
00385 AxSpeechInfo m_mainSpeechChannel;
00386 AxSpeechInfo m_contentSpeechChannel;
00387
00388 wxTTSTransformer* m_transformer;
00389 AxSpeechPolicy m_policy;
00390 AxSpeechEventHandler* m_handler;
00391 };
00392
00401 class AxSpeechEventHandler: public wxEvtHandler
00402 {
00403 public:
00404 DECLARE_CLASS( AxSpeechEventHandler )
00405
00406 AxSpeechEventHandler() { m_nextHandler = NULL; }
00407
00408 virtual bool ProcessSpeechEvent(AxSpeech* speech, AxSpeechEvent& event) = 0;
00409
00410 AxSpeechEventHandler* GetNextHandler() const { return m_nextHandler; }
00411 void SetNextHandler(AxSpeechEventHandler* handler) { m_nextHandler = handler; }
00412
00414 static bool IsPunctuation(const wxChar& ch);
00415
00417 static bool RemoveTrailingPunctuation(wxString& str);
00418
00421 static bool AddStop(wxString& str, const wxString& punct = wxT("."));
00422
00425 static bool AddPause(wxString& str, const wxString& punct = wxT(";"));
00426
00427 protected:
00428
00429 AxSpeechEventHandler* m_nextHandler;
00430 };
00431
00440 class AxStandardSpeechEventHandler: public AxSpeechEventHandler
00441 {
00442 public:
00443 DECLARE_DYNAMIC_CLASS( AxStandardSpeechEventHandler )
00444
00445 AxStandardSpeechEventHandler() {}
00446
00447 virtual bool ProcessSpeechEvent(AxSpeech* speech, AxSpeechEvent& event);
00448
00449 protected:
00450
00451 };
00452
00453
00454 #endif
00455