Lyria API

Lyria 是用於生成高品質音訊的新基礎模型,可根據文字提示創造多樣化的音景和音樂。Lyria 可讓使用者根據文字提示生成高品質的器樂音樂。

如要在控制台中探索這個模型,請參閱 Model Garden 中的 Lyria 模型資訊卡 (可透過「Media Studio」分頁存取)。

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

在 Colab 中試用 Lyria

支援的型號

Lyria API 支援下列模式:

  • lyria-002

HTTP 要求

curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  https://LOCATION[-aiplatform.googleapis.com/v1/projects/](https://-aiplatform.googleapis.com/v1/projects/)PROJECT_ID/locations/LOCATION/publishers/google/models/lyria-002:predict \
  -d '{
    "instances": [
      {
        "prompt": "string",
        "negative_prompt": "string", // Optional
        "seed": 0 // Optional. Cannot be used with sample_count.
      }
    ],
    "parameters": {
      "sample_count": 1 // Optional. Cannot be used with seed.
    }
  }'

請為 Lyria 模型使用下列參數。詳情請參閱 Lyria Model Garden 資訊卡詳細資料。

參數

prompt

(在 instances 物件中)

string

這是必要旗標,要產生音訊的美國英語 (en-us) 文字說明。

例如:「節奏快的活潑電子舞曲。」

negative_prompt

(在 instances 物件中)

string

(非必要) 說明要從產生的音訊中排除哪些內容。

示例:"vocals, slow tempo"

seed

(在 instances 物件中)

integer

(非必要) 用於確定性產生的種子。如果提供,模型會嘗試在相同提示和其他參數下產生相同的音訊。

無法在同一項要求中與 sample_count 搭配使用。

範例:12345

sample_count

(在 parameters 物件中)

integer

(非必要) 要產生的音訊樣本數量。如未指定且未使用種子,預設值為 1。

無法在同一項要求中與 seed 搭配使用。

範例:2

要求範例

使用以下要求,根據文字提示生成器樂:

文字轉音生成要求

curl

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/lyria-002:predict \
-d '{
  "instances": [
    {
      "prompt": "A calm acoustic folk song with a gentle guitar melody and soft strings.",
      "negative_prompt": "drums, electric guitar",
      "seed": 98765
    }
  ],
  "parameters": {}
}'

JSON

本範例使用 seed 產生可重現的輸出內容。


{
  "instances": [
    {
      "prompt": "A calm acoustic folk song with a gentle guitar melody and soft strings.",
      "negative_prompt": "drums, electric guitar",
      "seed": 98765
    }
  ],
  "parameters": {}
}

含有 sample_count 的 JSON

本範例使用 sample_count 產生多個樣本。

如要使用 Lyria API 測試文字提示,請將 POST 要求傳送至發布者模型端點。以下範例會從 instances 物件中省略 seed,並使用 parameters 物件中的 sample_count 產生多個樣本。


{
  "instances": [
    {
      "prompt": "A calm acoustic folk song with a gentle guitar melody and soft strings.",
      "negative_prompt": "drums, electric guitar"
    }
  ],
  "parameters": {
    "sample_count": 2
  }
}

回應主體

成功的請求會傳回 JSON 物件,其中包含產生的音訊資料。每個產生的音訊片段長度為 30 秒,並以 48kHz 取樣率的 WAV 音訊檔案提供。

{
  "predictions": [
    {
      "audioContent": "BASE64_ENCODED_WAV_STRING_SAMPLE_1",
      "mimeType": "audio/wav"
    }
    // Additional audio samples will be listed here if sample_count > 1
    // e.g.,
    //{"audioContent": "BASE64_ENCODED_WAV_STRING_SAMPLE_2",
    // "mimeType": "audio/wav"
    //}
  ],
  "deployedModelId": "xxxxxxxxxxxxxxx", // Actual ID may vary based on deployment
  "model": "projects/PROJECT_ID/locations/LOCATION/publishers/google/models/lyria-002",
  "modelDisplayName": "Lyria 2"
}
回應元素
predictions

array

產生的音訊樣本陣列。陣列中的每個物件都代表一個音訊片段。

predictions[].audioContent

string

產生的 WAV 音訊資料的 Base64 編碼字串。

predictions[].mimeType

string

音訊資料的 MIME 類型。對 Lyria 來說,就是 "audio/wav"

deployedModelId

string

處理要求的已部署模型 ID (如果端點類型適用)。

model

string

處理要求的模型完整資源名稱。

modelDisplayName

string

模型的顯示名稱。

最佳做法和限制

如要瞭解提示、語言支援 (僅限美國英語提示)、產生時間、輸出格式 (WAV、48 kHz、30 秒器樂片段)、安全措施和部署資訊的詳細最佳做法,請參閱 Lyria 模型資訊卡。

重點:

  • 詳細提示:通常可產生更優質的音訊。
  • 指定:類型、情境、樂器、節奏。
  • 負面提示:使用 negative_prompt 排除元素。
  • 輸出內容:30 秒的 WAV 音訊片段,48 kHz,僅含樂器。
  • 安全性:會套用內容安全性篩選器、朗誦檢查、藝人意圖檢查和 SynthID 浮水印。

定價

Lyria 2 的使用費用為每 30 秒產生的輸出音樂 $0.06 美元。詳情請參閱「Vertex AI 定價」。

更多資訊

  • 進一步瞭解 Vertex AI 的生成式 AI
  • 如需 Lyria 的總覽,請參閱 Model Garden (Media Studio) 中的模型資訊卡。

後續步驟