javascript - 无法使用 react-native-voice 包
问题描述
我正在尝试使用 react-native-voice 包。在我按下按钮的项目中,我正在调用 Voice.start('en-US') 方法。但它显示以下错误,
Possible Unhandled Promise Rejection(id: 0):
TypeError: null is not an object (evaluating 'Voice.startSpeech')
我已经自动和手动链接了包。但它没有奏效
旁注:我使用 expo 从 expo 管理的工作流程中弹出项目
解决方案
正如您在文档中看到的,它们在构造函数中有 init Voice
尝试这个
constructor(props) {
Voice.onSpeechStart = this.onSpeechStartHandler.bind(this);
Voice.onSpeechEnd = this.onSpeechEndHandler.bind(this);
Voice.onSpeechResults = this.onSpeechResultsHandler.bind(this);
}
onSpeechStartHandler = () => {}
onSpeechEndHandler = () => {}
onSpeechResultsHandler = () => {}
onStartButtonPress(e){
Voice.start('en-US');
}
还要检查权限