Lyria API

Lyria 是全新的基礎模型,可根據文字提示生成各種音景和樂曲,製作高品質音訊。使用者只要輸入文字提示,Lyria 就能生成高品質的純音樂。

如要在控制台中探索這個模型,請前往 Model Garden (可透過 Media Studio 分頁存取),查看 Lyria 模型資訊卡。

在 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": {}
}

JSON (含 sample_count)

本範例使用 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) 中的模型資訊卡。

後續步驟