Lyria로 음악 생성하기

Lyria를 사용하여 프롬프트에서 새로운 음악 트랙을 생성할 수 있습니다. 지원되는 인터페이스에는 Cloud de Confiance 콘솔과 Gemini API API가 있습니다.

Agent Platform (Agent Platform Studio)에서 Lyria 사용해 보기

시작하기 전에

  1. In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance 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

  2. Enable the Gemini Enterprise Agent Platform API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  3. 환경에 대한 인증을 설정하세요.

    이 페이지의 샘플 사용 방법에 대한 탭을 선택하세요.

    콘솔

    콘솔 Cloud de Confiance 을 사용하여 Cloud de Confiance by S3NS 서비스 및 API에 액세스하는 경우 인증을 설정할 필요가 없습니다.

    REST

    로컬 개발 환경에서 이 페이지의 REST API 샘플을 사용하려면 gcloud CLI에 제공한 사용자 인증 정보를 사용합니다.

      Google Cloud CLI를 설치한 후 제휴 ID로 gcloud CLI에 로그인합니다.

    자세한 내용은 인증 문서의 REST 사용을 위한 인증 을 참조하세요. Cloud de Confiance

콘솔

  1. Cloud de Confiance 콘솔에서 Vertex AI Studio > 미디어 생성 > 미디어 생성 페이지로 이동합니다.

    스튜디오 생성

  2. 음악 을 클릭합니다.

  3. 작업 메뉴에서 텍스트-음악 을 선택합니다.

  4. 모델 메뉴에서 나열된 옵션 중에서 모델을 선택합니다.

  5. (선택사항) 입력 애셋 섹션에서 추가 를 클릭하여 이 요청의 애셋을 추가합니다.

  6. 프롬프트 상자에 생성할 음악을 설명하는 미국 영어 텍스트 프롬프트를 입력합니다.

  7. 실행 을 클릭합니다.

    생성된 오디오 클립은 미리 볼 수 있으며 WAV 파일로 다운로드할 수 있습니다.

Lyria 3 REST

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: Cloud de Confiance by S3NS 프로젝트 ID를 나타내는 문자열
  • MODEL_ID: 사용할 모델 ID를 나타내는 문자열입니다. 허용되는 값은 다음과 같습니다.

    • lyria-3-clip-preview
    • lyria-3-pro-preview
  • TEXT_PROMPT: 음악 생성을 안내하는 데 사용되는 텍스트 프롬프트
  • IMAGE_URI: 선택사항: 입력 이미지가 있는 Cloud Storage URI
  • IMAGE_DATABYTES: 선택사항: Base64로 인코딩된 입력 이미지

HTTP 메서드 및 URL:

POST https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions

JSON 요청 본문:

{
  "model": "MODEL_ID",
  "input": [
    {
      "type": "text",
      "text": "TEXT_PROMPT"
    },
    {
      "type": "image",
      "mime_type": "image/jpeg",
      "uri": "IMAGE_URI"
    },
    {
      "type": "image",
      "mime_type": "image/png",
      "data": "IMAGE_DATABYTES"
    },
  ]
}

요청을 보내려면 다음 옵션 중 하나를 선택합니다.

curl

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions"

PowerShell

요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/global/interactions" | Select-Object -Expand Content
요청은 작업 이름, 상태, 결과를 반환합니다.
{
  "status": "completed",
  "outputs": [
    {
      "text": "LYRICS",
      "type": "text"
    },
    {
      "text": "DESCRIPTION",
      "type": "text"
    },
    {
      "mime_type": "audio/mpeg",
      "data": "GENERATED_SONG_DATABYTES",
      "type": "audio"
    },
    {}
  ],
  "role": "model",
  "created": "CREATED_TIME",
  "updated": "UPDATE_TIME",
  "object": "interaction",
  "model": "lyria-3-pro-preview"
}

Lyria 2 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초입니다.

다음 단계