I am trying to transcribe the audio to text using the pydub and speech recognition library. My code is successfully converting the '.mp3' file to '.wav' but while conversion/transcribing using recognize_google library I am getting this error
"ERROR: [WinError 6] The handle is invalid. "
The twist is when i am running this script directly its running fine but when my API created in Flask calls this script its failing.
My Flask application is HOSTED on IIS Server.
with recaptcha_audio as source:
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.record(source)
sleep(2)
try:
transcribed = recognizer.recognize_google(audio, language="en-US")
except Exception as e:
log.error(f"-----------------------ERROR: {str(e)}")
return f"-----------------------ERROR: {str(e)}"
I tried changing the audio files and also manipulating the AudioSegment.py subprocess implementation with "stdin=subprocess.DEVNULL".
No success yet. Please suggest a way out for my Flask Application with IIS, to implement this script.
After spending several days investigating, I've identified a solution for
recognizer.recognize_googleor Speech-to-Text (STT) issues when working with virtual environments and IIS deployment.The key to resolving the issue is ensuring that you create and use the
virtual environmentinstead use Python fromc:/python.Here's a concise guide:
Create Virtual Environment:
Use the following command to create a virtual environment named 'env':
python -m venv envActivate Virtual Environment:
.\env\Scripts\activateDependency Installation
While the virtual environment is active, install the required pip libraries for your project