本文整理汇总了Java中edu.cmu.sphinx.result.Result类的典型用法代码示例。如果您正苦于以下问题:Java Result类的具体用法?Java Result怎么用?Java Result使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Result类属于edu.cmu.sphinx.result包,在下文中一共展示了Result类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
/**
* Performs a single recognition
*/
public void run() {
if (recognizer != null && microphone != null) {
automaton.updateStatus(_LISTENING_FOR_COMMAND);
microphone.clear();
microphone.startRecording();
Result result = recognizer.recognize();
microphone.stopRecording();
if (result != null) {
String resultText = result.getBestFinalResultNoFiller();
String phrase = resultText.trim().toUpperCase();
fireListeners(phrase);
}
}
}
示例2: newResult
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
@Override
public void newResult(final Result result) {
if (result == null)
return;
int max = -1;
for (final String word : result.toString().split(" ")) {
for (int i = start; i < start + step && i < tokens.size(); i++) {
if (tokens.get(i).equals(word)) {
max = i;
break;
}
}
}
if (max > 0) {
start = max;
newGrammar();
createGrammar();
postProcessGrammar();
}
}
示例3: decode
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
public void decode() {
try {
utteranceId = 0;
DataOutputStream ctm = new DataOutputStream(new FileOutputStream(ctmFile));
recognizer.allocate();
for (Iterator<CTLUtterance> i = new CTLIterator(); i.hasNext();) {
CTLUtterance utt = i.next();
setInputStream(utt);
Result result = recognizer.recognize();
System.out.println("Utterance " + utteranceId + ": " + utt.getName());
System.out.println("Reference: " + utt.getRef());
System.out.println("Result : " + result);
logger.info("Utterance " + utteranceId + ": " + utt.getName());
logger.info("Result : " + result);
handleResult(ctm, utt, result);
utteranceId++;
}
recognizer.deallocate();
} catch (IOException io) {
logger.severe("I/O error during decoding: " + io.getMessage());
}
logger.info("BatchCTLDecoder: " + utteranceId + " utterances decoded");
}
示例4: process
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
/**
* Ranks the given set of tokens
*
* @param result the result to process
*/
private void process(Result result) {
if (result.isFinal()) {
collectStatistics(result);
} else {
List<Token> tokenList = result.getActiveTokens().getTokens();
if (!tokenList.isEmpty()) {
Collections.sort(tokenList, Scoreable.COMPARATOR);
Token bestToken = tokenList.get(0);
int rank = 0;
for (Token token : tokenList) {
float scoreDiff = bestToken.getScore() -
token.getScore();
assert scoreDiff >= 0;
token.getTokenProps().put(TOKEN_RANK, new TokenRank(rank++, scoreDiff));
assert tokenIsRanked(token);
}
}
}
}
示例5: newResult
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
@Override
public void newResult(Result result) {
String ref = result.getReferenceText();
if (result.isFinal() && ref != null) {
Lattice lattice = new Lattice(result);
LatticeOptimizer optimizer = new LatticeOptimizer(lattice);
optimizer.optimize();
lattice.computeNodePosteriors(languageModelWeight);
SausageMaker sausageMaker = new SausageMaker(lattice);
Sausage sausage = sausageMaker.makeSausage();
sausage.removeFillers();
getAligner().alignSausage(ref, sausage);
showFullPath(result);
showDetails(result.toString());
}
}
示例6: newResult
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
@Override
public void newResult(Result result) {
String ref = result.getReferenceText();
if (result.isFinal() && ref != null) {
numUtterances++;
String hyp = result.getBestResultNoFiller();
if (ref.equals("<unk>")) {
numOutOfGrammarUtterances++;
if (hyp.equals("<unk>")) {
numCorrectOutOfGrammarUtterances++;
} else {
numFalseInGrammarUtterances++;
}
} else {
if (hyp.equals("<unk>")) {
numFalseOutOfGrammarUtterances++;
} else {
numCorrectInGrammarUtterances++;
}
}
printStats();
}
}
示例7: run
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
@Override
public void run()
{
logger.info("Starting speech recognition");
startMicrophone();
while (!threadComponent.isStopped())
{
try
{
Result result = recognizer.recognize();
if (result != null)
{
processResult(result);
}
} catch (RuntimeException e)
{
// This happens when the recognizer is deallocated (which only happens when the stop() method was called)
}
}
logger.info("Ending speech recognition");
}
示例8: getTagString
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
/**
* Gets a space delimited string of tags representing the result
*
* @param result
* the recognition result
* @return the tag string
* @throws GrammarException
* if there is an error while parsing the result
*/
String getTagString(Result result) throws GrammarException {
RuleParse ruleParse = getRuleParse(result);
if (ruleParse == null)
return null;
String[] tags = ruleParse.getTags();
if (tags == null)
return "";
StringBuilder sb = new StringBuilder();
for (String tag : tags)
sb.append(tag).append(' ');
return sb.toString().trim();
}
示例9: run
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
public void run()
{
Utils.log("debug", "Recognition thread starting");
while (true == mRecognitionThreadEnabled)
{
if (!mMicrophone.isRecording())
{
Utils.log("warning", "Recognition thread is running, but "
+ "the microphone is disabled.");
}
else
{
Result result = null;
try
{
result = mRecognizer.recognize();
} catch (Throwable t) {}
if (result != null)
{
String s = result.getBestFinalResultNoFiller();
// Only save non-empty strings.
if (!s.equals(""))
{
Utils.log("debug", "Finished recognizing");
mRecognizedStringQueue.addLast(s);
}
}
}
}
Utils.log("debug", "Recognition thread finished");
}
示例10: recognize
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
/**
* Performs recognition for the given number of input frames, or until a 'final' result is generated. This method
* should only be called when the recognizer is in the <code>allocated</code> state.
*
* @param referenceText what was actually spoken
* @return a recognition result
* @throws IllegalStateException if the recognizer is not in the <code>ALLOCATED</code> state
*/
public Result recognize(String referenceText) throws IllegalStateException {
Result result = null;
checkState(State.READY);
try {
setState(State.RECOGNIZING);
result = decoder.decode(referenceText);
} finally {
setState(State.READY);
}
return result;
}
示例11: decode
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
/**
* Decodes the batch of audio files
*/
public void decode(String batchFile) throws IOException {
BatchItem batchItem;
int count = 0;
try {
recognizer.allocate();
setBatchFile(batchFile);
batchManager.start();
logger.info("BatchDecoder: decoding files in "
+ batchManager.getFilename());
while (count < utteranceId &&
(batchItem = batchManager.getNextItem()) != null) {
setInputStream(batchItem.getFilename());
Result result = recognizer.recognize(batchItem.getTranscript());
logger.info("File : " + batchItem.getFilename());
logger.info("Result: " + result);
count++;
}
batchManager.stop();
recognizer.deallocate();
} catch (IOException io) {
logger.severe("I/O error during decoding: " + io.getMessage());
throw io;
}
logger.info("BatchDecoder: " + count + " files decoded");
}
示例12: recognize
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
public Result recognize() throws IOException {
Result result = null;
BatchItem batchItem;
if (count < utteranceId &&
(batchItem = batchManager.getNextItem()) != null) {
setInputStream(batchItem.getFilename());
result = recognizer.recognize(batchItem.getTranscript());
logger.info("File : " + batchItem.getFilename());
logger.info("Result: " + result);
count++;
}
logger.info("BatchDecoder: " + count + " files decoded");
return result;
}
示例13: newResult
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
@Override
public void newResult(Result result) {
if (result.isFinal()) {
processingTime = (getTime() - startTime) / 1000.0f;
totalAudioTime += audioTime;
totalProcessingTime += processingTime;
if (showDetails) {
showAudioUsage();
}
}
}
示例14: newResult
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
@Override
public void newResult(Result result) {
if (enabled) {
process(result);
if (result.isFinal() && showDetails) {
showLatestResult();
}
}
}
示例15: collectAbsoluteBeamStatistics
import edu.cmu.sphinx.result.Result; //导入依赖的package包/类
/**
* Collects the absolute beam statistics
*
* @param result the result of interest
*/
private void collectAbsoluteBeamStatistics(Result result) {
Token token = result.getBestToken();
int count = 0;
int sumBeam = 0;
maxAbsoluteBeam = 0;
while (token != null) {
if (token.isEmitting()) {
TokenRank rank = (TokenRank) token.getTokenProps().get(TOKEN_RANK);
if (rank != null) {
if (rank.getAbsoluteRank() > maxAbsoluteBeam) {
maxAbsoluteBeam = rank.getAbsoluteRank();
}
sumBeam += rank.getAbsoluteRank();
count++;
} else {
if (token.getFrameNumber() > 0) {
System.out.println("Null rank! for " + token);
}
}
}
token = token.getPredecessor();
}
if (count > 0) {
avgAbsoluteBeam = sumBeam / count;
if (maxAbsoluteBeam > totMaxAbsoluteBeam) {
totMaxAbsoluteBeam = maxAbsoluteBeam;
}
sumAbsoluteBeam += avgAbsoluteBeam;
}
}