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:
- Go to https://editor.swagger.io
- Click File, then click Import URL
- Enter the Swagger URL including the region for your Speech Services subscription:
https://<your-region>.cris.ai/docs/v2.0/swagger
- Click Generate Client and select Python
- Save the client library
- Extract the downloaded python-client-generated.zip somewhere in your file system.
- Install the extracted python-client module in your Python environment using pip:
pip install path/to/package/python-client
. - The installed package has the name
swagger_client
. You can check that the installation worked using the commandpython -c "import swagger_client"
.
NOTE:
Due to a known bug in the swagger autogeneration, you might encounter errors on importing the swagger_client
package.
These can be fixed by deleting the line with the content
from swagger_client.models.model import Model # noqa: F401,E501
from the file swagger_client\models\model.py
and the line with the content
from swagger_client.models.inner_error import InnerError # noqa: F401,E501
from the file swagger_client\models\inner_error.py
inside the installed package. The error message will tell you where these files are located for your installation.
The sample uses the requests
library. You can install it with the command
pip install requests
The sample code itself is main.py. You will need to adapt the following information to run the sample:
- Your subscription key and the associated region. This must be the same region you downloaded the client for; it won't work for any other region.
- The uri of an audio recording in blob storage
- (Optional:) The model ids of both an adapted acoustic and language model, if you want to use a custom model.
You can use a development environment like PyCharm to edit, debug, and execute the sample.