| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_DELEGATE_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_DELEGATE_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_DELEGATE_H_ | 6 #define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_DELEGATE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "content/public/common/speech_input_result.h" | 9 #include "content/public/common/speech_recognition_result.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 // An interface to be implemented by consumers interested in receiving | 13 // An interface to be implemented by consumers interested in receiving |
| 14 // recognition events. | 14 // recognition events. |
| 15 class SpeechRecognizerDelegate { | 15 class SpeechRecognizerDelegate { |
| 16 public: | 16 public: |
| 17 virtual void SetRecognitionResult(int caller_id, | 17 virtual void SetRecognitionResult(int caller_id, |
| 18 const SpeechInputResult& result) = 0; | 18 const SpeechRecognitionResult& result) = 0; |
| 19 | 19 |
| 20 // Invoked when the first audio packet was received from the audio capture | 20 // Invoked when the first audio packet was received from the audio capture |
| 21 // device. | 21 // device. |
| 22 virtual void DidStartReceivingAudio(int caller_id) = 0; | 22 virtual void DidStartReceivingAudio(int caller_id) = 0; |
| 23 | 23 |
| 24 // Invoked when audio recording stops, either due to the end pointer | 24 // Invoked when audio recording stops, either due to the end pointer |
| 25 // detecting silence in user input or if |StopRecording| was called. The | 25 // detecting silence in user input or if |StopRecording| was called. The |
| 26 // delegate has to wait until |DidCompleteRecognition| is invoked before | 26 // delegate has to wait until |DidCompleteRecognition| is invoked before |
| 27 // destroying the |SpeechRecognizer| object. | 27 // destroying the |SpeechRecognizer| object. |
| 28 virtual void DidCompleteRecording(int caller_id) = 0; | 28 virtual void DidCompleteRecording(int caller_id) = 0; |
| 29 | 29 |
| 30 // This is guaranteed to be the last method invoked in the recognition | 30 // This is guaranteed to be the last method invoked in the recognition |
| 31 // sequence and the |SpeechRecognizer| object can be freed up if necessary. | 31 // sequence and the |SpeechRecognizer| object can be freed up if necessary. |
| 32 virtual void DidCompleteRecognition(int caller_id) = 0; | 32 virtual void DidCompleteRecognition(int caller_id) = 0; |
| 33 | 33 |
| 34 // Informs that the end pointer has started detecting speech. | 34 // Informs that the end pointer has started detecting speech. |
| 35 virtual void DidStartReceivingSpeech(int caller_id) = 0; | 35 virtual void DidStartReceivingSpeech(int caller_id) = 0; |
| 36 | 36 |
| 37 // Informs that the end pointer has stopped detecting speech. | 37 // Informs that the end pointer has stopped detecting speech. |
| 38 virtual void DidStopReceivingSpeech(int caller_id) = 0; | 38 virtual void DidStopReceivingSpeech(int caller_id) = 0; |
| 39 | 39 |
| 40 // Invoked if there was an error while recording or recognizing audio. The | 40 // Invoked if there was an error while recording or recognizing audio. The |
| 41 // session has already been cancelled when this call is made and the DidXxxx | 41 // session has already been cancelled when this call is made and the DidXxxx |
| 42 // callbacks will not be issued. It is safe to destroy/release the | 42 // callbacks will not be issued. It is safe to destroy/release the |
| 43 // |SpeechRecognizer| object while processing this call. | 43 // |SpeechRecognizer| object while processing this call. |
| 44 virtual void OnRecognizerError(int caller_id, SpeechInputError error) = 0; | 44 virtual void OnRecognizerError(int caller_id, |
| 45 SpeechRecognitionErrorCode error) = 0; |
| 45 | 46 |
| 46 // At the start of recognition, a short amount of audio is recorded to | 47 // At the start of recognition, a short amount of audio is recorded to |
| 47 // estimate the environment/background noise and this callback is issued | 48 // estimate the environment/background noise and this callback is issued |
| 48 // after that is complete. Typically the delegate brings up any speech | 49 // after that is complete. Typically the delegate brings up any speech |
| 49 // recognition UI once this callback is received. | 50 // recognition UI once this callback is received. |
| 50 virtual void DidCompleteEnvironmentEstimation(int caller_id) = 0; | 51 virtual void DidCompleteEnvironmentEstimation(int caller_id) = 0; |
| 51 | 52 |
| 52 // Informs of a change in the captured audio level, useful if displaying | 53 // Informs of a change in the captured audio level, useful if displaying |
| 53 // a microphone volume indicator while recording. | 54 // a microphone volume indicator while recording. |
| 54 // The value of |volume| and |noise_volume| is in the [0.0, 1.0] range. | 55 // The value of |volume| and |noise_volume| is in the [0.0, 1.0] range. |
| 55 virtual void SetInputVolume(int caller_id, | 56 virtual void SetInputVolume(int caller_id, |
| 56 float volume, | 57 float volume, |
| 57 float noise_volume) = 0; | 58 float noise_volume) = 0; |
| 58 | 59 |
| 59 protected: | 60 protected: |
| 60 virtual ~SpeechRecognizerDelegate() {} | 61 virtual ~SpeechRecognizerDelegate() {} |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 } // namespace content | 64 } // namespace content |
| 64 | 65 |
| 65 #endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_DELEGATE_H_ | 66 #endif // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNIZER_DELEGATE_H_ |
| OLD | NEW |