Azure Cognitive Services and Python Executable - python

I am working on creating a program that uses the Speech aspect of Azure's Cognitive Services. When I deploy the executable(.exe) with just console printing, it works as hoped. The program works perfect with the Azure Voice within the VS Code environment, but once it is deployed as an executable (.exe), it completely errors out with the following error:
RuntimeError: Exception with an error code: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND)
[CALL STACK BEGIN]
> property_bag_copy
- synthesizer_create_speech_synthesizer_from_config
- synthesizer_create_speech_synthesizer_from_config
- 00007FFECED052D4 (SymFromAddr() error: Attempt to access invalid address.)
- 00007FFECED4DA6E (SymFromAddr() error: Attempt to access invalid address.)
- 00007FFECED4E0F3 (SymFromAddr() error: Attempt to access invalid address.)
- PyArg_ParseTuple_SizeT
- PyEval_EvalFrameDefault
- PyFunction_Vectorcall
- PyEval_EvalFrameDefault
- PyObject_GC_Del
- PyFunction_Vectorcall
- PyType_GenericNew
- PyType_GenericNew
- PyObject_MakeTpCall
- PyEval_EvalFrameDefault
[CALL STACK END]
I have tried reinstalling all dependencies

The error indicates that it is not able to find the audio sys library/
This error might arise if it is not able to access the dependency dll :
Microsoft.CognitiveServices.Speech.extension.audio.sys.dll
You could add this dll to your package before converting it to exe.
The file will be in present at the location where you had installed the Speech Module for python.

Related

SPXERR_GSTREAMER_NOT_FOUND_ERROR, Python, Windows 11

I'm having an issue with running azure-cognitiveservices-speech python SDK which uses GStreamer. I followed the instruction Quickstart: Create captions with speech to text and got the following error:
File "C:\Users\z\Desktop\cognitive-services-speech-sdk-master\scenarios\python\console\captioning\captioning.py", line 355, in <module>
speech_recognizer_data = captioning.speech_recognizer_from_user_config()
File "C:\Users\z\Desktop\cognitive-services-speech-sdk-master\scenarios\python\console\captioning\captioning.py", line 263, in speech_recognizer_from_user_config
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config_data["audio_config"])
File "C:\Users\z\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\azure\cognitiveservices\speech\speech.py", line 1004, in __init__
_call_hr_fn(
- recognizer_create_speech_recognizer_from_config - ffi_prep_go_closure
- ffi_call_go
- ffi_call - 00007FFB60E62C35 (SymFromAddr() error: Attempt to access invalid address.)
- 00007FFB60E629B7 (SymFromAddr() error: Attempt to access invalid address.)
- 00007FFB60E62628 (SymFromAddr() error: Attempt to access invalid address.) - PyObject_Call
- PyEval_EvalFrameDefault
- PyFunction_Vectorcall
[CALL STACK END]
Exception with an error code: 0x29 (SPXERR_GSTREAMER_NOT_FOUND_ERROR)
When running gst-inspect-1.0.exe --version I can see that GStreamer is available:
gst-inspect-1.0 version 1.18.3
GStreamer 1.18.3
Unknown package origin
I am using azure-cognitiveservices-speech 1.25.0, Windows 11, Python 3.10.
I was trying to use older and latest version of SDK but I'm still getting the same error.

Azure Speech to text 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND)

