Я пробовал много решений, но ни одно из них не работает, только одно похоже, что это @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, который возвращает:
Ожидаемый пакет @expo/config-plugins@^5.0.2
Обнаружено неверно:
@expo/[email protected]
Я никогда такого не видел и не знаю, кто-нибудь уже решил подобную проблему?
во всех версиях @react-native-voice/voice есть @expo/[email protected]
Подробнее здесь: https://stackoverflow.com/questions/748 ... fig-plugin