Menu

[r9]: / vcrw / src / speech / recognizer / Sphinx.java  Maximize  Restore  History

Download this file

107 lines (87 with data), 2.7 kB

  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
package speech.recognizer;
import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;
public class Sphinx
{
static String status;
/*private static ConfigurationManager cm;
private static Recognizer recognizer;
private static Microphone microphone;*/
/*public Sphinx()
{
cm = new ConfigurationManager(Sphinx.class.getResource("main.config.xml"));
recognizer = (Recognizer) cm.lookup("recognizer");
microphone = (Microphone) cm.lookup("microphone");
}*/
public String error(int error_code)
{
switch(error_code)
{
case 1:
return "Sorry, Can't start microphone !";
case 2:
return "Sorry, I can't hear what you said!";
default:
return null;
}
}
public String get_status()
{
return status;
}
public String get_direction()
{
ConfigurationManager cm;
Recognizer recognizer;
Microphone microphone;
cm = new ConfigurationManager(Sphinx.class.getResource("direction.config.xml"));
recognizer = (Recognizer) cm.lookup("recognizer");
microphone = (Microphone) cm.lookup("microphone");
recognizer.allocate();
if (! microphone.startRecording())
{
recognizer.deallocate();
error(1);
}
status = "Processing..";
Result result = recognizer.recognize();
if (result != null)
{
recognizer.deallocate();
return result.getBestResultNoFiller();
}
else
error(2);
return null;
}
public boolean get_answer()
{
ConfigurationManager cm;
Recognizer recognizer;
Microphone microphone;
cm = new ConfigurationManager(Sphinx.class.getResource("answer.config.xml"));
recognizer = (Recognizer) cm.lookup("recognizer");
microphone = (Microphone) cm.lookup("microphone");
recognizer.allocate();
if (! microphone.startRecording())
{
recognizer.deallocate();
error(1);
}
Result result = recognizer.recognize();
if (result != null)
{
recognizer.deallocate();
String answer = result.getBestFinalResultNoFiller();
if(answer.equalsIgnoreCase("yes"))
return true;
else
return false;
}
else
error(2);
return false;
}
}