I want to incorporate a Python file using speech recognition in the backend of a React project.
Here I have the piece of Python code using Speech Recognition:
import speech_recognition as sr
r = sr.Recognizer()
def recognize(audio):
try:
return r.recognize_google(audio)
except LookupError:
print("There was an error")
return ''
def transciption():
with sr.Microphone() as source:
print('speak now')
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
return recognize(audio)
I tried to import the file in my react component like this:
import SpeechRec from 'SpeechRec.py';
Here I tried to link my button to the function in my Python file:
<button onClick={SpeechRec.transcription()}>SR</button>
I received the message that it failed to compile along with the following:
./src/components/container/Container.jsx
Module not found: Can't resolve 'SpeechRec.py' in '......\collaborative-whiteboard-SR\ui\src\components\container'
What can I do to make this work?