Cloud Speech-to-Text 是一种 API,它使用 Google 的 AI 技术将音频数据作为输入,并输出文本转写内容,从而将语音转换为文字。本页面介绍了如何为项目设置 Cloud Speech-to-Text API,以便您可以开始调用该 API。
本文档包括以下内容:
- 为 Google Cloud 项目启用和停用 Cloud Speech-to-Text API
- 为 Cloud Speech-to-Text 启用结算功能
- 可选:创建新的 Google Cloud 存储桶以存储音频数据(适用于大型文件)
本文档未介绍如何使用 Cloud Speech-to-Text API 开始发送和接收请求。如需了解如何开始将 Cloud Speech-to-Text 集成到实际代码中,请参阅我们的概览页面。
准备工作
访问该服务的方法有两种:使用 REST API,或使用Google Cloud 控制台。
本指南介绍了开始向 REST API 发送请求所需的步骤。如果您刚接触编码,我们建议您先学习 Google CloudPlatform 中的分步控制台教程,然后再开始学习这些步骤。
为您的 Google Cloud 项目启用 Cloud Speech-to-Text API
如果您创建新项目,则系统会提示您将一个结算账号关联到该项目。如果您使用的是现有项目,请确保已启用结算功能。
启用 Cloud Speech-to-Text API。点击页面顶部的搜索产品和资源文本字段,然后输入“speech”。从结果列表中选择 Cloud Speech-to-Text API。
如需启用 Cloud Speech-to-Text API 以用于您的项目,请点击启用。如果您想先试用 Cloud Speech-to-Text 而不将其与项目关联,请点击试用此 API。
可选:(仅限 API V1)启用数据日志记录。选择启用数据日志记录,即表示您允许 Google 记录您发送到 Cloud Speech-to-Text 的所有音频数据。此数据将用于改进 Cloud Speech-to-Text 模型。选择启用数据日志记录功能的用户可以获享更低的产品价格。如需了解详情,请参阅价格和数据日志记录条款及条件页面。
可选:创建 Cloud Storage 存储桶
如需转写时长超过 60 秒或文件大小大于 10 MB 的音频,您必须先将音频数据存储在 Cloud Storage 存储桶中,然后才能使用 Cloud Speech-to-Text 进行转写。
如需创建新的 Cloud Storage 存储桶,请执行以下操作:
- In the Google Cloud console, go to the Cloud Storage Buckets page.
- Click Create.
- On the Create a bucket page, enter your bucket information. To go to the next
step, click Continue.
- For Name your bucket, enter a unique bucket name. Don't include sensitive information in the bucket name, because the bucket namespace is global and publicly visible.
-
In the Choose where to store your data section, do the following:
- Select a Location type.
- Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
- If you select the dual-region location type, you can also choose to enable turbo replication by using the relevant checkbox.
- To set up cross-bucket replication, select
Add cross-bucket replication via Storage Transfer Service and
follow these steps:
Set up cross-bucket replication
- In the Bucket menu, select a bucket.
In the Replication settings section, click Configure to configure settings for the replication job.
The Configure cross-bucket replication pane appears.
- To filter objects to replicate by object name prefix, enter a prefix that you want to include or exclude objects from, then click Add a prefix.
- To set a storage class for the replicated objects, select a storage class from the Storage class menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default.
- Click Done.
-
In the Choose how to store your data section, do the following:
- Select a default storage class for the bucket or Autoclass for automatic storage class management of your bucket's data.
- To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
- In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control method for your bucket's objects.
-
In the Choose how to protect object data section, do the
following:
- Select any of the options under Data protection that you
want to set for your bucket.
- To enable soft delete, click the Soft delete policy (For data recovery) checkbox, and specify the number of days you want to retain objects after deletion.
- To set Object Versioning, click the Object versioning (For version control) checkbox, and specify the maximum number of versions per object and the number of days after which the noncurrent versions expire.
- To enable the retention policy on objects and buckets, click the Retention (For compliance) checkbox, and then do the following:
- To enable Object Retention Lock, click the Enable object retention checkbox.
- To enable Bucket Lock, click the Set bucket retention policy checkbox, and choose a unit of time and a length of time for your retention period.
- To choose how your object data will be encrypted, expand the Data encryption section (), and select a Data encryption method.
- Select any of the options under Data protection that you
want to set for your bucket.
- Click Create.
- 前往 Google Cloud 信息中心,然后点击前往 API 概览。
- 选择 Cloud Speech-to-Text API。
- 点击停用 API。
停用 Cloud Speech-to-Text API
如果您不再需要通过项目使用 Cloud Speech-to-Text API,请执行以下操作:
后续步骤
了解如何使用客户端库、gcloud、命令行或 Speech-to-Text 界面向 Cloud Speech-to-Text API 发送转写请求。