Home | History | Annotate | Download | only in cros
      1 // Copyright (c) 2010 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 #include "chrome/browser/chromeos/cros/speech_synthesis_library.h"
      6 
      7 #include "base/message_loop.h"
      8 #include "chrome/browser/chromeos/cros/cros_library.h"
      9 #include "third_party/cros/chromeos_speech_synthesis.h"
     10 
     11 namespace chromeos {
     12 
     13 // TODO(chaitanyag): rename to "locale" after making equivalent change in
     14 // Chrome OS code.
     15 const char SpeechSynthesisLibrary::kSpeechPropertyLocale[] = "name";
     16 
     17 const char SpeechSynthesisLibrary::kSpeechPropertyGender[] = "gender";
     18 const char SpeechSynthesisLibrary::kSpeechPropertyRate[] = "rate";
     19 const char SpeechSynthesisLibrary::kSpeechPropertyPitch[] = "pitch";
     20 const char SpeechSynthesisLibrary::kSpeechPropertyVolume[] = "volume";
     21 const char SpeechSynthesisLibrary::kSpeechPropertyEquals[] = "=";
     22 const char SpeechSynthesisLibrary::kSpeechPropertyDelimiter[] = ";";
     23 
     24 class SpeechSynthesisLibraryImpl : public SpeechSynthesisLibrary {
     25  public:
     26   SpeechSynthesisLibraryImpl() {}
     27   virtual ~SpeechSynthesisLibraryImpl() {}
     28 
     29   bool Speak(const char* text) {
     30     return chromeos::Speak(text);
     31   }
     32 
     33   bool SetSpeakProperties(const char* props) {
     34     return chromeos::SetSpeakProperties(props);
     35   }
     36 
     37   bool StopSpeaking() {
     38     return chromeos::StopSpeaking();
     39   }
     40 
     41   bool IsSpeaking() {
     42     return chromeos::IsSpeaking();
     43   }
     44 
     45   void InitTts(InitStatusCallback callback) {
     46     chromeos::InitTts(callback);
     47   }
     48 
     49  private:
     50   DISALLOW_COPY_AND_ASSIGN(SpeechSynthesisLibraryImpl);
     51 };
     52 
     53 class SpeechSynthesisLibraryStubImpl : public SpeechSynthesisLibrary {
     54  public:
     55   SpeechSynthesisLibraryStubImpl() {}
     56   virtual ~SpeechSynthesisLibraryStubImpl() {}
     57   bool Speak(const char* text) { return true; }
     58   bool SetSpeakProperties(const char* props) { return true; }
     59   bool StopSpeaking() { return true; }
     60   bool IsSpeaking() { return false; }
     61   void InitTts(InitStatusCallback callback) {}
     62 
     63  private:
     64   DISALLOW_COPY_AND_ASSIGN(SpeechSynthesisLibraryStubImpl);
     65 };
     66 
     67 // static
     68 SpeechSynthesisLibrary* SpeechSynthesisLibrary::GetImpl(bool stub) {
     69   if (stub)
     70     return new SpeechSynthesisLibraryStubImpl();
     71   else
     72     return new SpeechSynthesisLibraryImpl();
     73 }
     74 
     75 }  // namespace chromeos
     76