1

I am using both react-native-voice and expo-speech libraries to transcript my voice and to convert a text to a speech. The problem is, in android only, when I start the code runs Voice.onSpeechStarts then it returns false and does not record anything. But in iOS it is working fine. I am also using expo speech to speak out some component immediate after recording voice.

package.json versions:

"react": "18.2.0",
"react-native": "0.71.0",
"@react-native-voice/voice": "^3.2.4",

Note: I have tried with voice versions : 3.1.5, 3.2.4
Android sdk version : 31

Code:

export const Screen = () => {
  const [isRecording, setIsRecording] = useState(false);
  const [userMessage, setUserMessage] = useState('');

  useEffect(() => {
    Voice.onSpeechStart = onSpeechStartHandler;
    Voice.onSpeechEnd = onSpeechEndHandler;
    Voice.onSpeechResults = onSpeechResultsHandler;
    return () => {
      Voice.destroy().then(Voice.removeAllListeners);
    };
  }, []);

  const onSpeechStartHandler = e => {
    console.log('start handler=»', e);
  };

  const onSpeechEndHandler = e => {
    console.log('stop handler', e);
  };
  const onSpeechResultsHandler = e => {
    console.log('speech result handler', e);
    setUserMessage(e.value[0]);
  };

  const startRecording = async () => {
    setIsRecording(true);
    try {
      await Voice.start('en-US');
    } catch (e) {
      console.log('error -> ', e);
    }
  };

  const stopRecording = () => {
    setIsRecording(false);
    try {
      Voice.stop();
      console.log(userMessage);
    } catch (e) {
      console.log('error -> ', e);
    }
  };

  return (
    <View
      style={{
        alignContent: 'center',
        justifyContent: 'center',
        backgroundColor: 'black',
        flex: 1,
      }}>
      <Button
        title={isRecording ? 'Stop Speaking' : 'Start Speaking'}
        onPress={isRecording ? stopRecording : startRecording}
      />
    </View>
  );
};

Error after running the code

When I try to check available speech services

Thanks for your time.

Parzival
  • 13
  • 4

3 Answers3

1

in my case i do this solution: node_modules-> react-native-voice/voice -> android -> open androidManifest and add this block

<queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>

I tested on Android 13 device, try this ✌️

LongLe
  • 11
  • 1
  • I tried adding it but it was not even working for android 11 at that moment. So, I believe this is not a solution. Thanks for your time and effort. – Parzival Apr 13 '23 at 05:19
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 16 '23 at 03:47
0

This version of react native voice/voice is not compatible with the android version that is above 12 as per the open issue referred to in the GitHub, please refer to this https://github.com/react-native-voice/voice/issues/429 either you need to make changes on the native side of the library (android) or try downgrading the version of your android, you might have to wait for the update... I hope it helps you

Rishabh
  • 1
  • 1
  • Dude that issue on GitHub was raised by myself for self awareness about not supporting for android 12 and above. Thanks for your time and efforts. – Parzival Mar 27 '23 at 06:35
0

It was working after I installed some android 13 sdk from android studio and verified react native doctor output.

If it was android 13 sdk issue it would have worked earlier when I tested it with android 11 but it didn't worked at that moment. So, I don't know the exact issue which I solved which made it work on my android 13 and 11 devices. It just started working from a point.

So, anyone who is reading this, I would suggest you to at least verify the react-native doctor output, it may solve your issue.

I will post anything if I am able to find out what made it worked, in the comments and here : https://github.com/react-native-voice/voice/issues/429

Thanks.

Parzival
  • 13
  • 4
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 18 '23 at 21:53