Я пробовал много решений, но ни одно из них не работает, только одно похоже, что это @react-native-voice/voice.
Я устанавливаю @react-native-voice/voice:
npm i @react-native-voice/voice
мой код:
Код: Выделить всё
import { View, StyleSheet, Image, Text, Button } from "react-native";
import { NativeBaseProvider } from "native-base";
import { useState, useEffect } from "react";
import { StatusBar } from "expo-status-bar";
import Voice from "@react-native-voice/voice";
const App = () => {
let [started, setStarted] = useState(false);
let [results, setResults] = useState([]);
useEffect(() => {
Voice.onSpeechError = onSpeechError;
Voice.onSpeechResults = onSpeechResults;
return () => {
Voice.destroy().then(Voice.removeAllListeners);
};
}, []);
const startSpeechToText = async () => {
await Voice.start("en-NZ");
setStarted(true);
};
const stopSpeechToText = async () => {
await Voice.stop();
setStarted(false);
};
const onSpeechResults = (result) => {
setResults(result.value);
};
const onSpeechError = (error) => {
console.log(error);
};
return (
{!started ? (
) : undefined}
{started ? (
) : undefined}
{results.map((result, index) => (
{result}
))}
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
export default App;
Я запускаю свое приложение, и когда я нажимаю кнопку регистрации, оно возвращает эту ошибку :
[Отклонение необработанного обещания: TypeError: null не является объектом (оценка «Voice.startSpeech»)]
Затем я запускаю Expo Doctor It возвращает:
Ожидаемый пакет @expo/config-plugins@^5.0.2
Обнаружен недействительный:
@expo/config-plugins @2.0.4
Я никогда такого не видел и не знаю, кто-нибудь уже решил подобную проблему?
все версии из @react-native-voice/voice есть @expo/[email protected]
Подробнее здесь: https://stackoverflow.com/questions/748 ... fig-plugin