| // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef SPEECH_SYNTHESIS_SPEECH_SYNTHESIZER_SERVICE_H_ |
| #define SPEECH_SYNTHESIS_SPEECH_SYNTHESIZER_SERVICE_H_ |
| |
| #include "base/memory/scoped_ptr.h" |
| #include "base/time.h" |
| |
| #include <chromeos/dbus/abstract_dbus_service.h> |
| #include <chromeos/dbus/dbus.h> |
| #include <chromeos/dbus/service_constants.h> |
| |
| #include "pico/pico_tts_engine.h" |
| #include "threading.h" |
| #include "tts_engine.h" |
| #include "tts_service.h" |
| |
| namespace speech_synthesis { |
| namespace gobject { |
| struct SpeechSynthesizer; |
| } // namespace gobject |
| |
| // Provides a wrapper for exporting SpeechSynthesizerInterface to |
| // D-Bus and entering the glib run loop. |
| // |
| // ::g_type_init() must be called before this class is used. |
| class SpeechSynthesizerService : public chromeos::dbus::AbstractDbusService { |
| public: |
| SpeechSynthesizerService(); |
| virtual ~SpeechSynthesizerService(); |
| |
| //////////////////////////////////////////////////////////////////////////// |
| // Implementing chromeos::dbus::AbstractDbusService |
| virtual bool Initialize() OVERRIDE; |
| virtual bool Reset() OVERRIDE; |
| |
| virtual bool Run()OVERRIDE; |
| |
| virtual const char* service_name() const OVERRIDE { |
| return kSpeechSynthesizerServiceName; |
| } |
| virtual const char* service_path() const OVERRIDE { |
| return kSpeechSynthesizerServicePath; |
| } |
| virtual const char* service_interface() const OVERRIDE { |
| return kSpeechSynthesizerInterface; |
| } |
| virtual GObject* service_object() const OVERRIDE{ |
| return G_OBJECT(speech_synthesizer_); |
| } |
| |
| // Interface function prototypes which wrap service. |
| gboolean Speak(gchar *text, |
| gchar *properties, |
| GError **error); |
| gboolean Stop(GError **error); |
| gboolean IsSpeaking(gboolean *OUT_isSpeaking_requested, |
| GError **error); |
| gboolean Shutdown(GError **error); |
| |
| protected: |
| // AbstractDbusService override. |
| virtual GMainLoop* main_loop() OVERRIDE { return main_loop_; } |
| |
| private: |
| scoped_ptr<TtsService> ttsService_; |
| scoped_ptr<AudioOutput> audio_output_; |
| scoped_ptr<UtteranceOptions> utterance_options_; |
| |
| gobject::SpeechSynthesizer* speech_synthesizer_; |
| GMainLoop* main_loop_; |
| |
| // The time when the last dbus method call was made. |
| base::Time time_last_call_; |
| |
| gboolean AddProperties(gchar *properties); |
| |
| // Update |time_last_call_| to delay idle shutdown. |
| void UpdateLastCallTime(); |
| // Shutdown the service if dbus method call has not been made for long time. |
| void ShutdownIfIdle(); |
| // Handler method to be used by g_timeout_add. |
| static gboolean OnTimeout(gpointer user_data); |
| |
| DISALLOW_COPY_AND_ASSIGN(SpeechSynthesizerService); |
| }; |
| |
| } // namespace speech_synthesis |
| #endif // SPEECH_SYNTHESIS_SPEECH_SYNTHESIZER_SERVICE_H_ |