voice icon indicating copy to clipboard operation
voice copied to clipboard

Update VoiceTestFuncComp.tsx

Open Kaue-Romero opened this issue 1 year ago • 1 comments

Typescript was complaining with some types.

Kaue-Romero avatar Mar 26 '24 02:03 Kaue-Romero

The problem is that both SpeechResultsEvent and SpeechResultsEvent types in VoiceModuleType.ts define value as a possible undefined

export type SpeechResultsEvent = {
  value?: string[];
};

export type SpeechResultsEvent = {
  value?: string[];
};

even if looks odd setting an value as array or undefined while it could be just and empty array i think that was intentional because the return of thoose events its an array of the possible recognition not the words, for example if i said:

Hello world

it would output

[Hello Word, Hello, Hello word, Hallo word]

The weird part is that the method doesnt seen to return an "undefined" or nulish value

  @Override
  public void onResults(Bundle results) {
    WritableArray arr = Arguments.createArray();

    ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    if (matches != null) {
      for (String result : matches) {
        arr.pushString(result);
      }
    }
    WritableMap event = Arguments.createMap();
    event.putArray("value", arr);
    sendEvent("onSpeechResults", event);
    Log.d("ASR", "onResults()");
  }

pedrol2b avatar Apr 04 '24 20:04 pedrol2b