Generate a REST API client library for the Speech to text REST API

The 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.


Speech service has several REST APIs for Speech to text and Text to speech.

However only the speech to text REST API and custom voice REST API are 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 for the Speech to text REST API version 3.1.

You 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.

  1. In a browser, go to
  2. Select File, select Import URL,
  3. Enter the URL and select OK.
  4. Select Generate Client and select python. The client library downloads to your computer in a .zip file.
  5. Extract everything from the download. You might use tar -xf to extract everything.
  6. Install the extracted module into your Python environment:
    pip install path/to/package/python-client
  7. The installed package is named swagger_client. Check that the installation succeeded:
    python -c "import swagger_client"

You can use the Python library that you generated with the Speech service samples on GitHub.

Next steps