יצירת מוזיקה באמצעות Lyria 3
Lyria 3 היא משפחת המודלים של Google ליצירת מוזיקה, שזמינה דרך Gemini API. עם Lyria 3, אתם יכולים ליצור אודיו סטריאו באיכות גבוהה של 44.1 kHz מהנחיות טקסט או מתמונות. המודלים האלה מספקים קוהרנטיות מבנית, כולל שירה, מילים מתוזמנות ועיבודים מלאים של כלי נגינה.
משפחת Lyria 3 כוללת שני מודלים:
| דגם | מזהה דגם | הכי טוב עבור | משך | פלט |
|---|---|---|---|---|
| Lyria 3 Clip | lyria-3-clip-preview |
קליפים קצרים, לופים, תצוגות מקדימות | 30 שניות | MP3 |
| Lyria 3 Pro | lyria-3-pro-preview |
שירים באורך מלא עם בתים, פזמונים וגשרים | כמה דקות (אפשר לשלוט בזה באמצעות הנחיה) | MP3 |
אפשר להשתמש בשני המודלים באמצעות Interactions API החדש, שתומך בקלט מולטי-מודאלי (טקסט ותמונות) ומפיק אודיו סטריאו באיכות גבוהה של 44.1kHz.
יצירת קליפ מוזיקה
מודל Lyria 3 Clip תמיד יוצר קליפ באורך 30 שניות. כדי ליצור קליפ, קוראים ל-method interactions.create עם הנחיית טקסט. התשובה תמיד כוללת את המילים שנוצרו ואת מבנה השיר לצד האודיו בסכימה steps.
Python
import base64
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="lyria-3-clip-preview",
input="Create a 30-second cheerful acoustic folk song with guitar and harmonica.",
)
for step in interaction.steps:
if step.type == "model_output":
for content_block in step.content:
if content_block.type == "audio":
print(f"Generated audio with mime_type: {content_block.mime_type}")
with open("music.mp3", "wb") as f:
f.write(base64.b64decode(content_block.data))
elif content_block.type == "text":
print(f"Lyrics: {content_block.text}")
JavaScript
import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: 'lyria-3-clip-preview',
input: 'Create a 30-second cheerful acoustic folk song with ' +
'guitar and harmonica.',
});
for (const step of interaction.steps) {
if (step.type === 'model_output') {
for (const contentBlock of step.content) {
if (contentBlock.type === 'audio') {
console.log(`Generated audio with mime_type: ${contentBlock.mimeType}`);
fs.writeFileSync('music.mp3', Buffer.from(contentBlock.data, 'base64'));
} else if (contentBlock.type === 'text') {
console.log(`Lyrics: ${contentBlock.text}`);
}
}
}
}
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"model": "lyria-3-clip-preview",
"input": "Create a 30-second cheerful acoustic folk song with guitar and harmonica."
}'
יצירת שיר באורך מלא
אפשר להשתמש במודל lyria-3-pro-preview כדי ליצור שירים באורך מלא שנמשכים כמה דקות. מודל Pro מבין את המבנה המוזיקלי ויכול ליצור קומפוזיציות עם בתים, פזמונים וגשרים מובחנים. אפשר להשפיע על משך השיר על ידי ציון משך השיר בהנחיה (לדוגמה, 'צור שיר באורך 2 דקות') או על ידי שימוש בחותמות זמן כדי להגדיר את המבנה.
Python
interaction = client.interactions.create(
model="lyria-3-pro-preview",
input="An epic cinematic orchestral piece about a journey home. Starts with a solo piano intro, builds through sweeping strings, and climaxes with a massive wall of sound.",
)
JavaScript
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: 'An epic cinematic orchestral piece about a journey home. ' +
'Starts with a solo piano intro, builds through sweeping ' +
'strings, and climaxes with a massive wall of sound.',
});
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"model": "lyria-3-pro-preview",
"input": "An epic cinematic orchestral piece about a journey home. Starts with a solo piano intro, builds through sweeping strings, and climaxes with a massive wall of sound."
}'
בחירת פורמט הפלט
כברירת מחדל, מודלים של Lyria 3 יוצרים אודיו בפורמט MP3. ב-Lyria 3 Pro, אפשר גם לבקש את הפלט בפורמט WAV על ידי הגדרת response_mime_type.
Python
interaction = client.interactions.create(
model="lyria-3-pro-preview",
input="An atmospheric ambient track.",
response_modalities=["audio", "text"],
response_mime_type="audio/wav",
)
JavaScript
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: 'An atmospheric ambient track.',
responseModalities: ["audio", "text"],
responseMimeType: "audio/wav",
});
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "lyria-3-pro-preview",
"input": "An atmospheric ambient track.",
"responseModalities": ["audio", "text"],
"responseMimeType": "audio/wav"
}'
ניתוח התשובה
התשובה מ-Lyria 3 מכילה כמה בלוקים של תוכן בסכימה steps.
האינטראקציות מחזירות רצף של שלבים, שבהם model_output השלבים מכילים את התוכן שנוצר.
בלוקים של תוכן טקסט מכילים את המילים שנוצרו או תיאור JSON של מבנה השיר.
בלוקי תוכן עם סוג audio מכילים את נתוני האודיו בקידוד base64.
Python
lyrics = []
audio_data = None
for step in interaction.steps:
if step.type == "model_output":
for content_block in step.content:
if content_block.type == "audio":
audio_data = base64.b64decode(content_block.data)
elif content_block.type == "text":
lyrics.append(content_block.text)
if lyrics:
print("Lyrics:\n" + "\n".join(lyrics))
if audio_data:
with open("output.mp3", "wb") as f:
f.write(audio_data)
JavaScript
const lyrics = [];
let audioData = null;
for (const step of interaction.steps) {
if (step.type === 'model_output') {
for (const contentBlock of step.content) {
if (contentBlock.type === 'audio') {
audioData = Buffer.from(contentBlock.data, 'base64');
} else if (contentBlock.type === 'text') {
lyrics.push(contentBlock.text);
}
}
}
}
if (lyrics.length) {
console.log("Lyrics:\n" + lyrics.join("\n"));
}
if (audioData) {
fs.writeFileSync("output.mp3", audioData);
}
REST
# The output from the REST API is a JSON object containing base64 encoded data.
# You can extract the text or the audio data using a tool like jq.
# To extract the audio and save it to a file:
curl ... | jq -r '.steps[] | select(.type=="model_output") | .content[] | select(.type=="audio") | .data' | base64 -d > output.mp3
יצירת מוזיקה מתמונות
Lyria 3 תומך בקלט מולטימודאלי – אפשר לספק עד 10 תמונות לצד הנחיית הטקסט ברשימה input, והמודל ייצור מוזיקה בהשראת התוכן החזותי.
Python
uploaded_image = client.files.upload(file="desert_sunset.jpg")
response = client.interactions.create(
model="lyria-3-pro-preview",
input=[
{"type": "text", "text": "An atmospheric ambient track inspired by the mood and colors in this image."},
{
"type": "image",
"uri": uploaded_image.uri,
"mime_type": uploaded_image.mime_type
}
],
)
JavaScript
const uploadedImage = await client.files.upload({
file: "desert_sunset.jpg",
config: { mimeType: "image/jpeg" }
});
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: [
{ type: 'text', text: 'An atmospheric ambient track inspired by the mood and colors in this image.' },
{
type: 'image',
uri: uploadedImage.uri,
mimeType: uploadedImage.mimeType
}
],
});
REST
# First upload the image using the Files API, then use the URI:
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "lyria-3-pro-preview",
"input": [
{"type": "text", "text": "An atmospheric ambient track inspired by the mood and colors in this image."},
{"type": "image", "uri": "YOUR_FILE_URI", "mime_type": "image/jpeg"}
]
}'
ציון מילות שיר מותאמות אישית
אתם יכולים לכתוב מילים משלכם ולכלול אותן בהנחיה. כדי לעזור למודל להבין את מבנה השיר, כדאי להשתמש בתגי קטע כמו [Verse], [Chorus] ו-[Bridge]:
Python
prompt = """
Create a dreamy indie pop song with the following lyrics:
[Verse 1]
Walking through the neon glow,
city lights reflect below,
every shadow tells a story,
every corner, fading glory.
[Chorus]
We are the echoes in the night,
burning brighter than the light,
hold on tight, don't let me go,
we are the echoes down below.
[Verse 2]
Footsteps lost on empty streets,
rhythms sync to heartbeats,
whispers carried by the breeze,
dancing through the autumn leaves.
"""
interaction = client.interactions.create(
model="lyria-3-pro-preview",
input=prompt,
)
JavaScript
const prompt = `
Create a dreamy indie pop song with the following lyrics:
[Verse 1]
Walking through the neon glow,
city lights reflect below,
every shadow tells a story,
every corner, fading glory.
[Chorus]
We are the echoes in the night,
burning brighter than the light,
hold on tight, don't let me go,
we are the echoes down below.
[Verse 2]
Footsteps lost on empty streets,
rhythms sync to heartbeats,
whispers carried by the breeze,
dancing through the autumn leaves.
`;
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: prompt,
});
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "lyria-3-pro-preview",
"input": "Create a dreamy indie pop song with the following lyrics: ..."
}'
שליטה בתזמון ובמבנה
אתם יכולים לציין בדיוק מה קורה ברגעים מסוימים בשיר באמצעות חותמות זמן. התכונה הזו שימושית כדי לקבוע מתי כלי נגינה נכנסים, מתי המילים מוצגות ואיך השיר מתקדם:
Python
prompt = """
[0:00 - 0:10] Intro: Begin with a soft lo-fi beat and muffled
vinyl crackle.
[0:10 - 0:30] Verse 1: Add a warm Fender Rhodes piano melody
and gentle vocals singing about a rainy morning.
[0:30 - 0:50] Chorus: Full band with upbeat drums and soaring
synth leads. The lyrics are hopeful and uplifting.
[0:50 - 1:00] Outro: Fade out with the piano melody alone.
"""
interaction = client.interactions.create(
model="lyria-3-pro-preview",
input=prompt,
)
JavaScript
const prompt = `
[0:00 - 0:10] Intro: Begin with a soft lo-fi beat and muffled
vinyl crackle.
[0:10 - 0:30] Verse 1: Add a warm Fender Rhodes piano melody
and gentle vocals singing about a rainy morning.
[0:30 - 0:50] Chorus: Full band with upbeat drums and soaring
synth leads. The lyrics are hopeful and uplifting.
[0:50 - 1:00] Outro: Fade out with the piano melody alone.
`;
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: prompt,
});
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "lyria-3-pro-preview",
"input": "[0:00 - 0:10] Intro: ..."
}'
יצירת טראקים אינסטרומנטליים
כדי ליצור מוזיקת רקע, פסקולים למשחקים או כל מקרה שימוש אחר שלא דורש שירה, אפשר להנחות את המודל ליצור טראקים אינסטרומנטליים בלבד:
Python
interaction = client.interactions.create(
model="lyria-3-clip-preview",
input="A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals.",
)
JavaScript
const interaction = await client.interactions.create({
model: 'lyria-3-clip-preview',
input: 'A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals.',
});
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "lyria-3-clip-preview",
"input": "A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals."
}'
יצירת מוזיקה בשפות שונות
Lyria 3 יוצר מילים לשיר בשפה שבה ניתנה ההנחיה. כדי ליצור שיר עם מילים בצרפתית, כותבים את ההנחיה בצרפתית. המודל מתאים את סגנון הקול וההגייה שלו לשפה.
Python
interaction = client.interactions.create(
model="lyria-3-pro-preview",
input="Crée une chanson pop romantique en français sur un coucher de soleil à Paris. Utilise du piano et de la guitare acoustique.",
)
JavaScript
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: 'Crée une chanson pop romantique en français sur un coucher de soleil à Paris. Utilise du piano et de la guitare acoustique.',
});
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "lyria-3-pro-preview",
"input": "Crée une chanson pop romantique en français sur un coucher de soleil à Paris. Utilise du piano et de la guitare acoustique."
}'
הבינה של המודל
מודל Lyria 3 מנתח את תהליך ההנחיה שבו המודל מנמק את המבנה המוזיקלי (פתיחה, בית, פזמון, מעבר וכו') על סמך ההנחיה שלכם. התהליך הזה מתרחש לפני יצירת האודיו, והוא מבטיח עקביות מבנית ומוזיקליות.
מדריך לכתיבת הנחיות
ככל שההנחיה תהיה ספציפית יותר, כך התוצאות יהיו טובות יותר. אלה ההנחיות שאפשר לתת כדי לשפר את התוצאה:
- Genre: מציינים ז'אנר או שילוב של ז'אנרים (לדוגמה, lo-fi hip hop, jazz fusion, cinematic orchestral).
- כלי נגינה: מציינים כלי נגינה ספציפיים (למשל, "פסנתר Fender Rhodes", "גיטרת סלייד", "מכונת תופים TR-808").
- BPM: הגדרת הטמפו (למשל, 120 BPM, slow tempo around 70 BPM).
- טון/סולם: מציינים טון מוזיקלי (לדוגמה, "בסולם סול מז'ור", "בסולם רה מינור").
- מצב רוח ואווירה: השתמשו בשמות תואר תיאוריים (למשל, "נוסטלגי", "אגרסיבי", "שמימי", "חלומות").
- מבנה: אפשר להשתמש בתגים כמו
[Verse],[Chorus],[Bridge],[Intro],[Outro]או בחותמות זמן כדי לשלוט בהתקדמות השיר. - משך: מודל הקליפים תמיד יוצר קליפים באורך 30 שניות. במודל Pro, צריך לציין את האורך הרצוי בהנחיה (לדוגמה, 'צור שיר באורך 2 דקות') או להשתמש בחותמות זמן כדי לשלוט במשך.
הנחיות לדוגמה
הנה כמה דוגמאות להנחיות יעילות:
"A 30-second lofi hip hop beat with dusty vinyl crackle, mellow Rhodes piano chords, a slow boom-bap drum pattern at 85 BPM, and a jazzy upright bass line. Instrumental only.""An upbeat, feel-good pop song in G major at 120 BPM with bright acoustic guitar strumming, claps, and warm vocal harmonies about a summer road trip.""A dark, atmospheric trap beat at 140 BPM with heavy 808 bass, eerie synth pads, sharp hi-hats, and a haunting vocal sample. In D minor."
שיטות מומלצות
- כדאי להתחיל עם קליפ. כדאי להשתמש במודל המהיר יותר
lyria-3-clip-previewכדי להתנסות בהנחיות לפני שמתחייבים ליצירה באורך מלא באמצעותlyria-3-pro-preview. - ספציפיות היא שם המשחק. הנחיות מעורפלות מניבות תוצאות גנריות. כדי לקבל את התוצאה הכי טובה, כדאי לציין כלי נגינה, BPM, סולם, מצב רוח ומבנה.
- הגדרת השפה מזינים את ההנחיה בשפה שבה רוצים לכתוב את המילים.
- כדאי להשתמש בתגי קטע. תגי
[Verse], [Chorus]ו-[Bridge]מספקים למודל מבנה ברור לפעולה. - מפרידים בין מילות השיר להוראות. כשמספקים מילים בהתאמה אישית, צריך להפריד אותן בבירור מההוראות לגבי המוזיקה.
מגבלות
- בטיחות: כל ההנחיות נבדקות על ידי מסנני בטיחות. הנחיות שמפעילות את המסננים ייחסמו. זה כולל הנחיות שמבקשות קולות ספציפיים של אומנים או יצירה של מילות שירים שמוגנות בזכויות יוצרים.
- סימני מים: כל האודיו שנוצר כולל סימן מים באודיו של SynthID לצורך זיהוי. סימן המים הזה לא נשמע לאוזן אנושית ולא משפיע על חוויית ההאזנה.
- עריכה בכמה שלבים: יצירת מוזיקה היא תהליך חד-שלבי. בגרסה הנוכחית של Lyria 3 אין תמיכה בעריכה איטרטיבית או בשיפור של קליפ שנוצר באמצעות כמה הנחיות.
- אורך: מודל הקליפים תמיד יוצר קליפים באורך 30 שניות. מודל Pro יוצר שירים באורך של כמה דקות. אפשר להשפיע על האורך המדויק באמצעות ההנחיה.
- דטרמיניזם: התוצאות עשויות להיות שונות בין שיחות, גם אם משתמשים באותה הנחיה.
המאמרים הבאים
- כדאי לעיין בתמחור של מודלים של Lyria 3,
- כדאי לנסות יצירת מוזיקה בזמן אמת בסטרימינג עם Lyria RealTime,
- יצירת שיחות עם כמה דוברים באמצעות מודלים של TTS,
- איך יוצרים תמונות או סרטונים
- איך Gemini יכול להבין קובצי אודיו,
- מנהלים שיחה בזמן אמת עם Gemini באמצעות Live API.