Bonjours,
je suis en train de réaliser un projet personnel en java et j'aimerai intégrer la reconnaissance vocale à mon logiciel avec sphinx 4.Toutes les API on été incluse correctement dans le projet. Pour cela j'essaye de comprendre le code d'exemple en le compilant. Seulement j'ai une erreur : NullPointerException sur la ligne : recognizer.allocate(); apparement l'objet ne serait pas initialisé.
EDIT : la variable qui est nul est : recognizer je fait un
et sa m'ecrit NULL. comment ce fait-ce que la variable n'est pas initialisée?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 System.out.println(recognizer);
voici le code source :
le fichier de configuration
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package pTest; import java.util.Locale; import javax.speech.*; import javax.speech.synthesis.*; import javax.speech.recognition.* ; import java.io.FileReader ; import edu.cmu.sphinx.frontend.util.Microphone; import edu.cmu.sphinx.recognizer.Recognizer; import edu.cmu.sphinx.util.props.ConfigurationManager; import t2s.son.LecteurTexte; public class Test { public static void main(String[] args) { ConfigurationManager cm; if (args.length > 0) { cm = new ConfigurationManager(args[0]); } else { cm = new ConfigurationManager("gram.config.xml"); } Recognizer recognizer = (Recognizer) cm.lookup("recognizer"); recognizer.allocate(); // start the microphone or exit if the programm if this is not possible Microphone microphone = (Microphone) cm.lookup("microphone"); if (!microphone.startRecording()) { System.out.println("Cannot start microphone."); recognizer.deallocate(); System.exit(1); } System.out.println("Say: (Good morning | Hello) ( Bhiksha | Evandro | Paul | Philip | Rita | Will )"); // loop the recognition until the programm exits. while (true) { System.out.println("Start speaking. Press Ctrl-C to quit.\n"); Result result = (Result) recognizer.recognize(); if (result != null) { String resultText = ((edu.cmu.sphinx.result.Result) result).getBestFinalResultNoFiller(); System.out.println("You said: " + resultText + '\n'); } else { System.out.println("I can't hear what you said.\n"); } } } }
et la regle de grammaire
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?xml version="1.0" encoding="UTF-8"?> <!-- Sphinx-4 Configuration file --> <!-- ******************************************************** --> <!-- configuration file --> <!-- ******************************************************** --> <config> <!-- ******************************************************** --> <!-- The Grammar configuration --> <!-- ******************************************************** --> <component name="jsgfGrammar" type="edu.cmu.sphinx.jsgf.JSGFGrammar"> <property name="dictionary" value="dictionary"/> <property name="grammarLocation" value="resource:/com/cmu/sphinx/"/> <property name="grammarName" value="hello"/> <property name="logMath" value="logMath"/> </component> <!-- ******************************************************** --> <!-- The Dictionary configuration --> <!-- ******************************************************** --> <component name="dictionary" type="edu.cmu.sphinx.linguist.dictionary.FastDictionary"> <property name="dictionaryPath" value="resource:/edu.cmu.sphinx.model.acoustic.WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.Model!/edu/cmu/sphinx/model/acoustic/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict/cmudict.0.6d"/> <property name="fillerPath" value="resource:/edu.cmu.sphinx.model.acoustic.WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.Model!/edu/cmu/sphinx/model/acoustic/WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz/dict/fillerdict"/> <property name="addSilEndingPronunciation" value="false"/> <property name="allowMissingWords" value="false"/> <property name="unitManager" value="unitManager"/> </component> </config>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 #JSGF V1.0; grammar test; public <simple> = hello world;







Répondre avec citation





Partager