Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK
MIT License
2.88k stars 1.85k forks source link

AttributeError: module 'swagger_client' has no attribute 'CustomSpeechTranscriptionsApi' #477

Closed Ray12345678910 closed 4 years ago

Ray12345678910 commented 4 years ago

Hi community,

I am following the tutorial "How to use the Speech Services Batch Transcription API from Python" (see: https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/samples/batch/python).

After following all the steps (downloading the "cognitive-services-speech-sdk', moving the 'python-client-generated' -from swagger- file in that folder) and changing my Subscription key, service region and blob uri I receive the following error:

AttributeError: module 'swagger_client' has no attribute 'CustomSpeechTranscriptionsApi'

The error occurs in the transcribe function:

transcription_api = cris_client.CustomSpeechTranscriptionsApi(api_client=client)

Anyone ideas how I can solve this (or what I am doing wrong?).

Many thanks in advance!

chlandsi commented 4 years ago

Hi, please try installing the module into your python environment using pip install, as described in the instructions, and then remove the swagger_client directory from your working directory. If that doesn't help, please put the command print(dir(cris_client)) before the failing command, and post the output here.

Ray12345678910 commented 4 years ago

Hi, please try installing the module into your python environment using pip install, as described in the instructions, and then remove the swagger_client directory from your working directory. If that doesn't help, please put the command print(dir(cris_client)) before the failing command, and post the output here.

Thanks for your help! 1). I exactly followed the instruction (the installing via pip the Python Client). 2). When I run this in the command line, it gives no error:

C:\Users\xxx>python -c "import swagger_client"

3). When running the main script again, I received the same error as this topics name. 4). I removed 'swagger_client'. Resulting in: ModuleNotFoundError: No module named 'swagger_client' 5). I restored the 'swagger_client' again, and added your print suggestion:


runfile('C:/Users/xxx/Desktop/Azure_Blob_Text/cognitive-services-speech-sdk-master/samples/batch/python/python-client/main.py', wdir='C:/Users/xxx/Desktop/Azure_Blob_Text/cognitive-services-speech-sdk-master/samples/batch/python/python-client')
Starting transcription client...

['ApiClient', 'ApiResponse', 'Category', 'Configuration', 'Order', 'Pet', 'PetApi', 'StoreApi', 'Tag', 'User', 'UserApi', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'absolute_import', 'api', 'api_client', 'configuration', 'models', 'rest']

Traceback (most recent call last):

  File "C:\Users\xxx\Desktop\Azure_Blob_Text\cognitive-services-speech-sdk-master\samples\batch\python\python-client\main.py", line 144, in <module>
    transcribe()

  File "C:\Users\xxx\Desktop\Azure_Blob_Text\cognitive-services-speech-sdk-master\samples\batch\python\python-client\main.py", line 47, in transcribe
    transcription_api = cris_client.CustomSpeechTranscriptionsApi(api_client=client)

AttributeError: module 'swagger_client' has no attribute 'CustomSpeechTranscriptionsApi'

Many thanks for your help!!

chlandsi commented 4 years ago

Hi, this looks very much like the default API that the swagger autogenerator uses. Apparently the import of https://<your-region>.cris.ai/docs/v2.0/swagger in the online tool didn't work properly. Please completely remove the current python module from your system (pip uninstall) and try the complete process again. Please make sure that the swagger website shows the heading "Speech Services API v2.0" before you download the Python client.

Ray12345678910 commented 4 years ago

Hi, this looks very much like the default API that the swagger autogenerator uses. Apparently the import of https://<your-region>.cris.ai/docs/v2.0/swagger in the online tool didn't work properly. Please completely remove the current python module from your system (pip uninstall) and try the complete process again. Please make sure that the swagger website shows the heading "Speech Services API v2.0" before you download the Python client.

You are right, thanks! What solved the problem, was pasting "westeurope" instead of "west-europe" and "" in Swagger.

chlandsi commented 4 years ago

Glad that it is fixed!

nikitamalviya commented 1 year ago

Go through the README on the site.

To execute the sample you need to generate the Python library for the REST API which is generated through Swagger.

Follow these steps for the installation:

Follow these steps. It will work.