Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named '_speech_py_impl' #437

Closed
javierrodenas opened this issue Nov 18, 2019 · 24 comments
Closed

ModuleNotFoundError: No module named '_speech_py_impl' #437

javierrodenas opened this issue Nov 18, 2019 · 24 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@javierrodenas
Copy link

Hi,

I am trying to upload azure funtion in Python with Linux plan. In the first lines of code, it returns an error because of the following line:
import azure.cognitiveservices.speech as speechsdk

The error that I can see in logs is :

Result: Failure
Exception: ModuleNotFoundError: No module named '_speech_py_impl'
Stack: File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/dispatcher.py", line 242, in _handle__function_load_request
func_request.metadata.entry_point)
File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/loader.py", line 66, in load_function
mod = importlib.import_module(fullmodname)
File "/usr/local/lib/python3.6/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/site/wwwroot/SARASHttpTrigger/init.py", line 5, in
from . import STT
File "/home/site/wwwroot/SARASHttpTrigger/STT.py", line 4, in
import azure.cognitiveservices.speech as speechsdk
File "/home/site/wwwroot/.python_packages/lib/python3.6/site-packages/azure/cognitiveservices/speech/init.py", line 8, in
from .speech import *
File "/home/site/wwwroot/.python_packages/lib/python3.6/site-packages/azure/cognitiveservices/speech/speech.py", line 8, in
from . import speech_py_impl as impl
File "/home/site/wwwroot/.python_packages/lib/python3.6/site-packages/azure/cognitiveservices/speech/speech_py_impl.py", line 17, in
_speech_py_impl = swig_import_helper()
File "/home/site/wwwroot/.python_packages/lib/python3.6/site-packages/azure/cognitiveservices/speech/speech_py_impl.py", line 16, in swig_import_helper
return importlib.import_module('_speech_py_impl')
File "/usr/local/lib/python3.6/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)

I have tried with all version available of the library azure-cognitiveservices-speech but it doesn't work.

The structure of the .py files is the following:
-SARASFunction
- init.py
- function.json
- STT.py
-host.json
-requeriments.py

Could you help me? Is azure ready for azure.cognitiveservices.speech?

Thank you in advance.

@BrianMouncer
Copy link
Contributor

Can you successfully run this Python sample for Speech Recognition from Microphone?
I am not an expert on using Python, but the most common reason I have seen for a "import failure" like this (assuming you know the wheel is actually installed) is that the scope of the install is incorrect. You can install the python package for the current folder only, the user only, or the entire system. e.g you might want to use "pip install --user azure-cognitiveservices-speech" instead of "pip install azure-cognitiveservices-speech", and if you are having troubles with pip command-line installing the package for "Python", but you are using "Python3", you can use "python3 -m pip install --user azure-cognitiveservices-speech" to make sure you are installing the package for the python instance you are actually using...

Does that help?

Brian.

@Jamesits
Copy link

I can reproduce this problem in the same configuration. It seems that the native dependencies of speech SDK is not installed.

@javierrodenas
Copy link
Author

Thank for you response.

Do you know how to install system libraries in Linux plan? Kudu is not available in Linux and I don't know how to install/upload this system libraries.

@Jamesits
Copy link

Jamesits commented Nov 19, 2019

I don't know, I ported my code to a more normal Linux runtime this afternoon and as long as build-essential libssl1.0.2 libasound2 is installed, this library works well for me.

@BrianMouncer
Copy link
Contributor

I'm not sure what you mean by "Linux plan".

If you follow the readme for this quickstart, it gives the apt-get commands to install these system libraries.

https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/python/from-microphone

Brian.

@Jamesits
Copy link

@BrianMouncer We are trying to use this library on Azure Functions. It has a Linux plan which runs Python and installs whatever python modules you upload but it doesn't allow you to install system-level packages (I haven't found any way to access the system package manager).

@javierrodenas
Copy link
Author

javierrodenas commented Nov 20, 2019

@Jamesits What do you mean when you say "more normal"? How did you localize build-essential libssl1.0.2 libasound2 without Kudu?

@Jamesits
Copy link

@javierrodenas By saying "more normal" I meant the traditional, beloved VPS.

@chrisbasoglu
Copy link

Do you have all the dependencies listed in requirements.txt per: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python

@Jamesits
Copy link

@chrisbasoglu Yes, in my case the dependencies are managed by pipenv and frozen into requirements.txt before commit automatically. This does not mean it would just work; the speech SDK depends on several system-level libraries which cannot be installed via requirements.txt.

@brechtPhilips
Copy link

Hi,
Is there a solution for this problem? I'm getting the same error with azure functions in python on a linux app service plan. Using Kudu is not an option as i'm using a consumption plan for the functions. The vision services works fine it's the speech sdk that fails.

