Home > Net >  How to add in react-native script in python?
How to add in react-native script in python?

Time:11-26

Also i have got a new project, where nedded make a voice recognition (speech-to-text) , but i have't find a worked library in react-native. How can i connect scripts in python to react native project?

I only find how to make autorizathion in python, but by me it was maked in JS

CodePudding user response:

If your python app is going to be running on a separate machine to the react-native app (so it is running on a server). I would write a small server implementation ontop of the python app using something like flask which sends back a JSON then you can follow the tutorial here: https://reactnative.dev/docs/network Which talks about making http requests and parsing the response. So in a REST api manner

If you are talking about client side python running in tandem with react-native on a mobile device. That would be pretty difficult to accomplish as in production the react compile is compiling into native code by handling JavaScript/JSX and not python. Someone may have an answer on this last part

CodePudding user response:

You can embed Python into React-Native, but it's really tricky. I suggest you go with the other answer using Server-Client Architecture.

However if you really have no other choice.

  1. Then you can create a Turbo Module in C
  2. Use a python interpreter in C to call and use python libraries/scripts use this embedding tutorial
  3. Finally call this native module in your react-native application to make use of the python scripts.
  • Related