• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java StreamSpeechRecognizer类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中edu.cmu.sphinx.api.StreamSpeechRecognizer的典型用法代码示例。如果您正苦于以下问题:Java StreamSpeechRecognizer类的具体用法?Java StreamSpeechRecognizer怎么用?Java StreamSpeechRecognizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

StreamSpeechRecognizer类属于edu.cmu.sphinx.api包,在下文中一共展示了StreamSpeechRecognizer类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: transcribe

点赞 3

import edu.cmu.sphinx.api.StreamSpeechRecognizer; //导入依赖的package包/类
/**
 * Tries to predict the speech in a given audio fragment
 * @param audioStream the audio stream on which speech prediction is desired
 * @return the hypotheses of the speech in the given audio fragment
 * as a list of words
 * @throws IOException when the config does not point to correct
 * files needed for the transcription
 */
public ArrayList<WordResult> transcribe(InputStream audioStream)
        throws IOException
{
    StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(config);
    recognizer.startRecognition(audioStream);

    ArrayList<WordResult> utteredWords = new ArrayList<>();
    SpeechResult result;
    while ((result = recognizer.getResult()) != null)
    {
        utteredWords.addAll(result.getWords());
    }
    recognizer.stopRecognition();

    return utteredWords;
}
 

开发者ID:jitsi,
项目名称:Sphinx4-HTTP-server,
代码行数:25,
代码来源:AudioTranscriber.java

示例2: transcribeSynchronous

点赞 2

import edu.cmu.sphinx.api.StreamSpeechRecognizer; //导入依赖的package包/类
/**
 * Tries the predict the speech in a given audio fragment. It
 * will offer the result of every predicted word to a SynchronousQueue,
 * to be processed immediately
 * @param audioStream the audio fragment to transcribe
 * @param queue the queue to offer every WordResult to
 * @throws IOException when the config does not point to correct
 * files needed for the transcription
 */
public void transcribeSynchronous(InputStream audioStream,
                                  SynchronousQueue<WordResult> queue)
    throws IOException
{
    StreamSpeechRecognizer recognizer = new StreamSpeechRecognizer(config);
    recognizer.startRecognition(audioStream);

    logger.trace("Started chunked transcription");
    SpeechResult result;
    while( (result = recognizer.getResult()) != null)
    {
        logger.trace("got a word result of length {}",
                result.getWords().size());

        for(WordResult word : result.getWords())
        {
            logger.trace("offering {}", word.toString());
            try
            {
                queue.put(word);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
    recognizer.stopRecognition();
}
 

开发者ID:jitsi,
项目名称:Sphinx4-HTTP-server,
代码行数:39,
代码来源:AudioTranscriber.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)