jamsch / expo-speech-recognition

Speech Recognition for React Native Expo projects
16 stars 2 forks source link

Empty results when using the Web SpeechRecognition API #3

Closed abddeen closed 1 month ago

abddeen commented 1 month ago

@jamsch I tried the two approaches, hook vs web speech recognition api, and the latter is coming back with empty results.

See this video for details:

https://github.com/user-attachments/assets/c0b2ffb4-65aa-4129-b0a8-63e41d34b2a9

jamsch commented 1 month ago

@abddeen Looks like the results aren't properly serialized when calling Array.from(event.results). I pushed out v0.1.6, see if that works.

abddeen commented 1 month ago

@jamsch Nice, i'm getting results now. But I noticed they are typed as an indexed object as opposed to any array:

image

Compared to hook results:

image

Is that intended?

jamsch commented 1 month ago

@abddeen Yep, that's due to the serialization of the ExpoSpeechRecognitionResultList / ExpoSpeechRecognitionResult / ExpoSpeechRecognitionAlternative classes when you log in to the console. Those classes implement iterables (i.e. you can use it in a "for .. of" loop, and convert it to an array using Array.from()) and helpers (such as .item(index)) so that you can loop over them. The console logs that you got that showed {} meant that there wasn't any visible properties that can be serialized to the console, but you would have still been able to console log event.results[event.resultIndex][0].transcript.

abddeen commented 1 month ago

Ah yepp, that makes sense. It's all working as expected now. I've had to rejig my hook a little but this issue is fixed!