I've been trying to start a project involving azure speech to text and for testing purpose wanted to corroborate the workings with the demo code found in this site:
https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started-speech-to-text?tabs=windowsinstall%2Cterminal&pivots=programming-language-python.
Installed all the prerequisites from Microsoft redistributables to pip install azure-cognitiveservices-speech.
I've set my default microphone.
Got my subscription key and region from azure cognitive service via azure portal> all resources> speech resource> keys and endpoint
But im unable to start the demo since it throws error 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND)
The traceback is
Traceback (most recent call last):
File "c:\Users\user\Desktop\Azure test\test.py", line 26, in <module>
recognize_from_microphone()
File "c:\Users\user\Desktop\Azure test\test.py", line 10, in recognize_from_microphone
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
File "C:\Users\user\Desktop\Azure test\.env\lib\site-packages\azure\cognitiveservices\speech\speech.py", line 808, in __init__
self._impl = self._get_impl(impl.SpeechRecognizer, speech_config, audio_config, language, source_language_config, auto_detect_source_language_config)
File "C:\Users\user\Desktop\Azure test\.env\lib\site-packages\azure\cognitiveservices\speech\speech.py", line 870, in _get_impl
return reco_type._from_config(speech_config._impl)
RuntimeError: Exception with an error code: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND)
The call stack goes as follow
[CALL STACK BEGIN]
> pal_string_to_wstring
- pal_string_to_wstring
- audio_config_get_audio_processing_options
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
- pal_string_to_wstring
[CALL STACK END]
Just in case it matter I'm using Windows 11 and Python 3.9.12 acquired from microsoft store.
I would post the code but it's a literal copy of the one found in the html only with the subscription key which found in said place.
Edit:
I was able to run the same example using javascript but node.js only supports from audio file to text which is not what I'm looking for.
Also azure speech to text does work with microphone using js but using the browser with means client side but optimally this isn't what I'm looking for. Just pointing this out as proof all resource from azure are configured correctly and maybe this is something related to python or pip package manager but like i said all the dll files mentioned in other topics are in the virtual environment so it "shouldn't" be an issue
If someone could help me since I'm at loss here.
Please check if my findings are helpful:
As you mentioned that you are using the Python 3.9.12 acquired from Microsoft store.
The same issue had been registered in the GitHub where people had fixed this issue by switching/using the Python interpreter from the Python.org website and copied over the azure site packages to that install location.
So, try switching to python interpreter from official website and the troubleshooting steps given in this GitHub issue.
Per the defined pre-requisites, make sure to have dependencies installed.
In my case, I needed libssl-dev libasound2.

Google app engine deployment fails- Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')

