speech_recognition_manager.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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_MANAGER_H_
6#define CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_
7
8#include "base/string16.h"
9#include "base/callback.h"
10#include "content/common/content_export.h"
11#include "content/public/common/speech_recognition_result.h"
12
13namespace content {
14
15class SpeechRecognitionEventListener;
16struct SpeechRecognitionSessionConfig;
17struct SpeechRecognitionSessionContext;
18
19// The SpeechRecognitionManager (SRM) is a singleton class that handles SR
20// functionalities within Chrome. Everyone that needs to perform SR should
21// interface exclusively with the SRM, receiving events through the callback
22// interface SpeechRecognitionEventListener.
23// Since many different sources can use SR in different times (some overlapping
24// is allowed while waiting for results), the SRM has the further responsibility
25// of handling separately and reliably (taking into account also call sequences
26// that might not make sense, e.g., two subsequent AbortSession calls).
27// In this sense a session, within the SRM, models the ongoing evolution of a
28// SR request from the viewpoint of the end-user, abstracting all the concrete
29// operations that must be carried out, that will be handled by inner classes.
30class SpeechRecognitionManager {
31 public:
32  enum { kSessionIDInvalid = 0 };
33
34  // Returns the singleton instance.
35  static CONTENT_EXPORT SpeechRecognitionManager* GetInstance();
36
37  // Singleton manager setter useful for tests.
38  static void CONTENT_EXPORT SetManagerForTests(
39      SpeechRecognitionManager* manager);
40
41  // Creates a new recognition session.
42  virtual int CreateSession(const SpeechRecognitionSessionConfig& config) = 0;
43
44  // Starts/restarts recognition for an existing session, after performing a
45  // premilinary check on the delegate (CheckRecognitionIsAllowed).
46  virtual void StartSession(int session_id) = 0;
47
48  // Aborts recognition for an existing session, without providing any result.
49  virtual void AbortSession(int session_id) = 0;
50
51  // Aborts all sessions for a given listener, without providing any result.
52  virtual void AbortAllSessionsForListener(
53      SpeechRecognitionEventListener* listener) = 0;
54
55  // Aborts all sessions for a given RenderView, without providing any result.
56  virtual void AbortAllSessionsForRenderView(int render_process_id,
57                                             int render_view_id) = 0;
58
59  // Stops audio capture for an existing session. The audio captured before the
60  // call will be processed, possibly ending up with a result.
61  virtual void StopAudioCaptureForSession(int session_id) = 0;
62
63  // Retrieves the configuration of a session, as provided by the caller
64  // upon CreateSession.
65  virtual const SpeechRecognitionSessionConfig& GetSessionConfig(int session_id)
66      const = 0;
67
68  // Retrieves the context associated to a session.
69  virtual SpeechRecognitionSessionContext GetSessionContext(
70      int session_id) const = 0;
71
72  // Looks-up an existing session from the context tuple
73  // {render_view_id, render_view_id, request_id}.
74  virtual int GetSession(int render_process_id,
75                         int render_view_id,
76                         int request_id) const = 0;
77
78  // Returns true if the OS reports existence of audio recording devices.
79  virtual bool HasAudioInputDevices() = 0;
80
81  // Used to determine if something else is currently making use of audio input.
82  virtual bool IsCapturingAudio() = 0;
83
84  // Returns a human readable string for the model/make of the active audio
85  // input device for this computer.
86  virtual string16 GetAudioInputDeviceModel() = 0;
87
88  // Invokes the platform provided microphone settings UI in a non-blocking way,
89  // via the BrowserThread::FILE thread.
90  virtual void ShowAudioInputSettings() = 0;
91
92 protected:
93  virtual ~SpeechRecognitionManager() {}
94
95 private:
96  static SpeechRecognitionManager* manager_for_tests_;
97};
98
99}  // namespace content
100
101#endif  // CONTENT_PUBLIC_BROWSER_SPEECH_RECOGNITION_MANAGER_H_
102