Lyria 3 خانوادهای از مدلهای تولید موسیقی گوگل است که از طریق Gemini API در دسترس است. با Lyria 3، میتوانید صدای استریو با کیفیت بالا و فرکانس ۴۸ کیلوهرتز را از متن یا تصاویر تولید کنید. این مدلها انسجام ساختاری، از جمله آواز، اشعار زمانبندی شده و تنظیم کامل سازها را ارائه میدهند.
خانواده Lyria 3 شامل دو مدل است:
| مدل | شناسه مدل | بهترین برای | مدت زمان | خروجی |
|---|---|---|---|---|
| کلیپ لیریا ۳ | lyria-3-clip-preview | کلیپهای کوتاه، حلقهها، پیشنمایشها | ۳۰ ثانیه | ام پی۳ |
| لیریا ۳ پرو | lyria-3-pro-preview | آهنگهای کامل با اشعار، همخوانیها، پلها | چند دقیقه (قابل کنترل از طریق اعلان) | MP3، WAV |
هر دو مدل میتوانند با استفاده از روش استاندارد generateContent و API جدید Interactions ، با پشتیبانی از ورودیهای چندوجهی (متن و تصویر) مورد استفاده قرار گیرند و صدای استریو با کیفیت بالای ۴۸ کیلوهرتز تولید کنند.
یک کلیپ موسیقی تولید کنید
مدل Lyria 3 Clip همیشه یک کلیپ 30 ثانیهای تولید میکند. برای تولید کلیپ، متد generateContent فراخوانی کنید و response_modalities روی ["AUDIO", "TEXT"] تنظیم کنید. اضافه کردن TEXT به شما امکان میدهد متن آهنگ یا ساختار آهنگ تولید شده را در کنار صدا دریافت کنید.
پایتون
from google import genai
from google.genai import types
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.",
config=types.GenerateContentConfig(
response_modalities=["AUDIO", "TEXT"],
),
)
# 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")
جاوا اسکریپت
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.",
config: {
responseModalities: ["AUDIO", "TEXT"],
},
});
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();
برو
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)
}
config := &genai.GenerateContentConfig{
ResponseModalities: []string{"AUDIO", "TEXT"},
}
result, err := client.Models.GenerateContent(
ctx,
"lyria-3-clip-preview",
genai.Text("Create a 30-second cheerful acoustic folk song " +
"with guitar and harmonica."),
config,
)
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")
}
}
}
جاوا
import com.google.genai.Client;
import com.google.genai.types.GenerateContentConfig;
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()) {
GenerateContentConfig config = GenerateContentConfig.builder()
.responseModalities("AUDIO", "TEXT")
.build();
GenerateContentResponse response = client.models.generateContent(
"lyria-3-clip-preview",
"Create a 30-second cheerful acoustic folk song with "
+ "guitar and harmonica.",
config);
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");
}
}
}
}
}
}
استراحت
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."}
]
}],
"generationConfig": {
"responseModalities": ["AUDIO", "TEXT"]
}
}'
سی شارپ
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 config = new GenerateContentConfig {
ResponseModalities = { "AUDIO", "TEXT" }
};
var response = await client.Models.GenerateContentAsync(
model: "lyria-3-clip-preview",
contents: "Create a 30-second cheerful acoustic folk song with guitar and harmonica.",
config: config
);
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");
}
}
}
}
یک آهنگ کامل بسازید
از مدل lyria-3-pro-preview برای تولید آهنگهای کامل که چند دقیقه طول میکشند استفاده کنید. مدل Pro ساختار موسیقی را درک میکند و میتواند آهنگهایی با بندها، ترجیعبندها و پلهای متمایز ایجاد کند. شما میتوانید با مشخص کردن مدت زمان در اعلان خود (مثلاً "ایجاد یک آهنگ ۲ دقیقهای") یا با استفاده از مهرهای زمانی برای تعریف ساختار، بر مدت زمان تأثیر بگذارید.
پایتون
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.",
config=types.GenerateContentConfig(
response_modalities=["AUDIO", "TEXT"],
),
)
جاوا اسکریپت
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.",
config: {
responseModalities: ["AUDIO", "TEXT"],
},
});
برو
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."),
config,
)
جاوا
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.",
config);
استراحت
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."}
]
}],
"generationConfig": {
"responseModalities": ["AUDIO", "TEXT"]
}
}'
سی شارپ
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.",
config: config
);
پاسخ را تجزیه کنید
پاسخ Lyria 3 شامل چندین بخش است. بخشهای متنی شامل اشعار تولید شده یا توضیحات JSON از ساختار آهنگ هستند. بخشهای دارای inline_data شامل بایتهای صوتی هستند.
پایتون
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)
جاوا اسکریپت
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);
}
برو
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)
}
}
جاوا
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);
}
سی شارپ
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);
}
استراحت
# 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
تولید موسیقی از تصاویر
Lyria 3 از ورودیهای چندوجهی پشتیبانی میکند - شما میتوانید تا 10 تصویر را در کنار متن خود ارائه دهید و مدل با الهام از محتوای بصری، موسیقی میسازد.
پایتون
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,
],
config=types.GenerateContentConfig(
response_modalities=["AUDIO", "TEXT"],
),
)
جاوا اسکریپت
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,
},
},
],
config: {
responseModalities: ["AUDIO", "TEXT"],
},
});
برو
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,
config,
)
جاوا
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")),
config);
استراحت
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>\"
}
}
]
}],
\"generationConfig\": {
\"responseModalities\": [\"AUDIO\", \"TEXT\"]
}
}"
سی شارپ
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")
},
config: config
);

