在RN中处理文本到语音的应用程序,该应用程序检查Firebase的正确答案。唯一的问题是,我不知道如何使此本机语音(https://www.npmjs.com/package/react-native-voice)识别年份和日期。由于网络上缺乏可用资源,因此似乎找不到答案。
我正在为您提供我使用的准系统基本应用程序。 您可以复制并检查它的工作方式。是否可以识别F.X. “ 1960”或“ 3月30日”。
// App.js
import React from 'react';
import {
StyleSheet,
Text,
View,
Button,
AppRegistry,
} from 'react-native';
import Voice from 'react-native-voice';
export default class VoiceNative extends React.Component {
constructor(props) {
super(props);
this.state = {
recognized: '',
started: '',
results: [],
};
Voice.onSpeechStart = this.onSpeechStart.bind(this);
Voice.onSpeechRecognized = this.onSpeechRecognized.bind(this);
Voice.onSpeechResults = this.onSpeechResults.bind(this);
}
componentWillUnmount() {
Voice.destroy().then(Voice.removeAllListeners);
}
onSpeechStart(e) {
this.setState({
started: '√',
});
};
onSpeechRecognized(e) {
this.setState({
recognized: '√',
});
};
onSpeechResults(e) {
this.setState({
results: e.value,
});
}
async _startRecognition(e) {
this.setState({
recognized: '',
started: '',
results: [],
});
try {
await Voice.start('en-US');
} catch (e) {
console.error(e);
}
}
render () {
return (
<View>
<Text>Transcript</Text>
{this.state.results.map((result, index) => <Text> {result}</Text>
)}
<Button onPress={this._startRecognition.bind(this)}
title="Start"></Button>
</View>
);
}
};
AppRegistry.registerComponent('VoiceNative', () => VoiceNative);