Lyria | AI 音樂產生器

你可以使用 Lyria,透過在 Google Cloud 控制台中提供的文字提示,或在 Vertex AI API 中向 Gemini API 傳送要求,生成新的樂器音樂曲目。

在 Vertex AI (Vertex AI Studio) 上試用 Lyria

Lyria 功能和推出階段

Lyria 提供生成式 AI 功能,可創作音樂。

下表說明正式發布 (GA) 的功能,所有使用者都能使用:

功能 說明 發布階段
使用文字生成音樂 根據輸入的描述文字生成純音樂曲目。 正式發布版
負面提示 引導模型在生成的音樂中避開特定元素。 正式發布版
可重現性的種子 使用種子可確保系統針對相同提示和參數產生一致的輸出內容。 正式發布版

位置

位置是您可以在要求中指定的區域,用來控管靜態資料的儲存位置。Lyria 2 已在全球推出。如要查看 Vertex AI 服務的可用區域清單,請參閱「Vertex AI 的生成式 AI 服務地區」。

效能和限制

限制
形式 生成文字轉音樂 (僅限純音樂)
API 呼叫 (每項專案每分鐘的提示數) 如需標準 Vertex AI Inference 限制,請參閱配額與限制說明文件
要求延遲時間 (生成時間) 音訊片段通常會在 10 到 20 秒內生成。在用量高峰期,部分要求可能會排隊等候處理。
每個要求傳回的音訊片段數量上限 最多可儲值指定金額 sample_count。(sample_count 的最大值待定,通常為小整數,例如 1-4)。
每個片段的音訊長度 32.8 秒
支援的回傳音訊格式 取樣率為 48kHz 的 WAV 音訊
輸入提示語言 英文 (美國) (en-us)

負責任的 AI 技術

Lyria 會根據文字提示生成純音樂。 Lyria 會採取安全措施,包括內容安全篩選器、朗讀檢查和藝人意圖檢查,防止輸入及生成有害或不當內容。生成的音訊會加上 SynthID 浮水印。違反負責任的 AI 技術指南的提示可能會遭到封鎖。

Lyria Vertex AI 模型版本和生命週期

Lyria 模型和版本如下:

模型名稱 識別碼
Lyria 2 lyria-002

根據文字生成音樂

你可以輸入描述性文字,生成新穎的純音樂曲目。

事前準備

  1. 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.
  2. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  4. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  5. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  6. 為環境設定驗證機制。

    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 進行驗證」。

    控制台

    1. 在 Google Cloud 控制台中,依序前往「Vertex AI Studio」>「Media Studio」頁面。

      Media Studio

    2. 選取「Lyria」Lyria模型或音樂生成選項。

    3. 選擇性步驟:在「Settings」(設定) 窗格中完成下列設定:

      • 模型:如有不同版本,請選擇 lyria-002
      • 樣本數量 (sample_count):調整系統根據提示生成的音訊片段數量。(無法與 Seed 搭配使用)。
      • 種子:輸入整數,確保輸出結果可重現。(無法與樣本數搭配使用)。
    4. 在「撰寫提示」方塊中,以美式英文輸入文字提示,說明要生成的音樂。

    5. 選用:在「負面提示」方塊中輸入要從生成音樂中排除的字詞或描述。

    6. 按一下「生成」

    7. 生成音訊片段會提供預覽,並可下載為 WAV 檔案。

    REST

    使用 predict 方法傳送音樂生成要求。回應會直接包含音訊資料,如果回應是 JSON 格式,通常會採用 base64 編碼。

    如要進一步瞭解 lyria-002 模型要求,請參閱 lyria-002 模型 API 參考資料

    如要生成音樂,請將 POST 要求傳送至模型的 predict 端點。

    要求:

    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 秒。

    後續步驟