Input/Output Speech Recognizer

Legi

Mitglied
Hey!
Ich arbeite neuerdings mit Java Speech Recognizer.
Ich versuche, Sprache zu Text umzuwandeln.
Doch wenn ich ein neues Wort hinzufüge, kommt in der Konsole folgendes (Und da, ich habe einige Dateien heruntergeladen:D):
Code:
Jun 12, 2018 6:12:13 PM model.SpeechRecognizerMain <init>
INFORMATION: Loading Speech Recognizer...

18:12:14.041 INFO unitManager          CI Unit: AA
18:12:14.060 INFO unitManager          CI Unit: AAAH
18:12:14.060 INFO unitManager          CI Unit: AAH
18:12:14.060 INFO unitManager          CI Unit: AE
18:12:14.060 INFO unitManager          CI Unit: AH
18:12:14.060 INFO unitManager          CI Unit: AO
18:12:14.060 INFO unitManager          CI Unit: AW
18:12:14.060 INFO unitManager          CI Unit: AX
18:12:14.060 INFO unitManager          CI Unit: AY
18:12:14.060 INFO unitManager          CI Unit: B
18:12:14.060 INFO unitManager          CI Unit: CC
18:12:14.060 INFO unitManager          CI Unit: CH
18:12:14.060 INFO unitManager          CI Unit: D
18:12:14.060 INFO unitManager          CI Unit: DH
18:12:14.060 INFO unitManager          CI Unit: EE
18:12:14.060 INFO unitManager          CI Unit: EEH
18:12:14.060 INFO unitManager          CI Unit: EH
18:12:14.060 INFO unitManager          CI Unit: EHH
18:12:14.060 INFO unitManager          CI Unit: ER
18:12:14.060 INFO unitManager          CI Unit: ERH
18:12:14.060 INFO unitManager          CI Unit: EX
18:12:14.060 INFO unitManager          CI Unit: F
18:12:14.060 INFO unitManager          CI Unit: G
18:12:14.060 INFO unitManager          CI Unit: HH
18:12:14.060 INFO unitManager          CI Unit: HHH
18:12:14.060 INFO unitManager          CI Unit: IH
18:12:14.060 INFO unitManager          CI Unit: IIH
18:12:14.060 INFO unitManager          CI Unit: IY
18:12:14.060 INFO unitManager          CI Unit: JH
18:12:14.060 INFO unitManager          CI Unit: K
18:12:14.060 INFO unitManager          CI Unit: L
18:12:14.060 INFO unitManager          CI Unit: M
18:12:14.060 INFO unitManager          CI Unit: N
18:12:14.060 INFO unitManager          CI Unit: NG
18:12:14.060 INFO unitManager          CI Unit: OE
18:12:14.060 INFO unitManager          CI Unit: OH
18:12:14.060 INFO unitManager          CI Unit: OHH
18:12:14.060 INFO unitManager          CI Unit: OI
18:12:14.060 INFO unitManager          CI Unit: OO
18:12:14.060 INFO unitManager          CI Unit: OOH
18:12:14.060 INFO unitManager          CI Unit: OOOH
18:12:14.060 INFO unitManager          CI Unit: OY
18:12:14.060 INFO unitManager          CI Unit: P
18:12:14.060 INFO unitManager          CI Unit: PF
18:12:14.060 INFO unitManager          CI Unit: Q
18:12:14.060 INFO unitManager          CI Unit: R
18:12:14.060 INFO unitManager          CI Unit: RR
18:12:14.060 INFO unitManager          CI Unit: S
18:12:14.060 INFO unitManager          CI Unit: SH
18:12:14.060 INFO unitManager          CI Unit: T
18:12:14.060 INFO unitManager          CI Unit: TH
18:12:14.060 INFO unitManager          CI Unit: TS
18:12:14.060 INFO unitManager          CI Unit: UE
18:12:14.060 INFO unitManager          CI Unit: UH
18:12:14.076 INFO unitManager          CI Unit: UU
18:12:14.076 INFO unitManager          CI Unit: UUH
18:12:14.076 INFO unitManager          CI Unit: V
18:12:14.076 INFO unitManager          CI Unit: VV
18:12:14.076 INFO unitManager          CI Unit: W
18:12:14.076 INFO unitManager          CI Unit: X
18:12:14.076 INFO unitManager          CI Unit: Y
18:12:14.076 INFO unitManager          CI Unit: YY
18:12:14.076 INFO unitManager          CI Unit: YYH
18:12:14.076 INFO unitManager          CI Unit: Z
18:12:14.076 INFO unitManager          CI Unit: ZH
18:12:14.708 INFO autoCepstrum         Cepstrum component auto-configured as follows: autoCepstrum {MelFrequencyFilterBank, Denoise, DiscreteCosineTransform2, Lifter}
18:12:14.910 INFO acousticModelLoader  Loading tied-state acoustic model from: file:/P:/Eclipse%20Coding%20Data/Eclipse%20Programmierung/Programm-Development/Spracherkennung%20Test/bin/german_acoustic/
18:12:14.910 INFO acousticModelLoader  Pool means Entries: 99168
18:12:14.910 INFO acousticModelLoader  Pool variances Entries: 99168
18:12:14.910 INFO acousticModelLoader  Pool transition_matrices Entries: 66
18:12:14.910 INFO acousticModelLoader  Pool senones Entries: 6198
18:12:14.910 INFO acousticModelLoader  Gaussian weights: mixture_weights. Entries: 6198
18:12:14.910 INFO acousticModelLoader  Pool senones Entries: 6198
18:12:14.910 INFO acousticModelLoader  Context Independent Unit Entries: 66
18:12:14.910 INFO acousticModelLoader  HMM Manager: 84963 hmms
18:12:14.910 INFO acousticModel        CompositeSenoneSequences: 0
18:12:14.910 INFO dictionary           Loading dictionary from: file:/P:/Eclipse%20Coding%20Data/Eclipse%20Programmierung/Programm-Development/Spracherkennung%20Test/bin/german_lm/german.dic
18:12:14.932 INFO dictionary           Loading filler dictionary from: file:/P:/Eclipse%20Coding%20Data/Eclipse%20Programmierung/Programm-Development/Spracherkennung%20Test/bin/german_acoustic/noisedict
18:12:14.948 INFO dictionary           The dictionary is missing a phonetic transcription for the word 'Bot'
18:12:14.948 WARNING jsgfGrammar       Can't find pronunciation for Bot
18:12:14.948 INFO jsgfGrammar          Num nodes : 18
18:12:14.948 INFO jsgfGrammar          Num arcs  : 26
18:12:14.948 INFO jsgfGrammar          Avg arcs  : 1.4444444
18:12:14.964 INFO speedTracker         # ----------------------------- Timers----------------------------------------
18:12:14.964 INFO speedTracker         # Name               Count   CurTime   MinTime   MaxTime   AvgTime   TotTime   
18:12:14.979 INFO speedTracker         grammarLoad          1       0,0160s   0,0160s   0,0160s   0,0160s   0,0160s   
18:12:14.979 INFO speedTracker         Load Dictionary      1       0,0220s   0,0220s   0,0220s   0,0220s   0,0220s   
18:12:14.979 INFO speedTracker         Compile              1       0,0160s   0,0160s   0,0160s   0,0160s   0,0160s   
18:12:14.979 INFO speedTracker         Create States        1       0,0000s   0,0000s   0,0000s   0,0000s   0,0000s   
18:12:14.979 INFO speedTracker         Collect Contexts     1       0,0000s   0,0000s   0,0000s   0,0000s   0,0000s   
18:12:14.979 INFO speedTracker         Expand States        1       0,0160s   0,0160s   0,0160s   0,0160s   0,0160s   
18:12:14.979 INFO speedTracker         Connect Nodes        1       0,0000s   0,0000s   0,0000s   0,0000s   0,0000s   
18:12:14.979 INFO speedTracker         Load AM              1       1,3530s   1,3530s   1,3530s   1,3530s   1,3530s   
Jun 12, 2018 6:12:14 PM model.SpeechRecognizerMain lambda$0
INFORMATION: You can start to speak...
Warum ist das so und was muss ich ändern?
Sollted ihr Code brauchen, sagt Bescheid, welchen ihr braucht,
denn es sind insgesamt 115.938 Zeilen Code :eek:.

