blob: db7f7c0d3ce97bdb1789f7a1c38ba74cb120c75f [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/common/content_export.h"
#include "third_party/blink/public/mojom/speech/speech_recognition_result.mojom.h"
namespace blink {
namespace mojom {
class SpeechRecognitionError;
} // namespace blink
namespace content {
// The interface to be implemented by consumers interested in receiving
// speech recognition events.
class CONTENT_EXPORT SpeechRecognitionEventListener {
// Invoked when the StartRequest is received and the recognition process is
// started.
virtual void OnRecognitionStart(int session_id) = 0;
// Invoked when the first audio capture is initiated.
virtual void OnAudioStart(int session_id) = 0;
// At the start of recognition, a short amount of audio is recorded to
// estimate the environment/background noise and this callback is issued
// after that is complete. Typically the delegate brings up any speech
// recognition UI once this callback is received.
virtual void OnEnvironmentEstimationComplete(int session_id) = 0;
// Informs that the endpointer has started detecting sound (possibly speech).
virtual void OnSoundStart(int session_id) = 0;
// Informs that the endpointer has stopped detecting sound (a long silence).
virtual void OnSoundEnd(int session_id) = 0;
// Invoked when audio capture stops, either due to the endpoint detecting
// silence, an internal error, or an explicit stop was issued.
virtual void OnAudioEnd(int session_id) = 0;
// Invoked when a result is retrieved.
virtual void OnRecognitionResults(
int session_id,
const std::vector<blink::mojom::SpeechRecognitionResultPtr>& results) = 0;
// Invoked if there was an error while capturing or recognizing audio.
// The recognition has already been cancelled when this call is made and
// no more events will be raised.
virtual void OnRecognitionError(
int session_id,
const blink::mojom::SpeechRecognitionError& error) = 0;
// Informs of a change in the captured audio level, useful if displaying
// a microphone volume indicator while recording.
// The value of |volume| and |noise_volume| is in the [0.0, 1.0] range.
// TODO(janx): Is this necessary? It looks like only x-webkit-speech bubble
// uses it (see
virtual void OnAudioLevelsChange(int session_id,
float volume, float noise_volume) = 0;
// This is guaranteed to be the last event raised in the recognition
// process and the |SpeechRecognizer| object can be freed if necessary.
virtual void OnRecognitionEnd(int session_id) = 0;
virtual ~SpeechRecognitionEventListener() {}
} // namespace content