Skip to content

Commit 9ef46e2

Browse files
author
breandan
committed
Additional debugging commands
1 parent 733025d commit 9ef46e2

15 files changed

+327
-414
lines changed

META-INF/plugin.xml

+8-13
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
<version>1.0</version>
55
<vendor email="[email protected]" url="http://www.jetbrains.com">JetBrains</vendor>
66

7-
<description><![CDATA[
8-
Enter short description for your plugin here.<br>
9-
<em>most HTML tags may be used</em>
10-
]]></description>
11-
12-
<change-notes><![CDATA[
13-
Add change notes here.<br>
14-
<em>most HTML tags may be used</em>
15-
]]>
7+
<description>Speech-based user interface for your favorite IDE. Idear listens to voice commands and performs basic actions like navigating the IDE.</description>
8+
9+
<change-notes>
10+
1611
</change-notes>
1712

1813
<!-- please see https://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description -->
@@ -29,19 +24,19 @@
2924

3025
<extensions defaultExtensionNs="com.intellij">
3126

32-
<applicationService serviceInterface="com.jetbrains.idear.asr.ASRService" serviceImplementation="com.jetbrains.idear.asr.ASRServiceImpl">
27+
<applicationService serviceInterface="com.jetbrains.idear.asr.ASRService" serviceImplementation="com.jetbrains.idear.asr.ASRService">
3328
</applicationService>
3429

35-
<applicationService serviceInterface="com.jetbrains.idear.tts.TTSService" serviceImplementation="com.jetbrains.idear.tts.TTSServiceImpl">
30+
<applicationService serviceInterface="com.jetbrains.idear.tts.TTSService" serviceImplementation="com.jetbrains.idear.tts.TTSService">
3631
</applicationService>
3732

38-
<applicationService serviceInterface="com.jetbrains.idear.asr.GrammarService" serviceImplementation="com.jetbrains.idear.asr.GrammarServiceImpl">
33+
<applicationService serviceInterface="com.jetbrains.idear.asr.GrammarService" serviceImplementation="com.jetbrains.idear.asr.GrammarService">
3934
</applicationService>
4035

4136
<applicationService serviceInterface="com.jetbrains.idear.nlp.ParserService" serviceImplementation="com.jetbrains.idear.nlp.NlpParserService">
4237
</applicationService>
4338

44-
<applicationService serviceInterface="com.jetbrains.idear.ide.IDEService" serviceImplementation="com.jetbrains.idear.ide.IDEServiceImpl">
39+
<applicationService serviceInterface="com.jetbrains.idear.ide.IDEService" serviceImplementation="com.jetbrains.idear.ide.IDEService">
4540
</applicationService>
4641

4742
</extensions>

src/com/jetbrains/idear/actions/recognition/FindUsagesActionRecognizer.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package com.jetbrains.idear.actions.recognition;
22

3-
import com.intellij.codeInsight.TargetElementUtil;
4-
import com.intellij.find.FindManager;
5-
import com.intellij.find.findUsages.FindUsagesOptions;
63
import com.intellij.find.findUsages.PsiElement2UsageTargetAdapter;
74
import com.intellij.openapi.actionSystem.*;
85
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
96
import com.intellij.openapi.components.ServiceManager;
10-
import com.intellij.openapi.editor.Document;
117
import com.intellij.openapi.editor.Editor;
128
import com.intellij.openapi.project.Project;
13-
import com.intellij.psi.*;
14-
import com.intellij.psi.util.PsiTreeUtil;
9+
import com.intellij.psi.PsiClass;
10+
import com.intellij.psi.PsiElement;
1511
import com.intellij.usages.UsageTarget;
1612
import com.intellij.usages.UsageView;
1713
import com.jetbrains.idear.psi.PsiUtil;

src/com/jetbrains/idear/asr/ASRControlLoop.java

+50-26
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import javax.sound.sampled.AudioSystem;
2222
import javax.sound.sampled.Clip;
2323
import java.awt.*;
24-
import java.awt.event.KeyEvent;
2524
import java.io.IOException;
25+
import java.util.Collection;
2626
import java.util.logging.Level;
2727
import java.util.logging.Logger;
2828