We are using command prompt c:\gcloud app deploy app.yaml, but get the following error:
Running "python3 -m pip install --requirement requirements.txt --upgrade --upgrade-strategy only-if-needed --no-warn-script-location --no-warn-conflicts --force-reinstall --no-compile (PIP_CACHE_DIR=/layers/google.python.pip/pipcache PIP_DISABLE_PIP_VERSION_CHECK=1)"
Step #2 - "build": /layers/google.python.pip/pip/bin/python3: Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')
Step #2 - "build": Done "python3 -m pip install --requirement requirements.txt --upgr..." (34.49892ms)
Step #2 - "build": Failure: (ID: 0ea8a540) /layers/google.python.pip/pip/bin/python3: Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')
Step #2 - "build": --------------------------------------------------------------------------------
Step #2 - "build": Running "mv -f /builder/outputs/output-5577006791947779410 /builder/outputs/output"
Step #2 - "build": Done "mv -f /builder/outputs/output-5577006791947779410 /builder/o..." (12.758866ms)
Step #2 - "build": ERROR: failed to build: exit status 1
Finished Step #2 - "build"
ERROR
ERROR: build step 2 "us.gcr.io/gae-runtimes/buildpacks/python37/builder:python37_20211201_3_7_12_RC00" failed: step exited with non-zero status: 145
Our Requirements.txt is as below. We are currently on Python 3.7 standard app engine
firebase_admin==3.0.0
sendgrid==6.9.3
google-auth==1.35.0
google-auth-httplib2==0.1.0
jinja2==3.0.3
MarkupSafe==2.0.1
pytz==2021.3
Flask==2.0.2
twilio==6.46.0
httplib2==0.20.2
requests==2.24.0
requests_toolbelt==0.9.1
google-cloud-tasks==2.7.1
google-cloud-logging==1.15.1
googleapis-common-protos==1.54.0
Please help.The above code was working well before updating the requirements.txt file. We tried to remove gunicorn to allow the system pickup the latest according to documentation here.
We have a subdirectory structure that stores all the .py files in controllers and db definitions in models. Our main.py has the following -
sys.path.append(os.path.join(os.path.dirname(__file__), '../controllers'))
sys.path.append(os.path.join(os.path.dirname(__file__), '../models'))
Does anyone know how to debug this error - Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__'). What does this mean?
The release 60.3.0 of setuptools has a bug causing the above AttributeError, see : https://github.com/pypa/setuptools/issues/3002
It has been yanked by Pypi since then:
Yanked files are always ignored, unless they are the only file that matches a version specifier that "pins" to an exact version using either == (without any modifiers that make it a range, such as .*) or ===. Matching this version specifier should otherwise be done as per PEP 440 for things like local versions, zero padding, etc.
Source: https://www.python.org/dev/peps/pep-0592/
What you can do as of now is pass the version of the setuptools package explicitly, to use for example version 60.2.0 or 60.3.1.
I had the same issue when deploying a Google Cloud Function. The error
cloud function Error while finding module specification for 'pip' (AttributeError: module 'main' has no attribute 'file'); Error ID: c84b3231
appeared after commenting out some packages in the requirements.txt, but that was nothing important and likely did not cause it. I guess that it is more a problem of an instability in Google Storage, since that same Cloud Function I was working on had lost its archive already some time before, all of a sudden, out of nowhere, showing:
Archive not found in the storage location cloud function
and I did not delete or change anything that might explain this, as Archive not found in the storage location: Google Function would suggest. Though that answer has one very interesting guess that might explain at least the very first time the "Archive not found" error came up and thus made the CF instable: I might have changed the timezone city of the bucket during browsing the Google Storage. It is too long ago, but I know I browsed the GS, therefore, I cannot exclude this. Quote: "It [the Archive not found error] may occurr too if GCS bucket's region is not matched to your Cloud function region."
After this "Archive not found" crash, I manually added main.py and requirements.txt and filled them again with code from the backup. This worked for some time, but there seems to be some general instability in the Google Storage. Therefore, always keep backups of your deployed scripts.
Then, after getting this pip error of the question in that already instable Cloud Function, waiting for a day or two, Google Function again showed
Archive not found in the storage location cloud function
If you run into this pip error in a Cloud Function, you might consider updating pip in the "requirements.txt" but if you are in such an unstable Cloud Function the better workaround seems to be to create a new Cloud Function and copy everything in there.
The pip error probably just shows that the source script, in this case the requirements.txt, cannot be run since the source code is not fully embedded anymore or has lost some embedding in the Google Storage.
Or you give that Cloud Function a second chance and edit, go to Source tab, click on Dropdown Source code to choose Inline Editor and add main.py and requirements.txt manually (Runtime: Python).
By installing the previous version 60.2.0 of setuptools before installing pip-tools helped me get it running.
pip install setuptools==60.2.0
Your setuptools version is likely to be yanked:
https://pypi.org/project/setuptools/60.3.0/
Not sure how to fix that without a working pip though.
Setuptools 60.3.1 is out now. GitHub Link here.

Kivy buildozer: toolchain.py: error: the following arguments are required: --package

Everytime I deploy my app, I delete all the stuff in the folder and I load my Github app project (with the .spec) before running buildozer -v android release.
Now I encounter this error: toolchain.py: error: the following arguments are required: --package
but I only changed my python code. How is it possible that changing python stuff makes my .apk creation crash ? What could I try to debug this ?
Found it, you can begin a line with # to make a commentary but you can't do put it following a useful line.

import gammu class - getting error no module named

I just want to get status from gammu
import gammu.smsd
smsd = gammu.smsd.SMSD('/etc/gammu-smsdrc')
print smsd.GetStatus()
I saved code to /home/pi/mypython.py
and ran it from terminal
sudo pyhton /home/pi/mypython.py
I'm getting an error
ImportError : No module named gammu.smsd
My target is getting Gammu Status, then if gammu status is stopped I will start it automaticly from other python code.
I was trying:
service gammu-smsd status
Result: No help - just shown usage of gammu-smsd
service --status-all
Result: I'm getting [?] gammu-smsd < unknown is started or stopped
'
Whats wrong with my code? Is there any step I need to do?
The python bindings are separate package, so you need to install it separately even if you already have Gammu installed.

Categories

Resources