tts_service.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2020 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. #ifndef CHROMEOS_SERVICES_TTS_TTS_SERVICE_H_
  5. #define CHROMEOS_SERVICES_TTS_TTS_SERVICE_H_
  6. #include "chromeos/services/tts/google_tts_stream.h"
  7. #include "chromeos/services/tts/playback_tts_stream.h"
  8. #include "chromeos/services/tts/public/mojom/tts_service.mojom.h"
  9. #include "mojo/public/cpp/bindings/receiver.h"
  10. #include "mojo/public/cpp/bindings/receiver_set.h"
  11. #include "mojo/public/cpp/bindings/remote.h"
  12. namespace chromeos {
  13. namespace tts {
  14. class TtsService : public mojom::TtsService {
  15. public:
  16. explicit TtsService(mojo::PendingReceiver<mojom::TtsService> receiver);
  17. ~TtsService() override;
  18. // Maybe exit this process.
  19. void MaybeExit();
  20. void set_keep_process_alive_for_testing(bool value) {
  21. keep_process_alive_for_testing_ = value;
  22. }
  23. mojo::Receiver<mojom::TtsService>* receiver_for_testing() {
  24. return &service_receiver_;
  25. }
  26. PlaybackTtsStream* playback_tts_stream_for_testing() {
  27. return playback_tts_stream_.get();
  28. }
  29. // mojom::TtsService:
  30. void BindGoogleTtsStream(
  31. mojo::PendingReceiver<mojom::GoogleTtsStream> receiver,
  32. mojo::PendingRemote<media::mojom::AudioStreamFactory> factory) override;
  33. void BindPlaybackTtsStream(
  34. mojo::PendingReceiver<mojom::PlaybackTtsStream> receiver,
  35. mojo::PendingRemote<media::mojom::AudioStreamFactory> factory,
  36. mojom::AudioParametersPtr desired_audio_parameters,
  37. BindPlaybackTtsStreamCallback callback) override;
  38. private:
  39. // Connection to tts in the browser.
  40. mojo::Receiver<mojom::TtsService> service_receiver_;
  41. // The Google text-to-speech engine.
  42. std::unique_ptr<GoogleTtsStream> google_tts_stream_;
  43. // The active playback-based text-to-speech engine.
  44. std::unique_ptr<PlaybackTtsStream> playback_tts_stream_;
  45. // Keeps this process alive for testing.
  46. bool keep_process_alive_for_testing_ = false;
  47. base::WeakPtrFactory<TtsService> weak_factory_{this};
  48. };
  49. } // namespace tts
  50. } // namespace chromeos
  51. #endif // CHROMEOS_SERVICES_TTS_TTS_SERVICE_H_