Membuat musik dengan Lyria 3
Lyria 3 adalah rangkaian model pembuatan musik Google, yang tersedia melalui Gemini API. Dengan Lyria 3, Anda dapat membuat audio stereo 44, 1 kHz berkualitas tinggi dari perintah teks atau dari gambar. Model ini memberikan koherensi struktural, termasuk vokal, lirik yang diberi stempel waktu, dan aransemen instrumental lengkap.
Rangkaian Lyria 3 mencakup dua model:
| Model | ID Model | Paling cocok untuk | Durasi | Output |
|---|---|---|---|---|
| Lyria 3 Clip | lyria-3-clip-preview |
Klip pendek, loop, pratinjau | 30 detik | MP3 |
| Lyria 3 Pro | lyria-3-pro-preview |
Lagu berdurasi penuh dengan bait, chorus, bridge | Beberapa menit (dapat dikontrol menggunakan perintah) | MP3 |
Kedua model dapat digunakan menggunakan Interactions API, yang mendukung input multimodal (teks dan gambar), dan menghasilkan audio stereo 44,1 kHz dengan fidelitas tinggi.
Membuat klip musik
Model Lyria 3 Clip selalu membuat klip 30 detik. Untuk membuat klip, panggil metode interactions.create dengan perintah teks. Respons selalu menyertakan lirik dan struktur lagu yang dibuat bersama dengan audio dalam skema 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."
}'
Membuat lagu berdurasi penuh
Gunakan model lyria-3-pro-preview untuk membuat lagu berdurasi penuh yang berlangsung selama beberapa menit. Model Pro memahami struktur musik dan dapat membuat komposisi dengan bait, chorus, dan bridge yang berbeda. Anda dapat memengaruhi
durasi dengan menentukannya dalam perintah (misalnya, "buat lagu 2 menit") atau dengan
menggunakan stempel waktu untuk menentukan struktur.
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."
}'
Memilih format output
Secara default, model Lyria 3 membuat audio dalam format MP3. Untuk Lyria 3 Pro, Anda juga dapat meminta output dalam format WAV dengan menetapkan 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"
}'
Mengurai respons
Respons dari Lyria 3 berisi beberapa blok konten dalam skema steps.
Interaksi menampilkan urutan langkah, dengan langkah model_output berisi konten yang dibuat.
Blok konten teks berisi lirik yang dibuat atau deskripsi JSON dari struktur lagu.
Blok konten dengan jenis audio berisi data audio berenkode 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
Membuat musik dari gambar
Lyria 3 mendukung input multimodal — Anda dapat memberikan hingga 10 gambar bersama dengan perintah teks dalam daftar input dan model akan membuat musik yang terinspirasi dari konten visual.
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"}
]
}'
Menyediakan lirik kustom
Anda dapat menulis lirik sendiri dan menyertakannya dalam perintah. Gunakan tag bagian seperti [Verse], [Chorus], dan [Bridge] untuk membantu model memahami struktur lagu:
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: ..."
}'
Mengontrol waktu dan struktur
Anda dapat menentukan dengan tepat apa yang terjadi pada momen tertentu dalam lagu menggunakan stempel waktu. Hal ini berguna untuk mengontrol kapan instrumen masuk, kapan lirik disampaikan, dan bagaimana lagu berjalan:
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: ..."
}'
Membuat trek instrumental
Untuk musik latar, soundtrack game, atau kasus penggunaan apa pun yang tidak memerlukan vokal, Anda dapat meminta model untuk menghasilkan trek khusus instrumental:
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."
}'
Membuat musik dalam berbagai bahasa
Lyria 3 membuat lirik dalam bahasa perintah Anda. Untuk membuat lagu dengan lirik bahasa Prancis, tulis perintah Anda dalam bahasa Prancis. Model ini menyesuaikan gaya vokal dan pengucapannya agar sesuai dengan bahasa.
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."
}'
Kecerdasan model
Lyria 3 menganalisis proses perintah Anda saat model mempertimbangkan struktur musik (intro, bait, chorus, bridge, dll.) berdasarkan perintah Anda. Hal ini terjadi sebelum audio dibuat dan memastikan koherensi struktural dan musikalitas.
Panduan penulisan perintah
Makin spesifik perintah Anda, makin bagus hasilnya. Berikut hal-hal yang dapat Anda sertakan untuk memandu pembuatan:
- Genre: Tentukan genre atau campuran genre (misalnya, "lo-fi hip hop", "jazz fusion", "cinematic orchestral").
- Instrumen: Sebutkan instrumen tertentu (misalnya, "piano Fender Rhodes", "gitar slide", "mesin drum TR-808").
- BPM: Tetapkan tempo (misalnya, "120 BPM", "tempo lambat sekitar 70 BPM").
- Kunci/Skala: Tentukan kunci musik (misalnya, "dalam G mayor", "D minor").
- Suasana hati dan atmosfer: Gunakan kata sifat deskriptif (misalnya, "nostalgia", "agresif", "halus", "melamun").
- Struktur: Gunakan tag seperti
[Verse],[Chorus],[Bridge],[Intro],[Outro]atau stempel waktu untuk mengontrol perkembangan lagu. - Durasi: Model Klip selalu menghasilkan klip 30 detik. Untuk model Pro, tentukan panjang yang diinginkan dalam perintah Anda (misalnya, "buat lagu 2 menit") atau gunakan stempel waktu untuk mengontrol durasi.
Contoh perintah
Berikut beberapa contoh perintah yang efektif:
"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."
Praktik terbaik
- Lakukan iterasi dengan Klip terlebih dahulu. Gunakan model
lyria-3-clip-previewyang lebih cepat untuk bereksperimen dengan perintah sebelum berkomitmen pada pembuatan berdurasi penuh denganlyria-3-pro-preview. - Jadilah spesifik. Perintah yang tidak jelas akan menghasilkan hasil yang umum. Sebutkan instrumen, BPM, kunci, suasana hati, dan struktur untuk output terbaik.
- Sesuaikan bahasa Anda. Buat perintah dalam bahasa yang Anda inginkan untuk lirik.
- Gunakan tag bagian. Tag
[Verse],[Chorus],[Bridge]memberikan struktur yang jelas kepada model untuk diikuti. - Pisahkan lirik dari petunjuk. Saat memberikan lirik kustom, pisahkan lirik tersebut dengan jelas dari petunjuk arah musik Anda.
Batasan
- Keamanan: Semua perintah diperiksa oleh filter keamanan. Perintah yang memicu filter akan diblokir. Hal ini mencakup perintah yang meminta suara artis tertentu atau pembuatan lirik yang dilindungi hak cipta.
- Watermarking: Semua audio yang dibuat menyertakan watermark audio SynthID untuk identifikasi. Watermark ini tidak terlihat oleh telinga manusia dan tidak memengaruhi pengalaman mendengarkan.
- Pengeditan multi-turn: Pembuatan musik adalah proses satu kali. Pengeditan berulang atau penyempurnaan klip yang dibuat melalui beberapa perintah tidak didukung dalam versi Lyria 3 saat ini.
- Panjang: Model Klip selalu membuat klip 30 detik. Model Pro membuat lagu yang berlangsung selama beberapa menit; durasi yang tepat dapat dipengaruhi melalui perintah Anda.
- Determinisme: Hasil dapat bervariasi antar-panggilan, bahkan dengan perintah yang sama.
Langkah berikutnya
- Periksa harga untuk model Lyria 3,
- Coba pembuatan musik streaming real-time dengan Lyria RealTime,
- Buat percakapan multi-pembicara dengan model TTS,
- Temukan cara membuat gambar atau video,
- Cari tahu cara Gemini dapat memahami file audio,
- Lakukan percakapan real-time dengan Gemini menggunakan the Live API.