29+
import static java.awt.event.KeyEvent.*;
30+
2931
/**
3032
* Created by breandan on 10/23/2015.
3133
*/
@@ -54,6 +56,7 @@ public ASRControlLoop(CustomLiveSpeechRecognizer recognizer) {
5456
public static final String SHRINK = "shrink";
5557
public static final String PRESS = "press";
5658
public static final String DELETE = "delete";
59+
public static final String DEBUG = "debug";
5760
public static final String ENTER = "enter";
5861
public static final String ESCAPE = "escape";
5962
public static final String TAB = "tab";
@@ -105,6 +108,7 @@ private String getResultFromRecognizer() {
105108
logger.info("\tTop H: " + result.getResult() + " / " + result.getResult().getBestToken() + " / " + result.getResult().getBestPronunciationResult());
106109
logger.info("\tTop 3H: " + result.getNbest(3));
107110

111+
Collection<String> c = result.getNbest(3);
108112
return result.getHypothesis();
109113
}
110114

@@ -119,7 +123,7 @@ private void applyAction(String c) {
119123
} else if (c.endsWith(RECENT)) {
120124
ideService.invokeAction(IdeActions.ACTION_RECENT_FILES);
121125
} else if (c.endsWith(TERMINAL)) {
122-
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_F12);
126+
pressKeystroke(VK_ALT, VK_F12);
123127
}
124128
} else if (c.startsWith(NAVIGATE)) {
125129
ideService.invokeAction("GotoDeclaration");
@@ -130,53 +134,67 @@ private void applyAction(String c) {
130134
ideService.invokeAction("Idear.WhereAmI");
131135
} else if (c.startsWith("focus")) {
132136
if (c.endsWith(EDITOR)) {
133-
pressKeystroke(KeyEvent.VK_ESCAPE);
137+
pressKeystroke(VK_ESCAPE);
134138
} else if (c.endsWith(PROJECT)) {
135-
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_1);
139+
pressKeystroke(VK_ALT, VK_1);
136140
} else if(c.endsWith("symbols")) {
137141
ideService.invokeAction("AceJumpAction");
142+
ideService.type(VK_SPACE);
138143
ideService.type(("" + recognizeNumber()).toCharArray());
139144
}
145+
} else if (c.startsWith(GOTO)) {
146+
140147
} else if (c.startsWith(EXPAND)) {
141-
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_W);
148+
// ActionManager instance = ActionManager.getInstance();
149+
// AnAction a = instance.getAction("EditorSelectWord");
150+
// AnActionEvent event = new AnActionEvent(null, DataManager.getInstance().getDataContext(),
151+
// ActionPlaces.UNKNOWN, a.getTemplatePresentation(), instance, 0);
152+
// a.actionPerformed(event);
153+
ideService.invokeAction("EditorSelectWord");
142154
} else if (c.startsWith(SHRINK)) {
143-
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_SHIFT, KeyEvent.VK_W);
155+
pressKeystroke(VK_CONTROL, VK_SHIFT, VK_W);
144156
} else if (c.startsWith("press")) {
145157
if (c.contains("delete")) {
146-
pressKeystroke(KeyEvent.VK_DELETE);
147-
} else if (c.contains("return")) {
148-
pressKeystroke(KeyEvent.VK_ENTER);
158+
pressKeystroke(VK_DELETE);
159+
} else if (c.contains("return") || c.contains("enter")) {
160+
pressKeystroke(VK_ENTER);
149161
} else if (c.contains(ESCAPE)) {
150-
pressKeystroke(KeyEvent.VK_ESCAPE);
162+
pressKeystroke(VK_ESCAPE);
151163
} else if (c.contains(TAB)) {
152-
pressKeystroke(KeyEvent.VK_TAB);
164+
pressKeystroke(VK_TAB);
153165
} else if (c.contains(UNDO)) {
154-
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_Z);
166+
pressKeystroke(VK_CONTROL, VK_Z);
155167
}
156168
} else if (c.startsWith("following")) {
157169
if (c.endsWith("line")) {
158-
pressKeystroke(KeyEvent.VK_DOWN);
170+
pressKeystroke(VK_DOWN);
159171
} else if (c.endsWith("page")) {
160-
pressKeystroke(KeyEvent.VK_PAGE_DOWN);
172+
pressKeystroke(VK_PAGE_DOWN);
161173
} else if (c.endsWith("method")) {
162-
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_DOWN);
174+
pressKeystroke(VK_ALT, VK_DOWN);
175+
} else if (c.endsWith("tab")) {
176+
pressKeystroke(VK_CONTROL, VK_TAB);
177+
} else if (c.endsWith("page")) {
178+
pressKeystroke(VK_PAGE_DOWN);
163179
}
164180
} else if (c.startsWith("previous")) {
165181
if (c.endsWith("line")) {
166-
pressKeystroke(KeyEvent.VK_UP);
182+
pressKeystroke(VK_UP);
167183
} else if (c.endsWith("page")) {
168-
pressKeystroke(KeyEvent.VK_PAGE_UP);
184+
pressKeystroke(VK_PAGE_UP);
169185
} else if (c.endsWith("method")) {
170-
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_UP);
186+
pressKeystroke(VK_ALT, VK_UP);
187+
} else if (c.endsWith("page")) {
188+
pressKeystroke(VK_PAGE_UP);
171189
}
172190
} else if (c.startsWith("extract this")) {
173191
if (c.endsWith("method")) {
174-
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_M);
192+
pressKeystroke(VK_CONTROL, VK_ALT, VK_M);
175193
} else if (c.endsWith("parameter")) {
176-
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_P);
194+
pressKeystroke(VK_CONTROL, VK_ALT, VK_P);
177195
}
178196
} else if (c.startsWith("inspect code")) {
179-
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_SHIFT, KeyEvent.VK_I);
197+
pressKeystroke(VK_ALT, VK_SHIFT, VK_I);
180198
} else if (c.startsWith("speech pause")) {
181199
pauseSpeech();
182200
} else if (c.startsWith(OK_IDEA) || c.startsWith(OKAY_IDEA)) {
@@ -187,16 +205,22 @@ private void applyAction(String c) {
187205
fireGoogleSearch();
188206
} else if (c.contains("break point")) {
189207
if (c.startsWith("toggle")) {
190-
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_F8);
208+
pressKeystroke(VK_CONTROL, VK_F8);
191209
} else if (c.startsWith("view")) {
192-
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_SHIFT, KeyEvent.VK_F8);
210+
pressKeystroke(VK_CONTROL, VK_SHIFT, VK_F8);
193211
}
212+
} else if(c.startsWith("debug")){
213+
pressKeystroke(VK_SHIFT, VK_F9);
194214
} else if (c.startsWith("step")) {
195215
if (c.endsWith("over")) {
196-
pressKeystroke(KeyEvent.VK_F8);
216+
pressKeystroke(VK_F8);
197217
} else if (c.endsWith("into")) {
198-
pressKeystroke(KeyEvent.VK_F7);
218+
pressKeystroke(VK_F7);
219+
} else if (c.endsWith("return")) {
220+
pressKeystroke(VK_SHIFT, VK_F8);
199221
}
222+
} else if (c.startsWith("resume")) {
223+
pressKeystroke(VK_F9);
200224
} else if (c.startsWith("tell me a joke")) {
201225
tellJoke();
202226
} else if (c.contains("check")) {
@@ -338,7 +362,7 @@ public static synchronized void beep() {
338362
try {
339363
Clip clip = AudioSystem.getClip();
340364
AudioInputStream inputStream = AudioSystem.getAudioInputStream(
341-
ASRServiceImpl.class.getResourceAsStream("/com.jetbrains.idear/sounds/beep.wav"));
365+
ASRService.class.getResourceAsStream("/com.jetbrains.idear/sounds/beep.wav"));
342366
clip.open(inputStream);
343367
clip.start();
344368
} catch (Exception e) {
+73-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,76 @@
11
package com.jetbrains.idear.asr;
22

3-
public interface ASRService {
4-
void init();
5-
void dispose();
6-
boolean activate();
7-
boolean deactivate();
3+
import com.jetbrains.idear.recognizer.CustomLiveSpeechRecognizer;
4+
import edu.cmu.sphinx.api.Configuration;
5+
6+
import java.io.IOException;
7+
import java.util.logging.Level;
8+
import java.util.logging.Logger;
9+
10+
public class ASRService {
11+
12+
public static final double MASTER_GAIN = 0.85;
13+
public static final double CONFIDENCE_LEVEL_THRESHOLD = 0.5;
14+
15+
private Thread speechThread;
16+
17+
private static final String ACOUSTIC_MODEL = "resource:/edu.cmu.sphinx.models.en-us/en-us";
18+
private static final String DICTIONARY_PATH = "resource:/edu.cmu.sphinx.models.en-us/cmudict-en-us.dict";
19+
private static final String GRAMMAR_PATH = "resource:/com.jetbrains.idear/grammars";
20+
21+
private static final Logger logger = Logger.getLogger(ASRService.class.getSimpleName());
22+
23+
private CustomLiveSpeechRecognizer recognizer;
24+
25+
public void init() {
26+
Configuration configuration = new Configuration();
27+
configuration.setAcousticModelPath(ACOUSTIC_MODEL);
28+
configuration.setDictionaryPath(DICTIONARY_PATH);
29+
configuration.setGrammarPath(GRAMMAR_PATH);
30+
configuration.setUseGrammar(true);
31+
32+
configuration.setGrammarName("command");
33+
34+
try {
35+
recognizer = new CustomLiveSpeechRecognizer(configuration);
36+
// recognizer.setMasterGain(MASTER_GAIN);
37+
speechThread = new Thread(new ASRControlLoop(recognizer), "ASR Thread");
38+
recognizer.startRecognition(true);
39+
// Fire up control-loop
40+
speechThread.start();
41+
} catch (IOException e) {
42+
logger.log(Level.SEVERE, "Couldn't initialize speech recognizer:", e);
43+
}
44+
}
45+
46+
public boolean activate() {
47+
// if (getStatus() == Status.INIT) {
48+
// // Cold start prune cache
49+
// recognizer.startRecognition(true);
50+
// }
51+
52+
return ListeningState.activate();
53+
}
54+
55+
public boolean deactivate() {
56+
return ListeningState.standBy();
57+
}
58+
59+
public void dispose() {
60+
// Deactivate in the first place, therefore actually
61+
// prevent activation upon the user-input
62+
deactivate();
63+
terminate();
64+
}
65+
66+
private void terminate() {
67+
recognizer.stopRecognition();
68+
}
69+
70+
// This is for testing purposes solely
71+
public static void main(String[] args) {
72+
ASRService asrService = new ASRService();
73+
asrService.init();
74+
ListeningState.activate();
75+
}
876
}

src/com/jetbrains/idear/asr/ASRServiceImpl.java

-76
This file was deleted.

0 commit comments

Comments
 (0)