Swagger 文档Swagger documentation

语音服务提供了一个 Swagger 规范,用于与少量 REST API 交互,这些 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. 可使用这些 API 以编程方式完成通过 Speech Studio 的自定义语音识别区域提供的大部分操作。Most operations available through the Custom Speech area of the Speech Studio can be completed programmatically using these APIs.


语音服务具有多个 REST API,分别用于语音转文本文本转语音Speech service has several REST APIs for Speech-to-text and Text-to-speech.

但是,Swagger 规范中仅记录了语音转文本 REST API v3.0 和 v2.0。However only Speech-to-text REST API v3.0 and v2.0 are documented in the Swagger specification. 有关所有其他语音服务 REST API 的信息,请参阅上一段中引用的文档。See the documents referenced in the previous paragraph for the information on all other Speech Services REST APIs.

从 Swagger 规范生成代码Generating code from the Swagger specification

Swagger 规范包含可快速测试各种路径的选项。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. 让我们看看生成 Python 库的过程。Let's take a look at the process to generate a Python library.

你需要将 Swagger 设置为语音资源的区域。You'll need to set Swagger to the region of your Speech resource. 你可以在 Azure 门户的语音资源设置的“概述”部分中确认该区域。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. 在浏览器中,转到你所在区域的 Swagger 规范:In a browser, go to the Swagger specification for your region:
  2. 在该页上,单击“API 定义”,然后单击“Swagger” 。On that page, click API definition, and click Swagger. 复制显示的页的 URL。Copy the URL of the page that appears.
  3. 在新浏览器中,转到 https://editor.swagger.ioIn a new browser, go to https://editor.swagger.io
  4. 依次单击“文件”、“导入 URL”,然后粘贴该 URL,再单击“确定” 。Click File, click Import URL, paste the URL, and click OK.
  5. 单击“生成客户端”,然后选择“Python” 。Click Generate Client and select python. 客户端库会以 .zip 文件格式下载到你的计算机中。The client library downloads to your computer in a .zip file.
  6. 提取下载的全部内容。Extract everything from the download. 可使用 tar -xf 提取全部内容。You might use tar -xf to extract everything.
  7. 将提取的模块安装到 Python 环境:Install the extracted module into your Python environment:
    pip install path/to/package/python-client
  8. 将安装的包命名为 swagger_clientThe installed package is named swagger_client. 检查安装是否正常:Check that the installation has worked:
    python -c "import swagger_client"

可以使用通过 GitHub 上的语音服务示例生成的 Python 库。You can use the Python library that you generated with the Speech service samples on GitHub.

参考文档Reference documents

后续步骤Next steps