-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMacSpeechHandler.mm
117 lines (97 loc) · 2.95 KB
/
MacSpeechHandler.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <iostream>
#include "MacSpeechHandler.h"
#include "Voice_Adapter.hh"
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import "MacSpeechHandlerDelegate.h"
MacSpeechHandler::MacSpeechHandler(Voice_Adapter* adapter) : SpeechHandler(adapter)
{
pool = [[NSAutoreleasePool alloc] init];
NSArray *cmds = [NSArray arrayWithObjects:@"Pan Up", @"Pan Left", @"Pan Right", @"Pan Down", @"Full Size", @"Fit Image", @"Zoom In", @"Zoom Out",
@"Up", @"Left", @"Right", @"Down", @"Full", @"Fit", @"In", @"Out", @"Enhance", @"Restore", nil];
recog = [[NSSpeechRecognizer alloc] init]; // recog is an ivar
[recog setCommands:cmds];
[recog setDisplayedCommandsTitle:@"Pan and Zoom"];
delegate = [[MacSpeechHandlerDelegate alloc] init: this]; // passing this?
if (delegate)
{
[recog setDelegate:delegate];
}
else
{
std::cout << "Unable to initialize NSSpeechHandlerDelegate" << std::endl;
}
voice_adapter = adapter;
}
MacSpeechHandler::~MacSpeechHandler()
{
suspend();
[recog release];
recog = nil;
[pool release];
}
void MacSpeechHandler::listen()
{
std::cout << "I am listening " << std::endl;
[recog startListening];
}
void MacSpeechHandler::suspend()
{
std::cout << "I am not listening" << std::endl;
[recog stopListening];
}
void MacSpeechHandler::handleSpeechCommand(NSString* cmd)
{
std::cerr << "Received command" << cmd << std::endl;
if ([(NSString *)cmd isEqualToString:@"Full Size"] || [(NSString *)cmd isEqualToString:@"Full"])
{
voice_adapter->doFullSize();
return;
}
if ([(NSString *)cmd isEqualToString:@"Fit Image"] || [(NSString *)cmd isEqualToString:@"Fit"])
{
voice_adapter->doFitImage();
return;
}
if ([(NSString *)cmd isEqualToString:@"Zoom In"] || [(NSString *)cmd isEqualToString:@"In"])
{
voice_adapter->doZoomIn();
return;
}
if ([(NSString *)cmd isEqualToString:@"Zoom Out"] || [(NSString *)cmd isEqualToString:@"Out"])
{
voice_adapter->doZoomOut();
return;
}
if ([(NSString *)cmd isEqualToString:@"Pan Up"] || [(NSString *)cmd isEqualToString:@"Up"])
{
voice_adapter->doPanUp();
return;
}
if ([(NSString *)cmd isEqualToString:@"Pan Down"] || [(NSString *)cmd isEqualToString:@"Down"])
{
voice_adapter->doPanDown();
return;
}
if ([(NSString *)cmd isEqualToString:@"Pan Left"] || [(NSString *)cmd isEqualToString:@"Left"])
{
voice_adapter->doPanLeft();
return;
}
if ([(NSString *)cmd isEqualToString:@"Pan Right"] || [(NSString *)cmd isEqualToString:@"Right"])
{
voice_adapter->doPanRight();
return;
}
if ([(NSString *)cmd isEqualToString:@"Enhance"])
{
voice_adapter->doEnhance();
return;
}
if ([(NSString *)cmd isEqualToString:@"Restore"])
{
voice_adapter->doRestore();
return;
}
std::cerr << "Unhandled command" << cmd << std::endl;
}