Lyria 3 adalah rangkaian model pembuatan musik Google, yang tersedia melalui Gemini API. Dengan Lyria 3, Anda dapat menghasilkan audio stereo berkualitas tinggi 44, 1 kHz dari perintah teks atau dari gambar. Model ini memberikan koherensi struktural, termasuk vokal, lirik yang disesuaikan waktunya, dan aransemen instrumental lengkap.
Rangkaian model Lyria 3 mencakup dua model:
| Model | ID Model | Paling cocok untuk | Durasi | Output |
|---|---|---|---|---|
| Klip Lyria 3 | lyria-3-clip-preview |
Klip pendek, loop, pratinjau | 30 detik | MP3 |
| Lyria 3 Pro | lyria-3-pro-preview |
Lagu berdurasi penuh dengan bait, refrein, dan jembatan | Beberapa menit (dapat dikontrol melalui perintah) | MP3 |
Kedua model dapat digunakan menggunakan metode generateContent standar dan
Interactions API baru, yang mendukung input multimodal (teks dan gambar), serta menghasilkan audio stereo fidelitas tinggi 44,1 kHz.
Membuat klip musik
Model Lyria 3 Clip selalu menghasilkan klip 30 detik. Untuk membuat klip, panggil metode generateContent dengan perintah teks. Respons selalu
mencakup lirik dan struktur lagu yang dihasilkan bersama dengan audio.
Python
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="lyria-3-clip-preview",
contents="Create a 30-second cheerful acoustic folk song with "
"guitar and harmonica.",
)
# Parse the response
for part in response.parts:
if part.text is not None:
print(part.text)
elif part.inline_data is not None:
with open("clip.mp3", "wb") as f:
f.write(part.inline_data.data)
print("Audio saved to clip.mp3")
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
const ai = new GoogleGenAI({});
async function main() {
const response = await ai.models.generateContent({
model: "lyria-3-clip-preview",
contents: "Create a 30-second cheerful acoustic folk song with " +
"guitar and harmonica.",
});
for (const part of response.candidates[0].content.parts) {
if (part.text) {
console.log(part.text);
} else if (part.inlineData) {
const buffer = Buffer.from(part.inlineData.data, "base64");
fs.writeFileSync("clip.mp3", buffer);
console.log("Audio saved to clip.mp3");
}
}
}
main();
Go
package main
import (
"context"
"fmt"
"log"
"os"
"google.golang.org/genai"
)
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
result, err := client.Models.GenerateContent(
ctx,
"lyria-3-clip-preview",
genai.Text("Create a 30-second cheerful acoustic folk song " +
"with guitar and harmonica."),
nil,
)
if err != nil {
log.Fatal(err)
}
for _, part := range result.Candidates[0].Content.Parts {
if part.Text != "" {
fmt.Println(part.Text)
} else if part.InlineData != nil {
err := os.WriteFile("clip.mp3", part.InlineData.Data, 0644)
if err != nil {
log.Fatal(err)
}
fmt.Println("Audio saved to clip.mp3")
}
}
}
Java
import com.google.genai.Client;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.Part;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class GenerateMusicClip {
public static void main(String[] args) throws IOException {
try (Client client = new Client()) {
GenerateContentResponse response = client.models.generateContent(
"lyria-3-clip-preview",
"Create a 30-second cheerful acoustic folk song with "
+ "guitar and harmonica.");
for (Part part : response.parts()) {
if (part.text().isPresent()) {
System.out.println(part.text().get());
} else if (part.inlineData().isPresent()) {
var blob = part.inlineData().get();
if (blob.data().isPresent()) {
Files.write(Paths.get("clip.mp3"), blob.data().get());
System.out.println("Audio saved to clip.mp3");
}
}
}
}
}
}
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/lyria-3-clip-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [
{"text": "Create a 30-second cheerful acoustic folk song with guitar and harmonica."}
]
}]
}'
C#
using System.Threading.Tasks;
using Google.GenAI;
using Google.GenAI.Types;
using System.IO;
public class GenerateMusicClip {
public static async Task main() {
var client = new Client();
var response = await client.Models.GenerateContentAsync(
model: "lyria-3-clip-preview",
contents: "Create a 30-second cheerful acoustic folk song with guitar and harmonica."
);
foreach (var part in response.Candidates[0].Content.Parts) {
if (part.Text != null) {
Console.WriteLine(part.Text);
} else if (part.InlineData != null) {
await File.WriteAllBytesAsync("clip.mp3", part.InlineData.Data);
Console.WriteLine("Audio saved to clip.mp3");
}
}
}
}
Membuat lagu berdurasi penuh
Gunakan model lyria-3-pro-preview untuk membuat lagu berdurasi penuh yang berdurasi beberapa menit. Model Pro memahami struktur musik dan dapat membuat komposisi dengan bait, refrain, dan jembatan yang berbeda. Anda dapat memengaruhi durasi dengan menentukannya dalam perintah (misalnya, "buat lagu berdurasi 2 menit") atau dengan menggunakan stempel waktu untuk menentukan struktur.
Python
response = client.models.generate_content(
model="lyria-3-pro-preview",
contents="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 response = await ai.models.generateContent({
model: "lyria-3-pro-preview",
contents: "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.",
});
Go
result, err := client.Models.GenerateContent(
ctx,
"lyria-3-pro-preview",
genai.Text("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."),
nil,
)
Java
GenerateContentResponse response = client.models.generateContent(
"lyria-3-pro-preview",
"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 -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [
{"text": "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."}
]
}]
}'
C#
var response = await client.Models.GenerateContentAsync(
model: "lyria-3-pro-preview",
contents: "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."
);
Pilih format output
Secara default, model Lyria 3 menghasilkan audio dalam format MP3. Untuk
Lyria 3 Pro, Anda juga dapat meminta output dalam format WAV dengan menyetel
response_format di generationConfig.
Python
response = client.models.generate_content(
model="lyria-3-pro-preview",
contents="An atmospheric ambient track.",
config=types.GenerateContentConfig(
response_modalities=["AUDIO", "TEXT"],
response_format={"audio": {"mime_type": "audio/wav"}},
),
)
JavaScript
const response = await ai.models.generateContent({
model: "lyria-3-pro-preview",
contents: "An atmospheric ambient track.",
config: {
responseModalities: ["AUDIO", "TEXT"],
responseFormat: { audio: { mimeType: "audio/wav" } },
},
});
Go
config := &genai.GenerateContentConfig{
ResponseModalities: []string{"AUDIO", "TEXT"},
ResponseMIMEType: "audio/wav",
}
result, err := client.Models.GenerateContent(
ctx,
"lyria-3-pro-preview",
genai.Text("An atmospheric ambient track."),
config,
)
Java
GenerateContentConfig config = GenerateContentConfig.builder()
.responseModalities("AUDIO", "TEXT")
.responseFormat(ResponseFormat.builder().audio(AudioFormat.builder().mimeType("audio/wav").build()).build())
.build();
GenerateContentResponse response = client.models.generateContent(
"lyria-3-pro-preview",
"An atmospheric ambient track.",
config);
C#
var config = new GenerateContentConfig {
ResponseModalities = { "AUDIO", "TEXT" },
ResponseMimeType = "audio/wav"
};
var response = await client.Models.GenerateContentAsync(
model: "lyria-3-pro-preview",
contents: "An atmospheric ambient track.",
config: config
);
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [
{"text": "An atmospheric ambient track."}
]
}],
"generationConfig": {
"responseModalities": ["AUDIO", "TEXT"],
"responseFormat": { "audio": { "mimeType": "audio/wav" } }
}
}'
Mengurai respons
Respons dari Lyria 3 berisi beberapa bagian. Bagian teks berisi lirik yang dibuat atau deskripsi JSON dari struktur lagu. Bagian dengan
inline_data berisi byte audio.
Python
lyrics = []
audio_data = None
for part in response.parts:
if part.text is not None:
lyrics.append(part.text)
elif part.inline_data is not None:
audio_data = part.inline_data.data
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 part of response.candidates[0].content.parts) {
if (part.text) {
lyrics.push(part.text);
} else if (part.inlineData) {
audioData = Buffer.from(part.inlineData.data, "base64");
}
}
if (lyrics.length) {
console.log("Lyrics:\n" + lyrics.join("\n"));
}
if (audioData) {
fs.writeFileSync("output.mp3", audioData);
}
Go
var lyrics []string
var audioData []byte
for _, part := range result.Candidates[0].Content.Parts {
if part.Text != "" {
lyrics = append(lyrics, part.Text)
} else if part.InlineData != nil {
audioData = part.InlineData.Data
}
}
if len(lyrics) > 0 {
fmt.Println("Lyrics:\n" + strings.Join(lyrics, "\n"))
}
if audioData != nil {
err := os.WriteFile("output.mp3", audioData, 0644)
if err != nil {
log.Fatal(err)
}
}
Java
List<String> lyrics = new ArrayList<>();
byte[] audioData = null;
for (Part part : response.parts()) {
if (part.text().isPresent()) {
lyrics.add(part.text().get());
} else if (part.inlineData().isPresent()) {
audioData = part.inlineData().get().data().get();
}
}
if (!lyrics.isEmpty()) {
System.out.println("Lyrics:\n" + String.join("\n", lyrics));
}
if (audioData != null) {
Files.write(Paths.get("output.mp3"), audioData);
}
C#
var lyrics = new List<string>();
byte[] audioData = null;
foreach (var part in response.Candidates[0].Content.Parts) {
if (part.Text != null) {
lyrics.Add(part.Text);
} else if (part.InlineData != null) {
audioData = part.InlineData.Data;
}
}
if (lyrics.Count > 0) {
Console.WriteLine("Lyrics:\n" + string.Join("\n", lyrics));
}
if (audioData != null) {
await File.WriteAllBytesAsync("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 '.candidates[0].content.parts[] | select(.inlineData) | .inlineData.data' | base64 -d > output.mp3
Membuat musik dari gambar
Lyria 3 mendukung input multimodal — Anda dapat memberikan hingga 10 gambar bersama dengan perintah teks Anda dan model akan menyusun musik yang terinspirasi oleh konten visual.
Python
from PIL import Image
image = Image.open("desert_sunset.jpg")
response = client.models.generate_content(
model="lyria-3-pro-preview",
contents=[
"An atmospheric ambient track inspired by the mood and "
"colors in this image.",
image,
],
)
JavaScript
const imageData = fs.readFileSync("desert_sunset.jpg");
const base64Image = imageData.toString("base64");
const response = await ai.models.generateContent({
model: "lyria-3-pro-preview",
contents: [
{ text: "An atmospheric ambient track inspired by the mood " +
"and colors in this image." },
{
inlineData: {
mimeType: "image/jpeg",
data: base64Image,
},
},
],
});
Go
imgData, err := os.ReadFile("desert_sunset.jpg")
if err != nil {
log.Fatal(err)
}
parts := []*genai.Part{
genai.NewPartFromText("An atmospheric ambient track inspired " +
"by the mood and colors in this image."),
&genai.Part{
InlineData: &genai.Blob{
MIMEType: "image/jpeg",
Data: imgData,
},
},
}
contents := []*genai.Content{
genai.NewContentFromParts(parts, genai.RoleUser),
}
result, err := client.Models.GenerateContent(
ctx,
"lyria-3-pro-preview",
contents,
nil,
)
Java
GenerateContentResponse response = client.models.generateContent(
"lyria-3-pro-preview",
Content.fromParts(
Part.fromText("An atmospheric ambient track inspired by "
+ "the mood and colors in this image."),
Part.fromBytes(
Files.readAllBytes(Path.of("desert_sunset.jpg")),
"image/jpeg")));
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d "{
\"contents\": [{
\"parts\":[
{\"text\": \"An atmospheric ambient track inspired by the mood and colors in this image.\"},
{
\"inline_data\": {
\"mime_type\":\"image/jpeg\",
\"data\": \"<BASE64_IMAGE_DATA>\"
}
}
]
}]
}"
C#
var response = await client.Models.GenerateContentAsync(
model: "lyria-3-pro-preview",
contents: new List<Part> {
Part.FromText("An atmospheric ambient track inspired by the mood and colors in this image."),
Part.FromBytes(await File.ReadAllBytesAsync("desert_sunset.jpg"), "image/jpeg")
}
);