ارائه اشعار سفارشی
شما میتوانید اشعار خودتان را بنویسید و آنها را در اعلان قرار دهید. از برچسبهای بخش مانند [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.
"""
response = client.models.generate_content(
model="lyria-3-pro-preview",
contents=prompt,
config=types.GenerateContentConfig(
response_modalities=["AUDIO", "TEXT"],
),
)
جاوا اسکریپت
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,
config: {
responseModalities: ["AUDIO", "TEXT"],
},
});
برو
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),
config,
)
جاوا
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,
config);
سی شارپ
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,
config: config
);
استراحت
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: ..."}
]
}],
"generationConfig": {
"responseModalities": ["AUDIO", "TEXT"]
}
}'
کنترل زمان و ساختار
شما میتوانید با استفاده از مهرهای زمانی دقیقاً مشخص کنید که در لحظات خاص آهنگ چه اتفاقی میافتد. این برای کنترل زمان ورود سازها، زمان اجرای اشعار و نحوه پیشرفت آهنگ مفید است:
پایتون
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,
config=types.GenerateContentConfig(
response_modalities=["AUDIO", "TEXT"],
),
)
جاوا اسکریپت
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,
config: {
responseModalities: ["AUDIO", "TEXT"],
},
});
برو
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),
config,
)
جاوا
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,
config);
سی شارپ
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,
config: config
);
استراحت
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: ..."}
]
}],
"generationConfig": {
"responseModalities": ["AUDIO", "TEXT"]
}
}'
آهنگهای بیکلام تولید کنید
برای موسیقی پسزمینه، موسیقی متن بازی یا هر مورد استفادهای که در آن نیازی به آواز نیست، میتوانید مدل را طوری تنظیم کنید که فقط آهنگهای بیکلام تولید کند:
پایتون
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.",
config=types.GenerateContentConfig(
response_modalities=["AUDIO", "TEXT"],
),
)
جاوا اسکریپت
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.",
config: {
responseModalities: ["AUDIO", "TEXT"],
},
});
برو
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."),
config,
)
جاوا
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.",
config);
سی شارپ
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.",
config: config
);
استراحت
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."}
]
}],
"generationConfig": {
"responseModalities": ["AUDIO", "TEXT"]
}
}'
تولید موسیقی به زبانهای مختلف
Lyria 3 اشعار را به زبان سوال شما تولید میکند. برای تولید آهنگی با اشعار فرانسوی، سوال خود را به زبان فرانسوی بنویسید. این مدل سبک صوتی و تلفظ خود را برای مطابقت با زبان تطبیق میدهد.
پایتون
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.",
config=types.GenerateContentConfig(
response_modalities=["AUDIO", "TEXT"],
),
)
جاوا اسکریپت
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.",
config: {
responseModalities: ["AUDIO", "TEXT"],
},
});
برو
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."),
config,
)
جاوا
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.",
config);
سی شارپ
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.",
config: config
);
استراحت
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."}
]
}],
"generationConfig": {
"responseModalities": ["AUDIO", "TEXT"]
}
}'
هوش مدل
Lyria 3 فرآیند اجرای شما را تجزیه و تحلیل میکند، به این صورت که مدل بر اساس ساختار موسیقی (مقدمه، مصراع، همخوانی، پل و غیره) بر اساس اجرای شما استدلال میکند. این کار قبل از تولید صدا انجام میشود و انسجام ساختاری و موسیقیایی را تضمین میکند.
API تعاملات
شما میتوانید از مدلهای Lyria 3 با Interactions API استفاده کنید؛ یک رابط یکپارچه برای تعامل با مدلها و عاملهای Gemini. این رابط، مدیریت حالت و وظایف طولانیمدت را برای موارد استفاده پیچیده چندوجهی ساده میکند.
پایتون
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.",
response_modalities=["AUDIO", "TEXT"]
)
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")
جاوا اسکریپت
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.',
responseModalities: ['AUDIO', 'TEXT'],
});
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');
}
}
استراحت
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.",
"responseModalities": ["AUDIO", "TEXT"]
}'
راهنمای راهنمایی
هرچه درخواست شما خاصتر باشد، نتایج بهتری خواهید گرفت. در اینجا مواردی که میتوانید برای هدایت نسل جدید در نظر بگیرید، آورده شده است:
- ژانر : یک ژانر یا ترکیبی از ژانرها را مشخص کنید (مثلاً «هیپ هاپ لو-فای»، «جاز فیوژن»، «ارکستر سینمایی»).
- سازها : نام سازهای خاص را بنویسید (مثلاً «پیانوی فندر رودز»، «گیتار اسلاید»، «ماشین درام 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 مکالمهای بلادرنگ داشته باشید.