首页 > 解决方案 > 是否可以在本机反应中收听特定单词?

问题描述

我正在使用 React native 构建一个 android 应用程序。

https://github.com/react-native-community/voice这个包可以很好地捕捉语音。但我希望设备始终监听并在说出特定单词后触发事件(如“Hello myapp!”)。

我试过 https://github.com/spokestack/react-native-spokestack

但它不起作用。

任何人都可以帮助我吗?

标签: androidreact-nativevoice-recognitionmicrophonevoice

解决方案


import Voice from 'react-native-voice';
import React, {Component} from 'react';
 
class VoiceTest extends Component {
  constructor(props) {
    Voice.onSpeechStart = this.onSpeechStartHandler.bind(this);
    Voice.onSpeechEnd = this.onSpeechEndHandler.bind(this);
    Voice.onSpeechResults = this.onSpeechResultsHandler.bind(this);
  }
  onStartButtonPress(e){
    Voice.start('en-US');
  }
  ...
}

另请查看此链接https://www.npmjs.com/package/react-native-voice它会对您有很大帮助。


推荐阅读