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 推論限制,請參閱 [配額和限制說明文件](/vertex-ai/generative-ai/docs/quotas)。
要求延遲時間 (生成時間) 音訊片段通常會在 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.

    Go to project selector

  3. Enable the Vertex AI API.

    Enable the API

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Enable the Vertex AI API.

    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 驗證說明文件中的「Authenticate for using REST」。

    主控台

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

      媒體工作室

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

    3. 選用:在「設定」窗格中,設定下列選項:

      • 模型:如有不同版本,請選擇 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 秒。

    後續步驟