Home | History | Annotate | Download | only in browser
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_EVENT_LISTENER_H_
      6 #define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_EVENT_LISTENER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "content/common/content_export.h"
     10 #include "content/public/common/speech_recognition_result.h"
     11 
     12 namespace content {
     13 
     14 struct SpeechRecognitionError;
     15 
     16 // The interface to be implemented by consumers interested in receiving
     17 // speech recognition events.
     18 class CONTENT_EXPORT SpeechRecognitionEventListener {
     19  public:
     20   // Invoked when the StartRequest is received and the recognition process is
     21   // started.
     22   virtual void OnRecognitionStart(int session_id) = 0;
     23 
     24   // Invoked when the first audio capture is initiated.
     25   virtual void OnAudioStart(int session_id) = 0;
     26 
     27   // At the start of recognition, a short amount of audio is recorded to
     28   // estimate the environment/background noise and this callback is issued
     29   // after that is complete. Typically the delegate brings up any speech
     30   // recognition UI once this callback is received.
     31   virtual void OnEnvironmentEstimationComplete(int session_id) = 0;
     32 
     33   // Informs that the endpointer has started detecting sound (possibly speech).
     34   virtual void OnSoundStart(int session_id) = 0;
     35 
     36   // Informs that the endpointer has stopped detecting sound (a long silence).
     37   virtual void OnSoundEnd(int session_id) = 0;
     38 
     39   // Invoked when audio capture stops, either due to the endpoint detecting
     40   // silence, an internal error, or an explicit stop was issued.
     41   virtual void OnAudioEnd(int session_id) = 0;
     42 
     43   // Invoked when a result is retrieved.
     44   virtual void OnRecognitionResults(int session_id,
     45       const SpeechRecognitionResults& results) = 0;
     46 
     47   // Invoked if there was an error while capturing or recognizing audio.
     48   // The recognition has already been cancelled when this call is made and
     49   // no more events will be raised.
     50   virtual void OnRecognitionError(int session_id,
     51                                   const SpeechRecognitionError& error) = 0;
     52 
     53   // Informs of a change in the captured audio level, useful if displaying
     54   // a microphone volume indicator while recording.
     55   // The value of |volume| and |noise_volume| is in the [0.0, 1.0] range.
     56   // TODO(janx): Is this necessary? It looks like only x-webkit-speech bubble
     57   // uses it (see crbug.com/247351).
     58   virtual void OnAudioLevelsChange(int session_id,
     59                                    float volume, float noise_volume) = 0;
     60 
     61   // This is guaranteed to be the last event raised in the recognition
     62   // process and the |SpeechRecognizer| object can be freed if necessary.
     63   virtual void OnRecognitionEnd(int session_id) = 0;
     64 
     65  protected:
     66   virtual ~SpeechRecognitionEventListener() {}
     67 };
     68 
     69 }  // namespace content
     70 
     71 #endif  // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_EVENT_LISTENER_H_
     72