Ich habe viele Lösungen ausprobiert, aber keine funktioniert wirklich, die einzige das scheint nahe zu kommen, ist @react-native-voice/voice.
Ich installiere @react-native-voice/voice:
npm i @react-native-voice/ Stimme
mein Code:
Code: Select all
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;
Ich starte meine Anwendung und wenn ich auf die Schaltfläche „Registrieren“ drücke, wird dieser Fehler zurückgegeben :
[Unhandled Promise Rejection: TypeError: null is not an object (evaluating 'Voice.startSpeech')]
Ich starte dann expo doctor it gibt zurück:
Erwartetes Paket @expo/config-plugins@^5.0.2
Ungültig gefunden:
@expo/config-plugins @2.0.4
Ich habe das noch nie gesehen und weiß es auch nicht. Hat schon jemand ein ähnliches Problem gelöst?
alle Versionen von @react-native-voice/voice have @expo/config-plugins@2.0.4