Windows Virtual Shields for Arduino
Recognition.h
Go to the documentation of this file.
1 /*
2  Copyright(c) Microsoft Open Technologies, Inc. All rights reserved.
3 
4  The MIT License(MIT)
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files(the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions :
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  THE SOFTWARE.
23 */
24 
25 #ifndef Recognition_h
26 #define Recognition_h
27 
28 #include "Sensor.h"
29 #include "ShieldEvent.h"
30 #include <ArduinoJson.h>
31 
32 #include "Arduino.h"
33 
34 const int Confidence_High = 0;
35 const int Confidence_Medium = 1;
36 const int Confidence_Low = 2;
37 const int Confidence_Rejected = 3;
38 const int Confidence_Error = 5;
39 
40 class Recognition : public Sensor {
41 public:
42  int recognizedIndex = 0;
44 
46 
47  int listen(char* openTextBuffer, int* length, bool useUI = true, long timeout = 0);
48 
49  int listenFor(String constraint, bool useUI = true, int expectedConfidence = Confidence_Medium, long timeout = 0);
50  int listenFor(const char* constraint, bool useUI = true, int expectedConfidence = Confidence_Medium, long timeout = 0);
51  int listenFor(EPtr constraint, bool useUI = true, int expectedConfidence = Confidence_Medium, long timeout = 0);
52 
53  int stop() override;
54 
55  bool heard(String text);
56  bool heard(int spokenNumber);
57 
58  void onJsonReceived(JsonObject& root, ShieldEvent* shieldEvent) override;
59 private:
60  char* openTextBuffer;
61  int* length;
62 };
63 
64 #endif
Definition: Sensor.h:51
int stop() override
Stops this sensor.
Definition: Recognition.cpp:60
int listenFor(String constraint, bool useUI=true, int expectedConfidence=Confidence_Medium, long timeout=0)
Recognizes the specified constricted recognition text without a UI.
Definition: Recognition.cpp:70
Definition: VirtualShield.h:50
Definition: Recognition.h:40
VirtualShield & shield
Definition: Sensor.h:55
bool heard(String text)
Verifies if the recognized spoken text matches the text parameter.
Definition: Recognition.cpp:104
int recognizedIndex
Definition: Recognition.h:42
const int Confidence_Error
Definition: Recognition.h:38
int confidence
Definition: Recognition.h:43
const int Confidence_Rejected
Definition: Recognition.h:37
void onJsonReceived(JsonObject &root, ShieldEvent *shieldEvent) override
Event called when a valid json message was received. Consumes the proper values for this sensor...
Definition: Recognition.cpp:133
Definition: SensorModels.h:101
const int Confidence_Low
Definition: Recognition.h:36
Definition: ShieldEvent.h:35
int listen(char *openTextBuffer, int *length, bool useUI=true, long timeout=0)
Recognizes open text / not constricted without a UI.
Definition: Recognition.cpp:49
const int Confidence_High
Definition: Recognition.h:34
const int Confidence_Medium
Definition: Recognition.h:35
Recognition(const VirtualShield &shield)
Initializes a new instance of the Speech class.
Definition: Recognition.cpp:41