MfG,
~Legi
 

Java20134

Bekanntes Mitglied
Ich gehe davon aus, dass du nur eine Klasse hast. Kleiner Tipp: Nutze mehr Klassen in Java!
Und ansonsten wäre es nicht schlecht, wenn man ein wenig Code sehen könnte. Vielleicht erst einmal der Code vom Anfang des Programmes.
 

Legi

Mitglied
Nein, ich habe mehrere Klassen.
Hier der Code der Main Datei:
Code:
package model;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Port;

import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.LiveSpeechRecognizer;
import edu.cmu.sphinx.api.SpeechResult;
import edu.cmu.sphinx.result.WordResult;

public class SpeechRecognizerMain {
   
   // Necessary
   private LiveSpeechRecognizer recognizer;
   
   // Logger
   private Logger logger = Logger.getLogger(getClass().getName());
   
   /**
    * This String contains the Result that is coming back from SpeechRecognizer
    */
   private String speechRecognitionResult;
   
   //-----------------Lock Variables-----------------------------
   
   /**
    * This variable is used to ignore the results of speech recognition cause actually it can't be stopped...
    *
    * <br>
    * Check this link for more information: <a href=
    * "https://sourceforge.net/p/cmusphinx/discussion/sphinx4/thread/3875fc39/">https://sourceforge.net/p/cmusphinx/discussion/sphinx4/thread/3875fc39/</a>
    */
   private boolean ignoreSpeechRecognitionResults = false;
   
