![](/img/trans.png)
[英]EPERM: operation not permitted, chmod @react-native-community iOS
[英]Speech to text with react-native-community/voice is not giving proper result in iOS
我正在使用 react-native-community/voice 将语音转为文本。 对于 android,它工作正常,但对于 iOS,它没有给出正确的结果。 我也尝试使用钩子,但得到了相同的结果。
我使用了 5 秒的计时器来处理销毁语音方法(它也不适用于我的 iOS 项目)。
我在用着
react-native-cli: 2.0.1
react-native: 0.59.8
有人可以在这方面帮助我吗?
提前致谢。 这是我的代码:-
state = {
recognized: '',
pitch: '',
error: '',
end: '',
started: '',
results: [],
partialResults: [],
dataSource: [],
isNet:false,
isLoading : false,
};
constructor(props: Props) {
super(props);
Voice.onSpeechStart = this.onSpeechStart;
Voice.onSpeechRecognized = this.onSpeechRecognized;
Voice.onSpeechEnd = this.onSpeechEnd;
Voice.onSpeechError = this.onSpeechError;
Voice.onSpeechResults = this.onSpeechResults;
Voice.onSpeechPartialResults = this.onSpeechPartialResults;
Voice.onSpeechVolumeChanged = this.onSpeechVolumeChanged;
}
componentWillUnmount() {
Voice.destroy().then(Voice.removeAllListeners);
}
onSpeechStart = (e: any) => {
this.setState({
started: '',
});
};
onSpeechRecognized = (e: SpeechRecognizedEvent) => {
this.setState({
recognized: '',
});
};
onSpeechEnd = (e: any) => {
this.setState({
end: '',
});
};
onSpeechError = (e: SpeechErrorEvent) => {
this.setState({
error: JSON.stringify(e.error),
});
};
onSpeechResults = (e: SpeechResultsEvent) => {
this.setState({
results: e.value,
});
// My Own Method this.getSearchResult(e.value[0])
};
onSpeechPartialResults = (e: SpeechResultsEvent) => {
this.setState({
partialResults: e.value,
});
};
onSpeechVolumeChanged = (e: any) => {
this.setState({
pitch: e.value,
});
};
_startRecognizing = async () => {
this.setState({
recognized: '',
pitch: '',
error: '',
started: '',
results: [],
partialResults: [],
end: 'Listning ...',
});
try {
Platform.OS === 'ios'
{
setTimeout(() => {
this._destroyRecognizer()
}, 5000)
}
await Voice.start('en-US');
} catch (e) {
console.error(e);
}
};
_stopRecognizing = async () => {
try {
await Voice.stop();
} catch (e) {
console.error(e);
}
};
_cancelRecognizing = async () => {
try {
await Voice.cancel();
} catch (e) {
console.error(e);
}
};
_destroyRecognizer = async () => {
try {
await Voice.destroy();
} catch (e) {
console.error(e);
}
this.setState({
recognized: '',
pitch: '',
error: '',
started: '',
results: [],
partialResults: [],
end: '',
});
};
任何帮助将不胜感激
我有类似的问题,我只是用这个解决它
// for ios
onSpeechEnd(e) {
this.setState({
end: true
});
if (Platform.OS === 'ios') {
// use this.state.results here
}
}
// for android
onSpeechResults(e) {
this.setState({
results: e.value
});
if (Platform.OS === 'android') {
use this.state.results here
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.