IT. Expert System.

Android Reference

Recognizer


android.speech.srec

Class Recognizer



  • public final class Recognizer
    extends Object
    Simple, synchronous speech recognizer, using the Nuance SREC package. Usages proceeds as follows:
    • Create a Recognizer.
    • Create a Recognizer.Grammar.
    • Setup the Recognizer.Grammar.
    • Reset the Recognizer.Grammar slots, if needed.
    • Fill the Recognizer.Grammar slots, if needed.
    • Compile the Recognizer.Grammar, if needed.
    • Save the filled Recognizer.Grammar, if needed.
    • Start the Recognizer.
    • Loop over advance and putAudio until recognition complete.
    • Fetch and process results, or notify of failure.
    • Stop the Recognizer.
    • Destroy the Recognizer.

    Below is example code

     
     // create and start audio input
     InputStream audio = new MicrophoneInputStream(11025, 11025*5);
     // create a Recognizer
     String cdir = Recognizer.getConfigDir(null);
     Recognizer recognizer = new Recognizer(cdir + "/baseline11k.par");
     // create and load a Grammar
     Recognizer.Grammar grammar = recognizer.new Grammar(cdir + "/grammars/VoiceDialer.g2g");
     // setup the Grammar to work with the Recognizer
     grammar.setupRecognizer();
     // fill the Grammar slots with names and save, if required
     grammar.resetAllSlots();
     for (String name : names) grammar.addWordToSlot("@Names", name, null, 1, "V=1");
     grammar.compile();
     grammar.save(".../foo.g2g");
     // start the Recognizer
     recognizer.start();
     // loop over Recognizer events
     while (true) {
         switch (recognizer.advance()) {
         case Recognizer.EVENT_INCOMPLETE:
         case Recognizer.EVENT_STARTED:
         case Recognizer.EVENT_START_OF_VOICING:
         case Recognizer.EVENT_END_OF_VOICING:
             // let the Recognizer continue to run
             continue;
         case Recognizer.EVENT_RECOGNITION_RESULT:
             // success, so fetch results here!
             for (int i = 0; i < recognizer.getresultcount(); i++) {
                 string result = recognizer.getresult(i, recognizer.key_literal);
             }
             break;
         case recognizer.event_need_more_audio:
             // put more audio in the recognizer
             recognizer.putaudio(audio);
             continue;
         default:
             notifyfailure();
             break;
         }
         break;
     }
     // stop the recognizer
     recognizer.stop();
     // destroy the recognizer
     recognizer.destroy();
     // stop the audio device
     audio.close();
     
     
    • Field Detail

      • KEY_CONFIDENCE

        public static final String KEY_CONFIDENCE
        Result key corresponding to confidence score.
        See Also:
        Constant Field Values
      • EVENT_NO_MATCH

        public static final int EVENT_NO_MATCH
        Recognizer could not find a match for the utterance.
        See Also:
        Constant Field Values
      • EVENT_INCOMPLETE

        public static final int EVENT_INCOMPLETE
        Recognizer processed one frame of audio.
        See Also:
        Constant Field Values
      • EVENT_STARTED

        public static final int EVENT_STARTED
        Recognizer has just been started.
        See Also:
        Constant Field Values
      • EVENT_STOPPED

        public static final int EVENT_STOPPED
        Recognizer is stopped.
        See Also:
        Constant Field Values
      • EVENT_START_OF_VOICING

        public static final int EVENT_START_OF_VOICING
        Beginning of speech detected.
        See Also:
        Constant Field Values
      • EVENT_END_OF_VOICING

        public static final int EVENT_END_OF_VOICING
        End of speech detected.
        See Also:
        Constant Field Values
      • EVENT_SPOKE_TOO_SOON

        public static final int EVENT_SPOKE_TOO_SOON
        Beginning of utterance occured too soon.
        See Also:
        Constant Field Values
      • EVENT_RECOGNITION_RESULT

        public static final int EVENT_RECOGNITION_RESULT
        Recognition match detected.
        See Also:
        Constant Field Values
      • EVENT_START_OF_UTTERANCE_TIMEOUT

        public static final int EVENT_START_OF_UTTERANCE_TIMEOUT
        Timeout occured before beginning of utterance.
        See Also:
        Constant Field Values
      • EVENT_RECOGNITION_TIMEOUT

        public static final int EVENT_RECOGNITION_TIMEOUT
        Timeout occured before speech recognition could complete.
        See Also:
        Constant Field Values
      • EVENT_NEED_MORE_AUDIO

        public static final int EVENT_NEED_MORE_AUDIO
        Not enough samples to process one frame.
        See Also:
        Constant Field Values
      • EVENT_MAX_SPEECH

        public static final int EVENT_MAX_SPEECH
        More audio encountered than is allowed by 'swirec_max_speech_duration'.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Recognizer

        public Recognizer(String configFile)
                   throws IOException
        Create an instance of a SREC speech recognizer.
        Parameters:
        configFile - pathname of the baseline*.par configuration file, which in turn contains references to dictionaries, speech models, and other data needed to configure and operate the recognizer. A separate config file is needed for each audio sample rate. Two files, baseline11k.par and baseline8k.par, which correspond to 11025 and 8000 hz, are present in the directory indicated by getConfigDir(java.util.Locale).
        Throws:
        IOException
    • Method Detail

      • getConfigDir

        public static String getConfigDir(Locale locale)
        Get the pathname of the SREC configuration directory corresponding to the language indicated by the Locale. This directory contains dictionaries, speech models, configuration files, and other data needed by the Recognizer.
        Parameters:
        locale - Locale corresponding to the desired language, or null for default, currently Locale.US.
        Returns:
        Pathname of the configuration directory.
      • start

        public void start()
        Start recognition
      • advance

        public int advance()
        Process some audio and return the current status.
        Returns:
        recognition event, one of:
        • EVENT_INVALID
        • EVENT_NO_MATCH
        • EVENT_INCOMPLETE
        • EVENT_STARTED
        • EVENT_STOPPED
        • EVENT_START_OF_VOICING
        • EVENT_END_OF_VOICING
        • EVENT_SPOKE_TOO_SOON
        • EVENT_RECOGNITION_RESULT
        • EVENT_START_OF_UTTERANCE_TIMEOUT
        • EVENT_RECOGNITION_TIMEOUT
        • EVENT_NEED_MORE_AUDIO
        • EVENT_MAX_SPEECH
      • putAudio

        public int putAudio(byte[] buf,
                   int offset,
                   int length,
                   boolean isLast)
        Put audio samples into the Recognizer.
        Parameters:
        buf - holds the audio samples.
        offset - offset of the first sample.
        length - number of bytes containing samples.
        isLast - indicates no more audio data, normally false.
        Returns:
        number of bytes accepted.
      • putAudio

        public void putAudio(InputStream audio)
                      throws IOException
        Read audio samples from an InputStream and put them in the Recognizer.
        Parameters:
        audio - InputStream containing PCM audio samples.
        Throws:
        IOException
      • getResultCount

        public int getResultCount()
        Get the number of recognition results. Must be called after EVENT_RECOGNITION_RESULT is returned by advance, but before stop.
        Returns:
        number of results in nbest list.
      • getResultKeys

        public String[] getResultKeys(int index)
        Get a set of keys for the result. Must be called after EVENT_RECOGNITION_RESULT is returned by advance, but before stop.
        Parameters:
        index - index of result.
        Returns:
        array of keys.
      • getResult

        public String getResult(int index,
                       String key)
        Get a result value. Must be called after EVENT_RECOGNITION_RESULT is returned by advance, but before stop.
        Parameters:
        index - index of the result.
        key - key of the result. This is typically one of KEY_CONFIDENCE, KEY_LITERAL, or KEY_MEANING, but the user can also define their own keys in a grxml file, or in the tag slot of Grammar.addWordToSlot.
        Returns:
        the result.
      • stop

        public void stop()
        Stop the Recognizer.
      • resetAcousticState

        public void resetAcousticState()
        Reset the acoustic state vectorto it's default value.
      • setAcousticState

        public void setAcousticState(String state)
        Set the acoustic state vector.
        Parameters:
        state - String containing the acoustic state vector.
      • getAcousticState

        public String getAcousticState()
        Get the acoustic state vector.
        Returns:
        String containing the acoustic state vector.
      • destroy

        public void destroy()
        Clean up resources.
      • eventToString

        public static String eventToString(int event)
        Produce a displayable string from an advance event.
        Parameters:
        event -
        Returns:
        String representing the event.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 3438 / . Delta: 0.04758 с