1 // Copyright (c) 2018 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_TTS_CHROMEOS_H_
6 #define CHROME_BROWSER_SPEECH_TTS_CHROMEOS_H_
7 
8 #include "base/macros.h"
9 #include "base/no_destructor.h"
10 #include "content/public/browser/tts_platform.h"
11 
12 // This class includes extension-based tts through LoadBuiltInTtsExtension and
13 // native tts through ARC.
14 class TtsPlatformImplChromeOs : public content::TtsPlatform {
15  public:
16   TtsPlatformImplChromeOs(const TtsPlatformImplChromeOs&) = delete;
17   TtsPlatformImplChromeOs& operator=(const TtsPlatformImplChromeOs&) = delete;
18 
19   // TtsPlatform overrides:
20   bool PlatformImplSupported() override;
21   bool PlatformImplInitialized() override;
22   bool LoadBuiltInTtsEngine(content::BrowserContext* browser_context) override;
23   void Speak(int utterance_id,
24              const std::string& utterance,
25              const std::string& lang,
26              const content::VoiceData& voice,
27              const content::UtteranceContinuousParameters& params,
28              base::OnceCallback<void(bool)> on_speak_finished) override;
29   bool StopSpeaking() override;
30   void GetVoices(std::vector<content::VoiceData>* out_voices) override;
31   std::string GetError() override;
32   void ClearError() override;
33   void SetError(const std::string& error) override;
34   bool IsSpeaking() override;
35 
36   // Unimplemented.
Pause()37   void Pause() override {}
Resume()38   void Resume() override {}
WillSpeakUtteranceWithVoice(content::TtsUtterance * utterance,const content::VoiceData & voice_data)39   void WillSpeakUtteranceWithVoice(
40       content::TtsUtterance* utterance,
41       const content::VoiceData& voice_data) override {}
Shutdown()42   void Shutdown() override {}
43 
44   // Get the single instance of this class.
45   static TtsPlatformImplChromeOs* GetInstance();
46 
47  private:
48   friend base::NoDestructor<TtsPlatformImplChromeOs>;
49   TtsPlatformImplChromeOs();
50 
51   void ProcessSpeech(int utterance_id,
52                      const std::string& lang,
53                      const content::VoiceData& voice,
54                      const content::UtteranceContinuousParameters& params,
55                      base::OnceCallback<void(bool)> on_speak_finished,
56                      const std::string& parsed_utterance);
57 
58   std::string error_;
59 };
60 
61 #endif  // CHROME_BROWSER_SPEECH_TTS_CHROMEOS_H_
62