tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsSynthVoiceRegistry.h (2971B)


      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/. */
      6 
      7 #ifndef mozilla_dom_nsSynthVoiceRegistry_h
      8 #define mozilla_dom_nsSynthVoiceRegistry_h
      9 
     10 #include "nsISynthVoiceRegistry.h"
     11 #include "nsRefPtrHashtable.h"
     12 #include "nsTArray.h"
     13 
     14 class nsISpeechService;
     15 
     16 namespace mozilla::dom {
     17 
     18 class RemoteVoice;
     19 class SpeechSynthesisUtterance;
     20 class SpeechSynthesisChild;
     21 class SpeechSynthesisParent;
     22 class nsSpeechTask;
     23 class VoiceData;
     24 class GlobalQueueItem;
     25 
     26 class nsSynthVoiceRegistry final : public nsISynthVoiceRegistry {
     27 public:
     28  NS_DECL_ISUPPORTS
     29  NS_DECL_NSISYNTHVOICEREGISTRY
     30 
     31  nsSynthVoiceRegistry();
     32 
     33  already_AddRefed<nsSpeechTask> SpeakUtterance(
     34      SpeechSynthesisUtterance& aUtterance, const nsAString& aDocLang);
     35 
     36  void Speak(const nsAString& aText, const nsAString& aLang,
     37             const nsAString& aUri, const float& aVolume, const float& aRate,
     38             const float& aPitch, nsSpeechTask* aTask);
     39 
     40  bool SendInitialVoicesAndState(SpeechSynthesisParent* aParent);
     41 
     42  void SpeakNext();
     43 
     44  void ResumeQueue();
     45 
     46  bool IsSpeaking();
     47 
     48  void SetIsSpeaking(bool aIsSpeaking);
     49 
     50  static nsSynthVoiceRegistry* GetInstance();
     51 
     52  static already_AddRefed<nsSynthVoiceRegistry> GetInstanceForService();
     53 
     54  static void RecvInitialVoicesAndState(const nsTArray<RemoteVoice>& aVoices,
     55                                        const nsTArray<nsString>& aDefaults,
     56                                        const bool& aIsSpeaking);
     57 
     58  static void RecvRemoveVoice(const nsAString& aUri);
     59 
     60  static void RecvAddVoice(const RemoteVoice& aVoice);
     61 
     62  static void RecvSetDefaultVoice(const nsAString& aUri, bool aIsDefault);
     63 
     64  static void RecvIsSpeakingChanged(bool aIsSpeaking);
     65 
     66  static void RecvNotifyVoicesChanged();
     67 
     68  static void RecvNotifyVoicesError(const nsAString& aError);
     69 
     70 private:
     71  virtual ~nsSynthVoiceRegistry();
     72 
     73  VoiceData* FindBestMatch(const nsAString& aUri, const nsAString& lang);
     74 
     75  bool FindVoiceByLang(const nsAString& aLang, VoiceData** aRetval);
     76 
     77  nsresult AddVoiceImpl(nsISpeechService* aService, const nsAString& aUri,
     78                        const nsAString& aName, const nsAString& aLang,
     79                        bool aLocalService, bool aQueuesUtterances);
     80 
     81  void SpeakImpl(VoiceData* aVoice, nsSpeechTask* aTask, const nsAString& aText,
     82                 const float& aVolume, const float& aRate, const float& aPitch);
     83 
     84  nsTArray<RefPtr<VoiceData>> mVoices;
     85 
     86  nsTArray<RefPtr<VoiceData>> mDefaultVoices;
     87 
     88  nsRefPtrHashtable<nsStringHashKey, VoiceData> mUriVoiceMap;
     89 
     90  RefPtr<SpeechSynthesisChild> mSpeechSynthChild;
     91 
     92  bool mUseGlobalQueue;
     93 
     94  nsTArray<RefPtr<GlobalQueueItem>> mGlobalQueue;
     95 
     96  bool mIsSpeaking;
     97 };
     98 
     99 }  // namespace mozilla::dom
    100 
    101 #endif