Generate a REST API client library for the Speech to text REST API
Speech service offers a Swagger specification to interact with a handful of REST APIs used to import data, create models, test model accuracy, create custom endpoints, queue up batch transcriptions, and manage subscriptions. Most operations available through the Custom Speech area of the Speech Studio can be completed programmatically using these APIs.
Note
Speech service has several REST APIs for Speech to text and Text to speech.
However only Speech to text REST API is documented in the Swagger specification. See the documents referenced in the previous paragraph for the information on all other Speech service REST APIs.
Generating code from the Swagger specification
The Swagger specification has options that allow you to quickly test for various paths. However, sometimes it's desirable to generate code for all paths, creating a single library of calls that you can base future solutions on. Let's take a look at the process to generate a Python library.
You'll need to set Swagger to the region of your Speech resource. You can confirm the region in the Overview part of your Speech resource settings in Azure portal. The complete list of supported regions is available here.
- In a browser, go to the Swagger specification for your region:
https://<your-region>.dev.cognitive.microsoft.com/docs/services/speech-to-text-api-v3-1
- On that page, select API definition, and select Swagger. Copy the URL of the page that appears.
- In a new browser, go to https://editor.swagger.io
- Select File, select Import URL, paste the URL, and select OK.
- Select Generate Client and select python. The client library downloads to your computer in a
.zip
file. - Extract everything from the download. You might use
tar -xf
to extract everything. - Install the extracted module into your Python environment:
pip install path/to/package/python-client
- The installed package is named
swagger_client
. Check that the installation has worked:
python -c "import swagger_client"
You can use the Python library that you generated with the Speech service samples on GitHub.
Next steps
Feedback
Submit and view feedback for