Menyediakan lirik kustom
Anda dapat menulis lirik Anda 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.
"""
response = client.models.generate_content(
model="lyria-3-pro-preview",
contents=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 response = await ai.models.generateContent({
model: "lyria-3-pro-preview",
contents: prompt,
});
Go
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.
`
result, err := client.Models.GenerateContent(
ctx,
"lyria-3-pro-preview",
genai.Text(prompt),
nil,
)
Java
String 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.
""";
GenerateContentResponse response = client.models.generateContent(
"lyria-3-pro-preview",
prompt);
C#
var 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.
";
var response = await client.Models.GenerateContentAsync(
model: "lyria-3-pro-preview",
contents: prompt
);
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [
{"text": "Create a dreamy indie pop song with the following lyrics: ..."}
]
}]
}'
Mengontrol waktu dan struktur
Anda dapat menentukan apa yang terjadi tepatnya pada momen tertentu dalam lagu menggunakan stempel waktu. Hal ini berguna untuk mengontrol kapan instrumen masuk, kapan lirik disampaikan, dan bagaimana progres lagu:
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.
"""
response = client.models.generate_content(
model="lyria-3-pro-preview",
contents=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 response = await ai.models.generateContent({
model: "lyria-3-pro-preview",
contents: prompt,
});
Go
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.
`
result, err := client.Models.GenerateContent(
ctx,
"lyria-3-pro-preview",
genai.Text(prompt),
nil,
)
Java
String 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.
""";
GenerateContentResponse response = client.models.generateContent(
"lyria-3-pro-preview",
prompt);
C#
var 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.
";
var response = await client.Models.GenerateContentAsync(
model: "lyria-3-pro-preview",
contents: prompt
);
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [
{"text": "[0:00 - 0:10] Intro: ..."}
]
}]
}'
Membuat trek instrumental
Untuk musik latar belakang, soundtrack game, atau kasus penggunaan apa pun yang tidak memerlukan vokal, Anda dapat meminta model untuk menghasilkan trek khusus instrumental:
Python
response = client.models.generate_content(
model="lyria-3-clip-preview",
contents="A bright chiptune melody in C Major, retro 8-bit "
"video game style. Instrumental only, no vocals.",
)
JavaScript
const response = await ai.models.generateContent({
model: "lyria-3-clip-preview",
contents: "A bright chiptune melody in C Major, retro 8-bit " +
"video game style. Instrumental only, no vocals.",
});
Go
result, err := client.Models.GenerateContent(
ctx,
"lyria-3-clip-preview",
genai.Text("A bright chiptune melody in C Major, retro 8-bit " +
"video game style. Instrumental only, no vocals."),
nil,
)
Java
GenerateContentResponse response = client.models.generateContent(
"lyria-3-clip-preview",
"A bright chiptune melody in C Major, retro 8-bit "
+ "video game style. Instrumental only, no vocals.");
C#
var response = await client.Models.GenerateContentAsync(
model: "lyria-3-clip-preview",
contents: "A bright chiptune melody in C Major, retro 8-bit " +
"video game style. Instrumental only, no vocals."
);
REST
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/lyria-3-clip-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [
{"text": "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
response = client.models.generate_content(
model="lyria-3-pro-preview",
contents="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 response = await ai.models.generateContent({
model: "lyria-3-pro-preview",
contents: "Crée une chanson pop romantique en français sur un " +
"coucher de soleil à Paris. Utilise du piano et de " +
"la guitare acoustique.",
});
Go
result, err := client.Models.GenerateContent(
ctx,
"lyria-3-pro-preview",
genai.Text("Crée une chanson pop romantique en français sur un " +
"coucher de soleil à Paris. Utilise du piano et de " +
"la guitare acoustique."),
nil,
)
Java
GenerateContentResponse response = client.models.generateContent(
"lyria-3-pro-preview",
"Crée une chanson pop romantique en français sur un "
+ "coucher de soleil à Paris. Utilise du piano et de "
+ "la guitare acoustique.");
C#
var response = await client.Models.GenerateContentAsync(
model: "lyria-3-pro-preview",
contents: "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 -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [
{"text": "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 di mana model mempertimbangkan struktur musik (intro, bait, chorus, bridge, dll.) berdasarkan perintah Anda. Hal ini terjadi sebelum audio dibuat dan memastikan koherensi struktural dan musikalitas.
Interactions API
Anda dapat menggunakan model Lyria 3 dengan Interactions API; antarmuka terpadu untuk berinteraksi dengan model dan agen Gemini. Alat ini menyederhanakan pengelolaan status dan tugas yang berjalan lama untuk kasus penggunaan multimodal yang kompleks.
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="lyria-3-pro-preview",
input="A melancholic jazz fusion track in D minor, " +
"featuring a smooth saxophone melody, walking bass line, " +
"and complex drum rhythms.",
)
for output in interaction.outputs:
if output.text:
print(output.text)
elif output.inline_data:
with open("interaction_output.mp3", "wb") as f:
f.write(output.inline_data.data)
print("Audio saved to interaction_output.mp3")
JavaScript
import { GoogleGenAI } from '@google/genai';
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: 'A melancholic jazz fusion track in D minor, ' +
'featuring a smooth saxophone melody, walking bass line, ' +
'and complex drum rhythms.',
});
for (const output of interaction.outputs) {
if (output.text) {
console.log(output.text);
} else if (output.inlineData) {
const buffer = Buffer.from(output.inlineData.data, 'base64');
fs.writeFileSync('interaction_output.mp3', buffer);
console.log('Audio saved to interaction_output.mp3');
}
}
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 melancholic jazz fusion track in D minor, featuring a smooth saxophone melody, walking bass line, and complex drum rhythms."
}'
Panduan penulisan perintah
Perintah Anda bisa sesederhana "lagu folk tentang kucing lucu yang menghindari genangan air, vokal wanita dan suara hujan", atau sesuatu yang mendetail dan terstruktur seperti:
Lagu synth-pop bergaya 1980-an dengan beat yang kuat, synthesizer yang berkilau, dan chorus yang menarik dan bersemangat. Lagu ini harus memiliki nuansa retro-futuristik, yang mengingatkan pada lagu pop klasik era 80-an, dengan sentuhan produksi modern. Tempo harus ceria dan cocok untuk menari, sekitar 120 BPM, dengan struktur bait-refrain yang jelas dan hook instrumental yang mudah diingat. Liriknya menceritakan perasaan saat bersiap-siap untuk pergi ke pesta.
Perintah sederhana dan kompleks dapat memberikan output yang baik. Sebaiknya Anda bereksperimen dengan tips ini untuk menemukan apa yang paling cocok bagi Anda.
Genre
Awali perintah Anda dengan genre musik yang Anda inginkan, seperti hip hop, rock, dan rap. Anda dapat menentukan campuran genre:
- Perpaduan metal dan rap
- Kombinasi death metal dan opera
- Karya klasik dengan elemen drone elektronik
- Musik dance elektronik (EDM) modern yang dipadukan dengan Europop
Anda juga dapat menyertakan era:
- Hip-hop awal 90-an
- Pop ye-ye Prancis 60-an
- Eksperimen elektronik tahun 80-an
- Pop mainstream 2000-an
Jika Anda meminta genre khusus atau varian regional, seperti "techno Berlin" atau "hyphy Bay Area", model akan mencoba menangkap esensinya, tetapi mungkin tidak selalu benar.
Instrumen
Secara default, Lyria 3 akan membuat lagu dengan instrumen dan alat yang Anda harapkan untuk genre tersebut. Anda tidak perlu bersikap preskriptif.
Namun, trek musik dance tidak akan menyertakan saksofon kecuali jika Anda memintanya. Jadi, jika Anda menginginkan solo saksofon, Anda harus memberikan perintah:
Lagu dance dengan irama yang kuat, synthesizer yang berkilau, dan chorus yang menarik dan seperti lagu kebangsaan. Solo saksofon harus masuk selama bagian jembatan.
Perintah Anda dapat menyertakan instrumen tertentu, suaranya, dan cara instrumen tersebut berinteraksi satu sama lain. Anda dapat menggunakan kombinasi ini untuk menciptakan suasana atau tekstur tertentu:
- Garis bas yang kotor dan terdistorsi beradu dengan hi-hat yang bersih dan jernih
- Pad synthesizer analog yang hangat dan membesar di bawah gitar akustik yang kering dan intim
- Dinding suara yang dibuat oleh beberapa lapisan gitar fuzzy, dengan vokal yang terpendam dan jauh
Struktur lagu
Anda dapat menguraikan progres lagu dalam perintah Anda. Gunakan panah atau daftar untuk menentukan alur:
[Intro]->[Verse 1]->[Chorus]->[Verse 2]->[Chorus]->[Bridge]->[Outro]- Mulai dengan intro piano yang tenang, bangun ke bait yang keras, turun ke keheningan, lalu meledak ke chorus.
Anda juga dapat menentukan bagaimana perubahan tingkat energi di antara bagian-bagian ini:
- Bangun ketegangan di pra-chorus, lalu turunkan ke keheningan sebelum chorus yang besar dan eksplosif
- Crescendo bertahap di sepanjang lagu, menambahkan satu instrumen pada satu waktu hingga menghasilkan suara yang kacau
- Berhenti tiba-tiba setelah jembatan, diikuti dengan chorus acapella
Anda juga dapat meminta waktu yang tepat untuk melakukan sesuatu:
- Bangun hingga penurunan pada detik ke-12
- Seseorang mengucapkan "apa" setiap 2 detik
- Bagian chorus dimulai pada detik ke-22
Lirik
Vokal dan lirik dibuat secara default. Anda dapat memberikan lirik Anda sendiri, meminta tidak ada lirik (atau instrumental), atau mengarahkan pembuatan lirik ke arah yang Anda inginkan.
Lirik Anda akan menggunakan bahasa yang Anda gunakan untuk menulis perintah. Anda juga dapat meminta lirik dalam bahasa lain, seperti "Tulis lirik dalam bahasa Prancis".
Menggunakan lirik Anda sendiri
Untuk memberikan lirik Anda sendiri kepada model, sertakan lirik tersebut dalam perintah dengan awalan "Lirik:":
Lyrics:
[Intro]
Oooh, oooh
[Verse 1]
Let's go
Let's go
Go with the flow
[Chorus]
...
Anda dapat menambahkan awalan pada bagian lagu dengan judul bagian seperti [Intro],
[Verse 1], [Pre-chorus], [Chorus], dan [Outro].
Jika Anda ingin kata atau baris diulang, seperti gema atau oleh penyanyi latar, Anda dapat menyertakannya dalam tanda kurung: "Ayo (ayo)".
Meminta model untuk menulis lirik
Jika Anda ingin Lyria 3 membuat lirik untuk Anda, sebaiknya sertakan detail tentang isi lirik dalam perintah Anda. Jika tidak, model perlu menyimpulkan subjek dari perintah musik Anda, dan mungkin tidak sesuai dengan yang Anda inginkan.
Liriknya bercerita tentang cinta yang hilang dan rasa sakit akibat patah hati. Penyanyi ini mengenang hubungan masa lalunya dan kenangan yang kembali muncul.
Jika Anda menginginkan chorus yang berulang, sebaiknya minta chorus tersebut dalam perintah Anda:
Liriknya bercerita tentang cinta yang hilang dan rasa sakit akibat patah hati. Penyanyi ini mengenang hubungan masa lalunya dan kenangan yang kembali muncul. Bagian chorus yang kuat berfokus pada mengatasi rasa sakit dan melanjutkan hidup.
Lyria 3 akan otomatis mengarahkan struktur lirik ke jenis musik yang Anda minta, tetapi Anda juga dapat menekankan kembali hal ini dalam perintah Anda. Contoh:
Lagu EDM yang mengulang frasa energik yang sama berulang kali.
Anda juga dapat meminta efek vokal yang tidak sepenuhnya lirik, misalnya:
- Sampel berulang dari sebuah film mengatakan "Saya tidak percaya ini!" di sepanjang lagu
- Lagu techno berenergi tinggi, tepat sebelum drop, suara berhenti dan suara kecil berkata "Aku tidak tahu apa yang kulakukan di sini", lalu musik drop.
- Lagu ini diawali dengan percakapan tentang film tahun 90-an yang lebih bagus daripada film saat ini. Kemudian, lagu tersebut beralih ke lagu pop.
Vokal
Anda dapat memberikan perintah tentang cara lirik akan disampaikan. Untuk hasil terbaik, tentukan profil penyanyi yang mendetail yang mencakup gender, timbre, dan rentang vokal.
- Sopran Wanita: Timbre yang jernih dan seperti kristal dengan kualitas yang lincah dan tinggi. Mampu mencapai nada tinggi yang bersiul dengan tekstur ringan dan berhembus.
- Alto Perempuan: Rentang bawah yang kaya, hangat, dan serak. Timbre berasap dengan sentuhan vocal fry, penuh jiwa dan beresonansi.
- Tenor Pria: Cerah, tajam, dan penuh semangat. Timbre muda dengan sedikit sentuhan sengau, menembus campuran dengan kekuatan belting yang tinggi.
- Bariton Pria: Dalam, seperti cokelat, dan selembut beludru. Suara dada yang beresonansi dengan penyampaian yang menenangkan dan mendayu-dayu.
- Weathered Rocker (Pria): Serak dan bertekstur dengan timbre berpasir, mengingatkan pada grunge era 90-an. Rentang atas yang tegang untuk intensitas emosional.
Parameter perintah lainnya
Anda juga dapat menyertakan parameter ini untuk lebih menyempurnakan perintah Anda:
- Nada Dasar/Skala: Tentukan nada dasar musik (misalnya, "dalam G mayor", "D minor").
- Suasana dan nuansa: Gunakan kata sifat deskriptif (misalnya, "nostalgia", "agresif", "indah", "melamun").
- Durasi: Model Klip selalu menghasilkan klip berdurasi 30 detik. Untuk model Pro, tentukan durasi yang diinginkan dalam perintah Anda (misalnya, "buat lagu berdurasi 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 melakukan pembuatan video panjang denganlyria-3-pro-preview. - Jadilah spesifik. Perintah yang tidak jelas akan menghasilkan hasil yang umum. Sebutkan instrumen, BPM, nada dasar, suasana, dan struktur untuk output terbaik.
- Gunakan tag bagian. Tag
[Verse],[Chorus],[Bridge]memberikan struktur yang jelas untuk diikuti model. - Pisahkan lirik dari petunjuk. Saat memberikan lirik kustom, pisahkan dengan jelas dari petunjuk arahan musik Anda.
Batasan
- Keamanan (Safety): 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.
- Penyematan watermark: Semua audio yang dihasilkan menyertakan watermark audio SynthID untuk identifikasi. Watermark ini tidak dapat didengar oleh telinga manusia dan tidak memengaruhi pengalaman mendengarkan.
- Pengeditan multi-giliran: Pembuatan musik adalah proses satu giliran. Pengeditan atau penyempurnaan klip yang dihasilkan secara berulang melalui beberapa perintah tidak didukung di Lyria 3 versi saat ini.
- Panjang: Model Klip selalu menghasilkan klip berdurasi 30 detik. Model Pro menghasilkan lagu berdurasi 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,
- Menghasilkan 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 Live API.