Skip to content

Commit 75471d0

Browse files
committed
Fix errors in speech recognition example code
1 parent c71ded0 commit 75471d0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,16 @@ function App() {
103103
console.log("error code:", event.error, "error messsage:", event.message);
104104
});
105105

106-
const handleStart = () => {
107-
ExpoSpeechRecognitionModule.requestPermissionsAsync().then((result) => {
106+
const handleStart = async () => {
107+
try {
108+
const result =
109+
await ExpoSpeechRecognitionModule.requestPermissionsAsync();
108110
if (!result.granted) {
109111
console.warn("Permissions not granted", result);
110112
return;
111113
}
112114
// Start speech recognition
113-
ExpoSpeechRecognitionModule.start({
115+
await ExpoSpeechRecognitionModule.start({
114116
lang: "en-US",
115117
interimResults: true,
116118
maxAlternatives: 1,
@@ -119,12 +121,14 @@ function App() {
119121
addsPunctuation: false,
120122
contextualStrings: ["Carlsen", "Nepomniachtchi", "Praggnanandhaa"],
121123
});
122-
});
124+
} catch (error) {
125+
console.error("Error starting speech recognition:", error);
126+
}
123127
};
124128

125129
return (
126130
<View>
127-
{recognizing ? (
131+
{!recognizing ? (
128132
<Button title="Start" onPress={handleStart} />
129133
) : (
130134
<Button title="Stop" onPress={ExpoSpeechRecognitionModule.stop} />

0 commit comments

Comments
 (0)