1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_SPEECH_EXTENSION_API_TTS_ENGINE_EXTENSION_API_H_
6 #define CHROME_BROWSER_SPEECH_EXTENSION_API_TTS_ENGINE_EXTENSION_API_H_
7 
8 #include <vector>
9 
10 #include "base/memory/singleton.h"
11 #include "content/public/browser/tts_controller.h"
12 #include "extensions/browser/extension_function.h"
13 
14 namespace content {
15 class BrowserContext;
16 }
17 
18 namespace tts_engine_events {
19 extern const char kOnSpeak[];
20 extern const char kOnStop[];
21 extern const char kOnPause[];
22 extern const char kOnResume[];
23 }
24 
25 // TtsEngineDelegate implementation used by TtsController.
26 class TtsExtensionEngine : public content::TtsEngineDelegate {
27  public:
28   static TtsExtensionEngine* GetInstance();
29 
30   // Overridden from TtsEngineDelegate:
31   void GetVoices(content::BrowserContext* browser_context,
32                  std::vector<content::VoiceData>* out_voices) override;
33   void Speak(content::TtsUtterance* utterance,
34              const content::VoiceData& voice) override;
35   void Stop(content::TtsUtterance* utterance) override;
36   void Pause(content::TtsUtterance* utterance) override;
37   void Resume(content::TtsUtterance* utterance) override;
38   bool LoadBuiltInTtsEngine(content::BrowserContext* browser_context) override;
39 
DisableBuiltInTTSEngineForTesting()40   void DisableBuiltInTTSEngineForTesting() {
41     disable_built_in_tts_engine_for_testing_ = true;
42   }
43 
44  private:
45   bool disable_built_in_tts_engine_for_testing_ = false;
46 };
47 
48 // Function that allows tts engines to update its list of supported voices at
49 // runtime.
50 class ExtensionTtsEngineUpdateVoicesFunction : public ExtensionFunction {
51  private:
~ExtensionTtsEngineUpdateVoicesFunction()52   ~ExtensionTtsEngineUpdateVoicesFunction() override {}
53   ResponseAction Run() override;
54   DECLARE_EXTENSION_FUNCTION("ttsEngine.updateVoices", TTSENGINE_UPDATEVOICES)
55 };
56 
57 // Hidden/internal extension function used to allow TTS engine extensions
58 // to send events back to the client that's calling tts.speak().
59 class ExtensionTtsEngineSendTtsEventFunction : public ExtensionFunction {
60  private:
~ExtensionTtsEngineSendTtsEventFunction()61   ~ExtensionTtsEngineSendTtsEventFunction() override {}
62   ResponseAction Run() override;
63   DECLARE_EXTENSION_FUNCTION("ttsEngine.sendTtsEvent", TTSENGINE_SENDTTSEVENT)
64 };
65 
66 #endif  // CHROME_BROWSER_SPEECH_EXTENSION_API_TTS_ENGINE_EXTENSION_API_H_
67