| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/speech/speech_recognizer_impl_android.h" | 5 #include "content/browser/speech/speech_recognizer_impl_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 void SpeechRecognizerImplAndroid::StartRecognitionOnUIThread( | 57 void SpeechRecognizerImplAndroid::StartRecognitionOnUIThread( |
| 58 const std::string& language, | 58 const std::string& language, |
| 59 bool continuous, | 59 bool continuous, |
| 60 bool interim_results) { | 60 bool interim_results) { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 61 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 62 JNIEnv* env = AttachCurrentThread(); | 62 JNIEnv* env = AttachCurrentThread(); |
| 63 j_recognition_.Reset(Java_SpeechRecognition_createSpeechRecognition(env, | 63 j_recognition_.Reset(Java_SpeechRecognition_createSpeechRecognition(env, |
| 64 GetApplicationContext(), reinterpret_cast<intptr_t>(this))); | 64 GetApplicationContext(), reinterpret_cast<intptr_t>(this))); |
| 65 Java_SpeechRecognition_startRecognition(env, j_recognition_.obj(), | 65 Java_SpeechRecognition_startRecognition( |
| 66 ConvertUTF8ToJavaString(env, language).obj(), continuous, | 66 env, j_recognition_, ConvertUTF8ToJavaString(env, language), continuous, |
| 67 interim_results); | 67 interim_results); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void SpeechRecognizerImplAndroid::AbortRecognition() { | 70 void SpeechRecognizerImplAndroid::AbortRecognition() { |
| 71 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 71 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 72 state_ = STATE_IDLE; | 72 state_ = STATE_IDLE; |
| 73 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 73 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 74 &content::SpeechRecognizerImplAndroid::AbortRecognition, this)); | 74 &content::SpeechRecognizerImplAndroid::AbortRecognition, this)); |
| 75 return; | 75 return; |
| 76 } | 76 } |
| 77 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 77 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 78 JNIEnv* env = AttachCurrentThread(); | 78 JNIEnv* env = AttachCurrentThread(); |
| 79 if (!j_recognition_.is_null()) | 79 if (!j_recognition_.is_null()) |
| 80 Java_SpeechRecognition_abortRecognition(env, j_recognition_.obj()); | 80 Java_SpeechRecognition_abortRecognition(env, j_recognition_); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void SpeechRecognizerImplAndroid::StopAudioCapture() { | 83 void SpeechRecognizerImplAndroid::StopAudioCapture() { |
| 84 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 84 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 85 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 85 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 86 &content::SpeechRecognizerImplAndroid::StopAudioCapture, this)); | 86 &content::SpeechRecognizerImplAndroid::StopAudioCapture, this)); |
| 87 return; | 87 return; |
| 88 } | 88 } |
| 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 90 JNIEnv* env = AttachCurrentThread(); | 90 JNIEnv* env = AttachCurrentThread(); |
| 91 if (!j_recognition_.is_null()) | 91 if (!j_recognition_.is_null()) |
| 92 Java_SpeechRecognition_stopRecognition(env, j_recognition_.obj()); | 92 Java_SpeechRecognition_stopRecognition(env, j_recognition_); |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool SpeechRecognizerImplAndroid::IsActive() const { | 95 bool SpeechRecognizerImplAndroid::IsActive() const { |
| 96 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 96 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 97 return state_ != STATE_IDLE; | 97 return state_ != STATE_IDLE; |
| 98 } | 98 } |
| 99 | 99 |
| 100 bool SpeechRecognizerImplAndroid::IsCapturingAudio() const { | 100 bool SpeechRecognizerImplAndroid::IsCapturingAudio() const { |
| 101 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 101 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 102 return state_ == STATE_CAPTURING_AUDIO; | 102 return state_ == STATE_CAPTURING_AUDIO; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 state_ = STATE_IDLE; | 220 state_ = STATE_IDLE; |
| 221 listener()->OnRecognitionEnd(session_id()); | 221 listener()->OnRecognitionEnd(session_id()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 // static | 224 // static |
| 225 bool SpeechRecognizerImplAndroid::RegisterSpeechRecognizer(JNIEnv* env) { | 225 bool SpeechRecognizerImplAndroid::RegisterSpeechRecognizer(JNIEnv* env) { |
| 226 return RegisterNativesImpl(env); | 226 return RegisterNativesImpl(env); |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace content | 229 } // namespace content |
| OLD | NEW |