   /**
    * Checks if the speech recognise is already running
    */
   private boolean speechRecognizerThreadRunning = false;
   
   /**
    * Checks if the resources Thread is already running
    */
   private boolean resourcesThreadRunning;
   
   //---
   
   /**
    * This executor service is used in order the playerState events to be executed in an order
    */
   private ExecutorService eventsExecutorService = Executors.newFixedThreadPool(2);
   
   //------------------------------------------------------------------------------------
   
   /**
    * Constructor
    */
   public SpeechRecognizerMain() {
       
       // Loading Message
       logger.log(Level.INFO, "Loading Speech Recognizer...\n");
       
       // Configuration
       Configuration configuration = new Configuration();
       
       // Load model from the jar
       configuration.setAcousticModelPath("resource:/german_acoustic/");
       configuration.setDictionaryPath("resource:/german_lm/german.dic");
       
       //====================================================================================
       //=====================READ THIS!!!===============================================
       //Uncomment this line of code if you want the recognizer to recognize every word of the language
       //you are using , here it is English for example   
       //====================================================================================
       configuration.setLanguageModelPath("resource:/german_lm/cmusphinx-voxforge-de.lm.bin");
       
       //====================================================================================
       //=====================READ THIS!!!===============================================
       //If you don't want to use a grammar file comment below 3 lines and uncomment the above line for language model   
       //====================================================================================
       
       // Grammar
       configuration.setGrammarPath("resource:/grammars");
       configuration.setGrammarName("grammar");
       configuration.setUseGrammar(true);
       
       try {
           recognizer = new LiveSpeechRecognizer(configuration);
       } catch (IOException ex) {
           logger.log(Level.SEVERE, null, ex);
       }
       
       // Start recognition process pruning previously cached data.
       // recognizer.startRecognition(true);
       
       //Check if needed resources are available
       startResourcesThread();
       //Start speech recognition thread
       startSpeechRecognition();
   }
   
   //-----------------------------------------------------------------------------------------------
   
