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.1 kHz.
יצירת קליפ מוזיקה
מודל 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="A short instrumental acoustic guitar piece.",
)
generated_audio = interaction.output_audio
if generated_audio:
with open("music.mp3", "wb") as f:
f.write(base64.b64decode(generated_audio.data))
lyrics = interaction.output_text
if lyrics:
print(f"Lyrics:\n{lyrics}")
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: 'A short instrumental acoustic guitar piece.',
});
const generatedAudio = interaction.output_audio;
if (generatedAudio) {
fs.writeFileSync('music.mp3', Buffer.from(generatedAudio.data, 'base64'));
}
const lyrics = interaction.output_text;
if (lyrics) {
console.log(`Lyrics:\n${lyrics}`);
}
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": "A short instrumental acoustic guitar piece."
}'
אפשר לאחזר נתוני מוזיקה שנוצרו באמצעות המאפיין interaction.output_audio
שמחזיר את בלוק האודיו האחרון שנוצר. אפשר גם לאחזר את המילים והמבנה של השיר באמצעות המאפיין interaction.output_text. מידע נוסף על מאפייני נוחות מופיע במאמר סקירה כללית על אינטראקציות.
יצירת שיר באורך מלא
אפשר להשתמש במודל 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: 'A beautiful piano melody.',
});
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": "A beautiful piano melody."
}'
בחירת פורמט הפלט
כברירת מחדל, מודלים של Lyria 3 יוצרים אודיו בפורמט MP3. ב-Lyria 3 Pro, אפשר גם לבקש את הפלט בפורמט WAV על ידי הגדרת response_format.
Python
interaction = client.interactions.create(
model="lyria-3-pro-preview",
input="A beautiful piano melody.",
response_format={"type": "audio"},
)
JavaScript
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: 'A beautiful piano melody.',
response_format: {
type: 'audio',
},
});
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": "A beautiful piano melody.",
"response_format": {
"type": "audio"
}
}'
ניתוח התשובה
התשובה מ-Lyria 3 מכילה כמה בלוקים של תוכן בסכימה steps.
האינטראקציות מחזירות רצף של שלבים, כאשר השלבים model_output מכילים את התוכן שנוצר.
בלוקים של תוכן טקסט מכילים את המילים שנוצרו או תיאור JSON של מבנה השיר.
בלוקי תוכן עם סוג audio מכילים את נתוני האודיו בקידוד base64.
Python
lyrics = []
audio_data = None
generated_audio = interaction.output_audio
if generated_audio:
with open("output.mp3", "wb") as f:
f.write(base64.b64decode(generated_audio.data))
lyrics = interaction.output_text
if lyrics:
print(f"Lyrics:\n{lyrics}")
JavaScript
const lyrics = [];
let audioData = null;
const generatedAudio = interaction.output_audio;
if (generatedAudio) {
fs.writeFileSync("output.mp3", Buffer.from(generatedAudio.data, 'base64'));
}
const lyrics = interaction.output_text;
if (lyrics) {
console.log("Lyrics:\n" + lyrics);
}
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 הוא מורכב – הוא מכיל שלבים נפרדים ובלוקים של מילים (טקסט) ושירים (אודיו) שנוצרו – ולכן מאפייני הנוחות הם קיצור דרך מהיר ומומלץ.
עם זאת, אם רוצים שליטה מלאה ותכנותית בציר הזמן הגולמי של השלבים שמוחזרים על ידי השרת (למשל, רישום של בלוקים ספציפיים של תוכן בזמן שהם מתקבלים), אפשר להשתמש בשיטה steps במקום זאת:
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);
}
יצירת מוזיקה מתמונות
Lyria 3 תומך בקלט מולטי-מודאלי – אפשר לספק עד 10 תמונות לצד הנחייה טקסטואלית ברשימה input, והמודל ייצור מוזיקה בהשראת התוכן החזותי.
Python
import base64
with open("desert_sunset.jpg", "rb") as f:
image_bytes = f.read()
image_b64 = base64.b64encode(image_bytes).decode("utf-8")
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",
"mime_type": "image/jpeg",
"data": image_b64,
},
],
)
JavaScript
import * as fs from "fs";
const imageBytes = fs.readFileSync("desert_sunset.jpg").toString("base64");
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",
mime_type: "image/jpeg",
data: imageBytes,
},
],
});
REST
# Pass base64 encoded image data directly:
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", "mime_type": "image/jpeg", "data": "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wgALCAABAAEBAREA/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPxA="}
]
}'
ציון מילות שיר מותאמות אישית
אתם יכולים לכתוב מילים משלכם ולכלול אותן בהנחיה. כדי לעזור למודל להבין את מבנה השיר, אפשר להשתמש בתגי קטע כמו [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.