ساخت موسیقی با Lyria 3
Lyria 3 خانوادهای از مدلهای تولید موسیقی گوگل است که از طریق Gemini API در دسترس است. با Lyria 3، میتوانید صدای استریو با کیفیت بالا و فرکانس ۴۴.۱ کیلوهرتز را از متن یا تصاویر تولید کنید. این مدلها انسجام ساختاری، از جمله آواز، اشعار زمانبندی شده و تنظیم کامل سازها را ارائه میدهند.
خانواده Lyria 3 شامل دو مدل است:
| مدل | شناسه مدل | بهترین برای | مدت زمان | خروجی |
|---|---|---|---|---|
| کلیپ لیریا ۳ | lyria-3-clip-preview | کلیپهای کوتاه، حلقهها، پیشنمایشها | ۳۰ ثانیه | ام پی۳ |
| لیریا ۳ پرو | lyria-3-pro-preview | آهنگهای کامل با اشعار، همخوانیها، پلها | چند دقیقه (با استفاده از اعلان قابل کنترل است) | ام پی۳ |
هر دو مدل میتوانند با استفاده از API جدید Interactions ، که از ورودیهای چندوجهی (متن و تصویر) پشتیبانی میکند، مورد استفاده قرار گیرند و صدای استریو با کیفیت بالا و وضوح ۴۴.۱ کیلوهرتز تولید کنند.
یک کلیپ موسیقی تولید کنید
مدل Lyria 3 Clip همیشه یک کلیپ 30 ثانیهای تولید میکند. برای تولید یک کلیپ، متد interactions.create را با یک اعلان متنی فراخوانی کنید. پاسخ همیشه شامل اشعار تولید شده و ساختار آهنگ در کنار صدا در طرحواره steps است.
پایتون
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}")
جاوا اسکریپت
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}`);
}
}
}
}
استراحت
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 ساختار موسیقی را درک میکند و میتواند آهنگهایی با بندها، ترجیعبندها و پلهای متمایز ایجاد کند. شما میتوانید با مشخص کردن مدت زمان در اعلان خود (مثلاً "ایجاد یک آهنگ ۲ دقیقهای") یا با استفاده از مهرهای زمانی برای تعریف ساختار، بر مدت زمان تأثیر بگذارید.
پایتون
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.",
)
جاوا اسکریپت
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.',
});
استراحت
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، میتوانید با تنظیم response_mime_type ، خروجی را با فرمت WAV نیز درخواست کنید.
پایتون
interaction = client.interactions.create(
model="lyria-3-pro-preview",
input="An atmospheric ambient track.",
response_modalities=["audio", "text"],
response_mime_type="audio/wav",
)
جاوا اسکریپت
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: 'An atmospheric ambient track.',
responseModalities: ["audio", "text"],
responseMimeType: "audio/wav",
});
استراحت
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 است. Interactions توالی مراحل را برمیگرداند، که در آن مراحل model_output حاوی محتوای تولید شده هستند. بلوکهای محتوای متنی حاوی اشعار تولید شده یا توضیحات JSON از ساختار آهنگ هستند. بلوکهای محتوا با نوع audio حاوی دادههای صوتی کدگذاری شده base64 هستند.
پایتون
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)
جاوا اسکریپت
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);
}
استراحت
# 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 ارائه دهید و مدل با الهام از محتوای بصری، موسیقی میسازد.
پایتون
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
}
],
)
جاوا اسکریپت
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
}
],
});
استراحت
# 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] برای کمک به مدل در درک ساختار آهنگ استفاده کنید:
پایتون
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,
)
جاوا اسکریپت
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,
});
استراحت
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: ..."
}'
کنترل زمان و ساختار
شما میتوانید با استفاده از مهرهای زمانی دقیقاً مشخص کنید که در لحظات خاص آهنگ چه اتفاقی میافتد. این برای کنترل زمان ورود سازها، زمان اجرای اشعار و نحوه پیشرفت آهنگ مفید است:
پایتون
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,
)
جاوا اسکریپت
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,
});
استراحت
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: ..."
}'
آهنگهای بیکلام تولید کنید
برای موسیقی پسزمینه، موسیقی متن بازی یا هر مورد استفادهای که در آن نیازی به آواز نیست، میتوانید مدل را طوری تنظیم کنید که فقط آهنگهای بیکلام تولید کند:
پایتون
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.",
)
جاوا اسکریپت
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.',
});
استراحت
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 اشعار را به زبان سوال شما تولید میکند. برای تولید آهنگی با اشعار فرانسوی، سوال خود را به زبان فرانسوی بنویسید. این مدل سبک صوتی و تلفظ خود را برای مطابقت با زبان تطبیق میدهد.
پایتون
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.",
)
جاوا اسکریپت
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.',
});
استراحت
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 فرآیند اجرای شما را تجزیه و تحلیل میکند، به این صورت که مدل بر اساس ساختار موسیقی (مقدمه، مصراع، همخوانی، پل و غیره) بر اساس اجرای شما استدلال میکند. این کار قبل از تولید صدا انجام میشود و انسجام ساختاری و موسیقیایی بودن را تضمین میکند.
راهنمای راهنمایی
هرچه درخواست شما خاصتر باشد، نتایج بهتری خواهید گرفت. در اینجا مواردی که میتوانید برای هدایت نسل جدید در نظر بگیرید، آورده شده است:
- ژانر : یک ژانر یا ترکیبی از ژانرها را مشخص کنید (مثلاً «هیپ هاپ لو-فای»، «جاز فیوژن»، «ارکستر سینمایی»).
- سازها : نام سازهای خاص را بنویسید (مثلاً «پیانوی فندر رودز»، «گیتار اسلاید»، «ماشین درام TR-808»).
- BPM : سرعت را تنظیم کنید (مثلاً "120 BPM"، "سرعت آهسته حدود 70 BPM").
- کلید/گام : یک گام موسیقی مشخص کنید (مثلاً «در سل ماژور»، «رِ مینور»).
- حال و هوا و فضا : از صفات توصیفی استفاده کنید (مثلاً «نوستالژیک»، «پرخاشگرانه»، «اثیری»، «رویایی»).
- ساختار : از برچسبهایی مانند
[Verse]،[Chorus]،[Bridge]،[Intro]،[Outro]یا نشانگرهای زمانی برای کنترل روند آهنگ استفاده کنید. - مدت زمان : مدل کلیپ همیشه کلیپهای ۳۰ ثانیهای تولید میکند. برای مدل پرو، مدت زمان مورد نظر را در اعلان خود مشخص کنید (مثلاً «ایجاد یک آهنگ ۲ دقیقهای») یا از مهرهای زمانی برای کنترل مدت زمان استفاده کنید.
مثالهای پیشنهادی
در اینجا چند نمونه از پیامهای انگیزشی مؤثر آورده شده است:
-
"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."
بهترین شیوهها
- ابتدا با Clip تکرار کنید. قبل از اینکه با
lyria-3-pro-previewبه تولید کامل فایلها بپردازید، از مدل سریعترlyria-3-clip-previewبرای آزمایش دستورات استفاده کنید. - دقیق باشید. دستورالعملهای مبهم نتایج کلی ایجاد میکنند. برای بهترین خروجی، سازها، ریتم، گام، حال و هوا و ساختار را ذکر کنید.
- زبان خود را مطابقت دهید. به زبانی که میخواهید متن آهنگ به آن باشد، درخواست دهید.
- از تگهای بخش استفاده کنید. تگهای
[Verse]،[Chorus]،[Bridge]به مدل ساختار واضحی برای دنبال کردن میدهند. - اشعار را از دستورالعملها جدا کنید. هنگام ارائه اشعار سفارشی، آنها را به وضوح از دستورالعملهای جهتگیری موسیقی خود جدا کنید.
محدودیتها
- ایمنی : همه درخواستها توسط فیلترهای ایمنی بررسی میشوند. درخواستهایی که فیلترها را فعال میکنند مسدود خواهند شد. این شامل درخواستهایی میشود که صدای هنرمند خاصی را درخواست میکنند یا اشعار دارای حق چاپ را تولید میکنند.
- واترمارک : تمام صداهای تولید شده شامل یک واترمارک صوتی SynthID برای شناسایی هستند. این واترمارک برای گوش انسان غیرقابل مشاهده است و بر تجربه شنیداری تأثیری نمیگذارد.
- ویرایش چند مرحلهای : تولید موسیقی یک فرآیند تک مرحلهای است. ویرایش یا اصلاح مکرر یک کلیپ تولید شده از طریق چندین دستور در نسخه فعلی Lyria 3 پشتیبانی نمیشود.
- مدت زمان : مدل کلیپ همیشه کلیپهای ۳۰ ثانیهای تولید میکند. مدل پرو آهنگهایی تولید میکند که چند دقیقه طول میکشند؛ مدت زمان دقیق را میتوان از طریق اعلان شما تغییر داد.
- جبرگرایی : نتایج ممکن است بین فراخوانیها، حتی با یک درخواست یکسان، متفاوت باشد.
قدم بعدی چیست؟
- قیمت مدلهای Lyria 3 را بررسی کنید،
- با Lyria RealTime ، تولید موسیقی به صورت آنلاین و استریم را امتحان کنید.
- مکالمات چند گوینده را با مدلهای TTS ایجاد کنید،
- کشف کنید که چگونه تصاویر یا ویدیوها را تولید کنید،
- دریابید که چگونه Gemini میتواند فایلهای صوتی را درک کند ،
- با استفاده از Live API با Gemini مکالمهای بلادرنگ داشته باشید.