@javierrodenas
Copy link
Author

Hi @brechtPhilips,

The solution I have found is to use C# speech SDK. I hope some day python works...

@jhakulin
Copy link

jhakulin commented Dec 6, 2019

Thanks for feedback, we will include the request to support Python with Azure functions on Linux consumption plan to our backlog.
@javierrodenas Have you tried Python with Azure functions on Windows consumption plan ?

@javierrodenas
Copy link
Author

javierrodenas commented Dec 9, 2019

Hi @jhakulin ,
I think in Windows consumption plan is not posible to deploy a Python azure function.

@richardcerny
Copy link

@jhakulin Do you have ETA when the SDK will be supported by Azure Function?

@oscholz
Copy link
Contributor

oscholz commented Jan 22, 2020

Sorry for the radio silence on this.
a good path forward for this custom dependency scenario would be creating a custom Functions container image and hosting that custom container image on the Premium Plan for Linux.

Alternatively, you can wait until the SDK team will refactor some code to support this in your current configuration. We have put that work on our backlog, and we strive to respond to customer issues first before we do a lot of net new work. That said, I cannot give a timeline for when this work will be done.
When this does get done, we will respond on this thread to let you know that we've completed the work.

@javierrodenas
Copy link
Author

Thanks for your response @oscholz. We will wait news about that!

@pankopon pankopon added the bug Something isn't working label Feb 20, 2020
@pankopon pankopon assigned oscholz and unassigned BrianMouncer Feb 20, 2020
@siwon
Copy link

siwon commented Feb 25, 2020

Hi @oscholz,

Is there any news about the fix from the SDK team ?

Thanks a lot !

@giucas79
Copy link

Is there any news about this problem?

@TKlerx
Copy link

TKlerx commented Apr 30, 2020

Any update on this?
We are building an AppSource solution (Teams Bot) and upload the recordings to a blob store.
The obvious scenario is to use a BlobTrigger function in which we use the speech SDK (using python at the moment).
That does not work, so it would be good to have a fix for this!

@TKlerx
Copy link

TKlerx commented May 1, 2020

To add to my previous comment:
I guess the SDK does not work on linux (esp. Azure function) because the SDK brings functionality to access the microphone.
Why don't you build and upload the SDK package to Pypi with a mandatory part to send audio files to the web API and an optional part for sending audio from microphone to the web API? I don't need the microphone functionality in the Azure function.

For anyone still interested in using this in Azure functions: I wrote a simple snippet (following the official documentation) that just sends a web request to the web API, but does not cover all functionality of the SDK:

# Request module must be installed.
# Run 'pip install requests' if necessary.
import requests

subscription_key = '<your subscription key>'
# adapt URL for other location and/or language
url = "https://westeurope.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=de-DE&format=detailed"

def get_token(subscription_key):
    fetch_token_url = 'https://westeurope.api.cognitive.microsoft.com/sts/v1.0/issueToken'
    headers = {
        'Ocp-Apim-Subscription-Key': subscription_key
    }
    response = requests.post(fetch_token_url, headers=headers)
    return str(response.text)

token = get_token(subscription_key)

headers = {
  'Authorization': f'Bearer {token}',
  'Content-Type': 'audio/wave',
  'Accept': 'application/json'
}
with open(r"../temp.wav","rb") as payload:
    response = requests.request("POST", url, headers=headers, data=payload)
    print(response.text.encode('utf8'))

@oscholz
Copy link
Contributor

oscholz commented Jun 16, 2020

@javierrodenas @siwon @TKlerx @giucas79 @brechtPhilips @Jamesits @richardcerny I apologize for the radio silence on this. We have added this to our backlog, but haven't yet gotten to it. I will close this issue now. When we complete the work required, we will update this issue with information about the release number that will contain the fix. Thank you for your patience!

@oscholz oscholz closed this as completed Jun 16, 2020
@jhakulin
Copy link

@javierrodenas @siwon @TKlerx @giucas79 @brechtPhilips @Jamesits @richardcerny Speech SDK Azure functions for Python (which always uses Linux OS in Azure) has been verified working with the latest 1.13.0 version. Azure functions for Python were verified working in Azure portal (with http and blob triggers) using steps documented here https://docs.microsoft.com/en-us/azure/developer/python/tutorial-vs-code-serverless-python-01 and adding dependencies to microsoft-cognitiveservices-speech library in requirements.txt and basic speech sdk code which use speech recognizer.
Please let us know if you see any problems currently.

@Mono33
Copy link

Mono33 commented Apr 21, 2021

Try to install speech-interface with pip install speech-interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests