יצירת מוזיקה באמצעות Lyria

אתם יכולים להשתמש ב-Lyria כדי ליצור טראקי מוזיקה חדשים באמצעות הנחיות. הממשקים הנתמכים כוללים את מסוף Cloud de Confiance ואת Gemini API.

נסה את Lyria בפלטפורמת Agent (Agent Platform Studio)

לפני שמתחילים

  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 כדי לגשת לשירותים ולממשקי ה-API של Cloud de Confiance by S3NS , לא צריך להגדיר אימות.

    REST

    כדי להשתמש בסביבת פיתוח מקומית בדוגמאות של API בארכיטקטורת REST שבדף הזה, צריך להשתמש בפרטי הכניסה שאתם נותנים ל-CLI של gcloud.

      התקינו את ה-CLI של Google Cloud ואז היכנסו ל-CLI של gcloud באמצעות הזהות המאוחדת שלכם.

    מידע נוסף מופיע במאמר אימות לשימוש ב-REST במסמכי האימות של Cloud de Confiance .

המסוף

  1. במסוף Cloud de Confiance , נכנסים לדף Agent Studio > Generate Media > Generate media.

    Generate studio

  2. לוחצים על מוזיקה.

  3. בתפריט Task, בוחרים באפשרות Text-to-music.

  4. בתפריט מודל, בוחרים מודל מבין האפשרויות שמופיעות.

  5. אופציונלי: בקטע נכסי קלט, לוחצים על הוספה כדי להוסיף נכס לבקשה הזו.

  6. בתיבה Prompt, מזינים באנגלית (ארה"ב) את הפרומפט הטקסטואלי שמתאר את המוזיקה שרוצים ליצור.

  7. לוחצים על Run.

    אפשר להאזין לקטעי האודיו שנוצרו בתצוגה מקדימה ולהוריד אותם כקובצי WAV.

Lyria 3 REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט.
  • ‫MODEL_ID: מחרוזת שמייצגת את מזהה המודל שבו רוצים להשתמש. אלה הערכים הקבילים:

    • lyria-3-clip-preview
    • lyria-3-pro-preview
  • ‫TEXT_PROMPT: הפרומפט הטקסטואלי שמשמש ליצירת המוזיקה.
  • ‫IMAGE_URI: אופציונלי: ה-URI של Cloud Storage שבו נמצאת תמונת הקלט.
  • ‫IMAGE_DATABYTES: אופציונלי: תמונת קלט בקידוד base64.

ה-method של ה-HTTP וכתובת ה-URL:

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

גוף בקשת JSON:

{
  "model": "MODEL_ID",
  "input": [
    {
      "type": "user_input",
      "content": [
        {
          "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/v1/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/v1/projects/PROJECT_ID/locations/global/interactions" | Select-Object -Expand Content
הבקשה מחזירה את מזהה האינטראקציה, הסטטוס והשלבים שנוצרו.
{
  "id": "INTERACTION_ID",
  "status": "completed",
  "created": "CREATED_TIME",
  "updated": "UPDATE_TIME",
  "steps": [
    {
      "type": "model_output",
      "content": [
        {
          "type": "text",
          "text": "LYRICS"
        }
      ]
    },
    {
      "type": "model_output",
      "content": [
        {
          "type": "text",
          "text": "DESCRIPTION"
        }
      ]
    },
    {
      "type": "model_output",
      "content": [
        {
          "type": "audio",
          "mime_type": "audio/mpeg",
          "data": "GENERATED_SONG_DATABYTES"
        }
      ]
    }
  ],
  "object": "interaction",
  "model": "lyria-3-pro-preview"
}

‫Lyria 2 REST

כדי לשלוח בקשה ליצירת מוזיקה, משתמשים ב-method‏ predict. התגובה תכיל ישירות את נתוני האודיו, בדרך כלל בקידוד base64 אם התגובה היא בפורמט JSON.

למידע נוסף על בקשות למודל lyria-002, עיינו במאמרי העזרה של ה-API של מודל lyria-002.

כדי ליצור מוזיקה, שולחים בקשת 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 שניות.

המאמרים הבאים