tts_android.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
1// Copyright (c) 2013 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_ANDROID_H_
6#define CHROME_BROWSER_SPEECH_TTS_ANDROID_H_
7
8#include "base/android/jni_android.h"
9#include "base/android/scoped_java_ref.h"
10#include "chrome/browser/speech/tts_platform.h"
11
12class TtsPlatformImplAndroid : public TtsPlatformImpl {
13 public:
14  // TtsPlatformImpl implementation.
15  virtual bool PlatformImplAvailable() OVERRIDE;
16  virtual bool Speak(
17      int utterance_id,
18      const std::string& utterance,
19      const std::string& lang,
20      const VoiceData& voice,
21      const UtteranceContinuousParameters& params) OVERRIDE;
22  virtual bool StopSpeaking() OVERRIDE;
23  virtual bool IsSpeaking() OVERRIDE;
24  virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE;
25
26  // Methods called from Java via JNI.
27  void VoicesChanged(JNIEnv* env, jobject obj);
28  void OnEndEvent(JNIEnv* env, jobject obj, jint utterance_id);
29  void OnErrorEvent(JNIEnv* env, jobject obj, jint utterance_id);
30  void OnStartEvent(JNIEnv* env, jobject obj, jint utterance_id);
31
32  // Static functions.
33  static TtsPlatformImplAndroid* GetInstance();
34  static bool Register(JNIEnv* env);
35
36 private:
37  friend struct DefaultSingletonTraits<TtsPlatformImplAndroid>;
38
39  TtsPlatformImplAndroid();
40  virtual ~TtsPlatformImplAndroid();
41
42  void SendFinalTtsEvent(
43      int utterance_id, TtsEventType event_type, int char_index);
44
45  base::android::ScopedJavaGlobalRef<jobject> java_ref_;
46  int utterance_id_;
47  std::string utterance_;
48
49  DISALLOW_COPY_AND_ASSIGN(TtsPlatformImplAndroid);
50};
51
52#endif  // CHROME_BROWSER_SPEECH_TTS_ANDROID_H_
53