Swagger 文档Swagger documentation

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


支持将语音转文本和文本转语音操作作为 REST API,而后者记录在 Swagger 规范中。Both Speech-to-Text and Text-to-Speech operations are supported available as REST APIs, which are in turn documented in the Swagger specification.

从 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 same region as your Speech service subscription. 可在 Azure 门户中的语音服务资源下确认区域。You can confirm your region in the Azure portal under your Speech service resource. 有关受支持区域的完整列表,请参阅区域For a complete list of supported regions, see regions.

  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 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 docs

后续步骤Next steps