17d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file. 47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_ANDROID_H_ 67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_ANDROID_H_ 77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <jni.h> 97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/android/scoped_java_ref.h" 117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/memory/ref_counted.h" 127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "content/browser/speech/speech_recognizer.h" 147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "content/public/common/speech_recognition_error.h" 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "content/public/common/speech_recognition_result.h" 167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace content { 187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class SpeechRecognitionEventListener; 207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class CONTENT_EXPORT SpeechRecognizerImplAndroid : public SpeechRecognizer { 227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public: 237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SpeechRecognizerImplAndroid(SpeechRecognitionEventListener* listener, 247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int session_id); 257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // SpeechRecognizer methods. 27eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual void StartRecognition(const std::string& device_id) OVERRIDE; 287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void AbortRecognition() OVERRIDE; 297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void StopAudioCapture() OVERRIDE; 307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual bool IsActive() const OVERRIDE; 317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual bool IsCapturingAudio() const OVERRIDE; 327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Called from Java methods via JNI. 347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void OnAudioStart(JNIEnv* env, jobject obj); 357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void OnSoundStart(JNIEnv* env, jobject obj); 367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void OnSoundEnd(JNIEnv* env, jobject obj); 377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void OnAudioEnd(JNIEnv* env, jobject obj); 387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void OnRecognitionResults(JNIEnv* env, jobject obj, jobjectArray strings, 397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) jfloatArray floats, jboolean interim); 407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void OnRecognitionError(JNIEnv* env, jobject obj, jint error); 417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void OnRecognitionEnd(JNIEnv* env, jobject obj); 427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static bool RegisterSpeechRecognizer(JNIEnv* env); 447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) private: 467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) enum State { 477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) STATE_IDLE = 0, 487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) STATE_CAPTURING_AUDIO, 497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) STATE_AWAITING_FINAL_RESULT 507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) }; 517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void StartRecognitionOnUIThread( 537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch std::string language, bool continuous, bool interim_results); 547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void OnRecognitionResultsOnIOThread(SpeechRecognitionResults const &results); 557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual ~SpeechRecognizerImplAndroid(); 577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::android::ScopedJavaGlobalRef<jobject> j_recognition_; 597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) State state_; 607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImplAndroid); 627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}; 637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} // namespace content 657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNIZER_IMPL_ANDROID_H_ 67