如何从 reactjs 中的语音命令模型结果中识别标签?

how to identify label from result of speech command model in reactjs?

我正在使用 tensorflow-models/speech-commands 模型通过 ReactJs 应用程序检测语音命令,我能够在应用程序中初始化识别器并获得结果,但不确定如何根据结果识别标签模型。

  componentDidMount () {
    fetch("http://localhost:3001/ITEMS").then(resp => resp.json())
    .then(result => this.setState({
      products: result
    },() => {
       this.call()
    }));

  }

  async call() {

const recognizer = speechCommands.create('BROWSER_FFT')
await recognizer.ensureModelLoaded();
console.log("CALL",recognizer)
recognizer.listen(result => {
  // - result.scores contains the probability scores that correspond to
  //   recognizer.wordLabels().
  // - result.spectrogram contains the spectrogram of the recognized word.
  console.log("Result",result)
}, {
  includeSpectrogram: true,
  probabilityThreshold: 0.75
});

// Stop the recognition in 10 seconds.
setTimeout(() =>{
  console.log("Stopped listening")
  recognizer.stopListening()}, 10000);
  }

如您所见,我在 did mount 上初始化识别器并从我的语音命令中获得以下结果,但不确定如何准确识别从结果中检测到的标签模型。

我想我应该参考分数 属性,但不确定哪一个是预测的。请帮忙。

.scores包含给定语音是某个词的概率。

Which one exactly is the predicted

这取决于意图。优先级最高的词或topk是否被认为是预测值?

无论如何,索引都需要在.score中检索并用于检索.words

中的相应单词

检索概率最高的单词

recognizer.wordsLabels()[result.scores.indexOf(Math.max(...result.scores))];

检索topk词

result.score.sort((a, b) => b-a).slice(0,k).map(s => result.scores.indexOf(s)).map(i => recognizer.wordsLabels()[i])