您可以使用 Lyria 根据您在 Google Cloud 控制台中提供或在请求中发送给 Gemini API in Vertex AI API 的文本提示生成新的器乐曲目。
试用 Lyria on Vertex AI (Vertex AI Studio)
Lyria 功能和发布阶段
Lyria 提供用于音乐创作的生成式 AI 功能。
下表介绍了已面向所有用户正式发布 (GA) 的功能:
功能 | 说明 | 发布阶段 |
---|---|---|
根据文本生成音乐 | 根据描述性文本输入生成器乐曲目。 | 正式版 |
否定提示 | 引导模型避免在生成的音乐中包含特定元素。 | 正式版 |
用于实现可重现性的种子 | 使用种子可确保针对同一提示和参数生成一致的输出。 | 正式版 |
位置
位置是您可以在请求中指定的区域,用于控制静态数据的存储位置。Lyria 2 面向全球用户提供。如需查看 Vertex AI 服务的可用区域列表,请参阅 Vertex AI 上的生成式 AI 位置。
性能和限制
限制 | 值 |
---|---|
模态 | 文生音乐(仅限器乐) |
API 调用(每个项目每分钟提示数) | 如需了解标准 Vertex AI 推理限制,请参阅 [配额和限制文档](/vertex-ai/generative-ai/docs/quotas)。 |
请求延迟时间(生成时间) | 音频片段通常会在 10 到 20 秒内生成。在高使用率期间,部分请求可能会排队。 |
每个请求返回的音频片段数量上限 | 最多为指定的 sample_count 。(sample_count 的最大值待定,通常是一个较小的整数,例如 1-4). |
每个片段的音频时长 | 32.8 秒 |
支持的返回音频格式 | 采样率为 48kHz 的 WAV 音频 |
输入提示语言 | 英语(美国)(en-us) |
Responsible AI
Lyria 可根据文本提示生成器乐。 Lyria 会采取安全措施,包括内容安全过滤器、朗诵检查和艺术家意图检查,以防止输入和生成有害或不当内容。SynthID 水印用于生成的音频。违反负责任的 AI 准则的提示可能会被屏蔽。
Lyria Vertex AI 模型版本和生命周期
Lyria 模型和版本如下所示:
模型名称 | ID |
---|---|
Lyria 2 | lyria-002 |
根据文本生成音乐
您可以使用描述性文本作为输入来生成新器乐曲目。
准备工作
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Enable the Vertex AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
为您的环境设置身份验证。
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭证。
安装 Google Cloud CLI。 安装完成后,运行以下命令来初始化 Google Cloud CLI:
gcloud init
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
控制台
在 Google Cloud 控制台中,依次前往 Vertex AI Studio > Media Studio 页面。
选择 Lyria 模型或音乐生成选项。
可选:在设置窗格中,配置以下设置:
- 模型:如果有多个版本,请选择
lyria-002
。 - 样本数量 (
sample_count
):调整要为提示生成的音频片段数量。(不能与 Seed 一起使用)。 - 种子:输入一个整数,以便获得可重现的输出。(不能与“样本数”一起使用)。
- 模型:如果有多个版本,请选择
在撰写提示框中,输入描述要生成的音乐的文本提示(使用美国英语)。
可选:在负面提示框中,输入要从生成的音乐中排除的字词或说明。
点击
生成。生成的音频片段将以 WAV 文件格式提供,供您预览和下载。
REST
使用
predict
方法发送音乐生成请求。响应将直接包含音频数据,如果响应是 JSON,则通常会进行 base64 编码。如需详细了解
lyria-002
模型请求,请参阅lyria-002
模型 API 参考文档。如需生成音乐,请向模型的
predict
端点发送 POST 请求。请求:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/lyria-002:predict \ -d '{ "instances": [ { "prompt": "An uplifting and hopeful orchestral piece with a soaring string melody and triumphant brass.", "negative_prompt": " dissonant, minor key", "seed": 12345 } ], "parameters": { // "sample_count": 1 // Use either seed or sample_count } }'
响应:
如果请求成功,则会返回一个包含生成的音频数据的 JSON 对象。输出应如下所示:
{ "predictions": [ { "audioContent": "BASE64_ENCODED_WAV_STRING_SAMPLE_1", "mimeType": "audio/wav" }, { "audioContent": "BASE64_ENCODED_WAV_STRING_SAMPLE_2", "mimeType": "audio/wav" } ], "deployedModelId": "xxxxxxxxxxxxxxx", "model": "projects/PROJECT_ID/locations/LOCATION/publishers/google/models/lyria-002", "modelDisplayName": "Lyria 2" }
然后,您需要对
audioContent
(base64) 进行解码,以获取 WAV 音频文件。每个剪辑的时长为 32.8 秒。后续步骤
- 请参阅 Lyria 音乐生成提示指南,了解如何撰写有效的提示
- 探索 Lyria API 参考文档
- 探索 Vertex AI 上的其他生成式 AI 模型
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-12。