   /**
    * Starts the Speech Recognition Thread
    */
   public synchronized void startSpeechRecognition() {
       
       //Check lock
       if (speechRecognizerThreadRunning)
           logger.log(Level.INFO, "Speech Recognition Thread already running...\n");
       else
           //Submit to ExecutorService
           eventsExecutorService.submit(() -> {
               
               //locks
               speechRecognizerThreadRunning = true;
               ignoreSpeechRecognitionResults = false;
               
               //Start Recognition
               recognizer.startRecognition(true);
               
               //Information           
               logger.log(Level.INFO, "You can start to speak...\n");
               
               try {
                   while (speechRecognizerThreadRunning) {
                       /*
                        * This method will return when the end of speech is reached. Note that the end pointer will determine the end of speech.
                        */
                       SpeechResult speechResult = recognizer.getResult();
                       
                       //Check if we ignore the speech recognition results
                       if (!ignoreSpeechRecognitionResults) {
                           
                           //Check the result
                           if (speechResult == null)
                               logger.log(Level.INFO, "I can't understand what you said.\n");
                           else {
                               
                               //Get the hypothesis
                               speechRecognitionResult = speechResult.getHypothesis();
                               
                               //You said?
                               System.out.println("You said: [" + speechRecognitionResult + "]\n");
                               
                               //Call the appropriate method
                               makeDecision(speechRecognitionResult, speechResult.getWords());
                               
                           }
                       } else
                           logger.log(Level.INFO, "Ingoring Speech Recognition Results...");
                       
                   }
               } catch (Exception ex) {
                   logger.log(Level.WARNING, null, ex);
                   speechRecognizerThreadRunning = false;
               }
               
               logger.log(Level.INFO, "SpeechThread has exited...");
               
           });
   }
   
   /**
    * Stops ignoring the results of SpeechRecognition
    */
   public synchronized void stopIgnoreSpeechRecognitionResults() {
       
       //Stop ignoring speech recognition results
       ignoreSpeechRecognitionResults = false;
   }
   
   /**
    * Ignores the results of SpeechRecognition
    */
   public synchronized void ignoreSpeechRecognitionResults() {
       
       //Instead of stopping the speech recognition we are ignoring it's results
       ignoreSpeechRecognitionResults = true;
       
   }
   
   //-----------------------------------------------------------------------------------------------
   
   /**
    * Starting a Thread that checks if the resources needed to the SpeechRecognition library are available
    */
   public void startResourcesThread() {
       
       //Check lock
       if (resourcesThreadRunning)
           logger.log(Level.INFO, "Resources Thread already running...\n");
       else
           //Submit to ExecutorService
           eventsExecutorService.submit(() -> {
               try {
                   
                   //Lock
                   resourcesThreadRunning = true;
                   
                   // Detect if the microphone is available
                   while (true) {
                       
                       //Is the Microphone Available
                       if (!AudioSystem.isLineSupported(Port.Info.MICROPHONE))
                           logger.log(Level.INFO, "Microphone is not available.\n");
                       
                       // Sleep some period
                       Thread.sleep(350);
                   }
                   
               } catch (InterruptedException ex) {
                   logger.log(Level.WARNING, null, ex);
                   resourcesThreadRunning = false;
               }
           });
   }
   
   /**
    * Takes a decision based on the given result
    *
    * @param speechWords
    */
   public void makeDecision(String speech , List<WordResult> speechWords) {
       
       System.out.println(speech);
       
   }
   
   public boolean getIgnoreSpeechRecognitionResults() {
       return ignoreSpeechRecognitionResults;
   }
   
   public boolean getSpeechRecognizerThreadRunning() {
       return speechRecognizerThreadRunning;
   }
   
   /**
    * Main Method
    *
    * @param args
    */
   public static void main(String[] args) {
       new SpeechRecognizerMain();
   }
}
Passt das? Wenn nein, sag Bescheid.
 

Ähnliche Java Themen

Neue Themen


Oben