I am executing .py file in Java using Jython 2.7.2 and getting error as org.python.core.PyException: ImportError: No module named speech_recognition. Can anyone please help resolving the issue.
Attached the code snippet of my java and .py files and error message.
import java.io.IOException;
import javax.script.ScriptException;
import org.apache.commons.exec.ExecuteException;
import org.python.util.PythonInterpreter;
import org.testng.annotations.Test;
public class pythonReader {
@Test
public void record_audio_while_doing_voice_over()
throws InterruptedException, ScriptException, ExecuteException, IOException {
PythonInterpreter python = new PythonInterpreter();
python.execfile("C:\\SpeechtoText\\audio_transcriber.py");
}
}
Python Code : (File Name :audio_transcriber.py)
import speech_recognition as sr
filename = "C:\\SpeechToText\\16-122828-0002.wav"
# initialize the recognizer
r = sr.Recognizer()
with sr.AudioFile(filename) as source:
# listen for the data (load audio to memory)
audio_data = r.record(source)
try:
# recognize (convert from speech to text)
text = r.recognize_google(audio_data)
print(text)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Google Speech Recognition error; {0}".format(e))
print("Transaction complete")
Error Message
org.python.core.PyException: ImportError: No module named speech_recognition
at appium.test.pythonReader.record_audio_while_doing_voice_over(pythonReader.java:18)