Lyria 3.5 คือกลุ่มโมเดลการสร้างเพลงของ Google ซึ่งพร้อมให้บริการ ผ่าน Gemini API Lyria 3.5 ช่วยให้คุณสร้างเสียงสเตอริโอ 44.1 kHz คุณภาพสูงจากพรอมต์ข้อความหรือจากรูปภาพได้ โมเดลเหล่านี้ ให้ความสอดคล้องเชิงโครงสร้าง ซึ่งรวมถึงเสียงร้อง เนื้อเพลงที่กำหนดเวลา และดนตรีบรรเลง ทั้งหมด
ตระกูล Lyria มีโมเดลต่อไปนี้
| รุ่น | รหัสโมเดล | เหมาะสำหรับ | ระยะเวลา | เอาต์พุต |
|---|---|---|---|---|
| คลิป Lyria 3 | lyria-3-clip-preview |
คลิปสั้น ลูป ตัวอย่าง | 30 วินาที | MP3 |
| Lyria 3.5 | lyria-3.5 |
เพลงเต็มความยาวที่มีท่อนร้อง คอรัส และบริดจ์ | 2-3 นาที (ควบคุมได้โดยใช้พรอมต์) | MP3 |
คุณสามารถใช้ทั้ง 2 โมเดลได้โดยใช้ Interactions API ใหม่ ซึ่งรองรับอินพุตแบบมัลติโมดอล (ข้อความและรูปภาพ) และสร้างเสียงสเตอริโอที่มีความเที่ยงตรงสูง 44.1 kHz
สร้างมิวสิกคลิป
โมเดลคลิป Lyria 3 จะสร้างคลิปความยาว 30 วินาทีเสมอ หากต้องการสร้าง
คลิป ให้เรียกใช้เมธอด interactions.create ด้วยพรอมต์ข้อความ คำตอบ
จะมีเนื้อเพลงและโครงสร้างเพลงที่สร้างขึ้นพร้อมกับเสียงใน
สคีมา steps เสมอ
Python
import base64
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="lyria-3-clip-preview",
input="A short instrumental acoustic guitar piece.",
)
generated_audio = interaction.output_audio
if generated_audio:
with open("music.mp3", "wb") as f:
f.write(base64.b64decode(generated_audio.data))
lyrics = interaction.output_text
if lyrics:
print(f"Lyrics:\n{lyrics}")
JavaScript
import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: 'lyria-3-clip-preview',
input: 'A short instrumental acoustic guitar piece.',
});
const generatedAudio = interaction.output_audio;
if (generatedAudio) {
fs.writeFileSync('music.mp3', Buffer.from(generatedAudio.data, 'base64'));
}
const lyrics = interaction.output_text;
if (lyrics) {
console.log(`Lyrics:\n${lyrics}`);
}
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ResponseModality;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-generate-001"))
.responseModalities(Arrays.asList(ResponseModality.AUDIO))
.input(InteractionsInput.of("Upbeat electronic synthwave track"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Audio generated: " + interaction.outputAudio().isPresent());
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
"model": "lyria-3-clip-preview",
"input": "A short instrumental acoustic guitar piece."
}'
คุณสามารถดึงข้อมูลเพลงที่สร้างขึ้นได้โดยใช้พร็อพเพอร์ตี้ interaction.output_audio
ซึ่งจะแสดงบล็อกเสียงที่สร้างล่าสุด นอกจากนี้ คุณยังดึงข้อมูลเนื้อเพลงและโครงสร้างของเพลงได้โดยใช้พร็อพเพอร์ตี้ interaction.output_text
ดูรายละเอียดเกี่ยวกับพร็อพเพอร์ตี้ความสะดวกได้ที่ภาพรวมของการโต้ตอบ
สร้างเพลงแบบเต็มความยาว
ใช้โมเดล lyria-3.5 เพื่อสร้างเพลงแบบเต็มความยาว 2-3 นาที โมเดล Pro เข้าใจโครงสร้างดนตรีและสามารถสร้าง
ผลงานที่มีท่อนร้อง คอรัส และบริดจ์ที่แตกต่างกัน คุณสามารถกำหนดระยะเวลาได้โดยระบุในพรอมต์ (เช่น "สร้างเพลง 2 นาที") หรือโดยใช้การประทับเวลาเพื่อกำหนดโครงสร้าง
Python
interaction = client.interactions.create(
model="lyria-3.5",
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.5',
input: 'A beautiful piano melody.',
});
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ResponseModality;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-generate-001"))
.responseModalities(Arrays.asList(ResponseModality.AUDIO))
.input(InteractionsInput.of("Upbeat electronic synthwave track"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Audio generated: " + interaction.outputAudio().isPresent());
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.5",
"input": "A beautiful piano melody."
}'
เลือกรูปแบบเอาต์พุต
โดยค่าเริ่มต้น โมเดล Lyria 3.5 จะสร้างเสียงในรูปแบบ MP3 สำหรับ
Lyria 3.5 คุณยังขอเอาต์พุตในรูปแบบ WAV ได้ด้วยโดยตั้งค่า
response_format
Python
interaction = client.interactions.create(
model="lyria-3.5",
input="A beautiful piano melody.",
response_format={"type": "audio"},
)
JavaScript
const interaction = await client.interactions.create({
model: 'lyria-3.5',
input: 'A beautiful piano melody.',
response_format: {
type: 'audio',
},
});
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ResponseModality;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-generate-001"))
.responseModalities(Arrays.asList(ResponseModality.AUDIO))
.input(InteractionsInput.of("Upbeat electronic synthwave track"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Audio generated: " + interaction.outputAudio().isPresent());
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.5",
"input": "A beautiful piano melody.",
"response_format": {
"type": "audio"
}
}'
แยกวิเคราะห์คำตอบ
การตอบกลับจาก Lyria 3.5 มีบล็อกเนื้อหาหลายรายการภายในstepsสคีมา
การโต้ตอบจะแสดงลำดับขั้นตอน โดยขั้นตอน model_output จะมี
เนื้อหาที่สร้างขึ้น
บล็อกเนื้อหาข้อความจะมีเนื้อเพลงที่สร้างขึ้นหรือคำอธิบาย JSON ของโครงสร้างเพลง
บล็อกเนื้อหาที่มีประเภท audio จะมีข้อมูลเสียงที่เข้ารหัส Base64
Python
lyrics = []
audio_data = None
generated_audio = interaction.output_audio
if generated_audio:
with open("output.mp3", "wb") as f:
f.write(base64.b64decode(generated_audio.data))
lyrics = interaction.output_text
if lyrics:
print(f"Lyrics:\n{lyrics}")
JavaScript
const lyrics = [];
let audioData = null;
const generatedAudio = interaction.output_audio;
if (generatedAudio) {
fs.writeFileSync("output.mp3", Buffer.from(generatedAudio.data, 'base64'));
}
const lyrics = interaction.output_text;
if (lyrics) {
console.log("Lyrics:\n" + lyrics);
}
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ResponseModality;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-generate-001"))
.responseModalities(Arrays.asList(ResponseModality.AUDIO))
.input(InteractionsInput.of("Upbeat electronic synthwave track"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Audio generated: " + interaction.outputAudio().isPresent());
REST
# The output from the REST API is a JSON object containing base64 encoded data.
# You can extract the text or the audio data using a tool like jq.
# To extract the audio and save it to a file:
curl ... | jq -r '.steps[] | select(.type=="model_output") | .content[] | select(.type=="audio") | .data' | base64 -d > output.mp3
เนื้อเพลงและเพลงที่สลับกัน
เนื่องจากเอาต์พุตจาก Lyria 3.5 มีความซับซ้อน โดยมีขั้นตอนและบล็อกแยกต่างหากสำหรับเนื้อเพลง (ข้อความ) และตัวเพลง (เสียง) ที่สร้างขึ้น คุณสมบัติความสะดวกจึงเป็นทางลัดที่รวดเร็วและแนะนำ
อย่างไรก็ตาม หากต้องการควบคุมไทม์ไลน์ดิบของขั้นตอนที่เซิร์ฟเวอร์ส่งคืนแบบเป็นโปรแกรมอย่างเต็มรูปแบบ (เช่น การบันทึกบล็อกเนื้อหาแต่ละรายการเมื่อได้รับ) คุณสามารถวนซ้ำ steps ด้วยตนเองแทนได้
Python
lyrics = []
audio_data = None
for step in interaction.steps:
if step.type == "model_output":
for content_block in step.content:
if content_block.type == "audio":
audio_data = base64.b64decode(content_block.data)
elif content_block.type == "text":
lyrics.append(content_block.text)
if lyrics:
print("Lyrics:\n" + "\n".join(lyrics))
if audio_data:
with open("output.mp3", "wb") as f:
f.write(audio_data)
JavaScript
const lyrics = [];
let audioData = null;
for (const step of interaction.steps) {
if (step.type === 'model_output') {
for (const contentBlock of step.content) {
if (contentBlock.type === 'audio') {
audioData = Buffer.from(contentBlock.data, 'base64');
} else if (contentBlock.type === 'text') {
lyrics.push(contentBlock.text);
}
}
}
}
if (lyrics.length) {
console.log("Lyrics:\n" + lyrics.join("\n"));
}
if (audioData) {
fs.writeFileSync("output.mp3", audioData);
}
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ResponseModality;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-generate-001"))
.responseModalities(Arrays.asList(ResponseModality.AUDIO))
.input(InteractionsInput.of("Upbeat electronic synthwave track"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Audio generated: " + interaction.outputAudio().isPresent());
สร้างเพลงจากรูปภาพ
Lyria 3.5 รองรับอินพุตแบบมัลติโมดัล ซึ่งคุณสามารถระบุรูปภาพได้สูงสุด 10 รูป
พร้อมกับพรอมต์ข้อความในรายการinput และโมเดลจะแต่งเพลง
โดยได้แรงบันดาลใจจากเนื้อหาภาพ
Python
import base64
with open("desert_sunset.jpg", "rb") as f:
image_bytes = f.read()
image_b64 = base64.b64encode(image_bytes).decode("utf-8")
response = client.interactions.create(
model="lyria-3.5",
input=[
{
"type": "text",
"text": "An atmospheric ambient track inspired by the mood and colors in this image.",
},
{
"type": "image",
"mime_type": "image/jpeg",
"data": image_b64,
},
],
)
JavaScript
import * as fs from "fs";
const imageBytes = fs.readFileSync("desert_sunset.jpg").toString("base64");
const interaction = await client.interactions.create({
model: "lyria-3.5",
input: [
{
type: "text",
text: "An atmospheric ambient track inspired by the mood and colors in this image.",
},
{
type: "image",
mime_type: "image/jpeg",
data: imageBytes,
},
],
});
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ResponseModality;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-generate-001"))
.responseModalities(Arrays.asList(ResponseModality.AUDIO))
.input(InteractionsInput.of("Upbeat electronic synthwave track"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Audio generated: " + interaction.outputAudio().isPresent());
REST
# Pass base64 encoded image data directly:
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "lyria-3.5",
"input": [
{"type": "text", "text": "An atmospheric ambient track inspired by the mood and colors in this image."},
{"type": "image", "mime_type": "image/jpeg", "data": "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wgALCAABAAEBAREA/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPxA="}
]
}'
ระบุเนื้อเพลงที่กำหนดเอง
คุณสามารถเขียนเนื้อเพลงของคุณเองและใส่ไว้ในพรอมต์ได้ ใช้แท็กส่วน
เช่น [Verse], [Chorus] และ [Bridge] เพื่อช่วยให้โมเดลเข้าใจโครงสร้างเพลง
Python
prompt = """
Create a dreamy indie pop song with the following lyrics:
[Verse 1]
Walking through the neon glow,
city lights reflect below,
every shadow tells a story,
every corner, fading glory.
[Chorus]
We are the echoes in the night,
burning brighter than the light,
hold on tight, don't let me go,
we are the echoes down below.
[Verse 2]
Footsteps lost on empty streets,
rhythms sync to heartbeats,
whispers carried by the breeze,
dancing through the autumn leaves.
"""
interaction = client.interactions.create(
model="lyria-3.5",
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.5',
input: prompt,
});
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ResponseModality;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-generate-001"))
.responseModalities(Arrays.asList(ResponseModality.AUDIO))
.input(InteractionsInput.of("Upbeat electronic synthwave track"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Audio generated: " + interaction.outputAudio().isPresent());
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.5",
"input": "Create a dreamy indie pop song with the following lyrics: ..."
}'
ควบคุมเวลาและโครงสร้าง
คุณสามารถระบุสิ่งที่เกิดขึ้นในช่วงเวลาที่เฉพาะเจาะจงในเพลงได้โดยใช้ การประทับเวลา ซึ่งมีประโยชน์ในการควบคุมเวลาที่เครื่องดนตรีเริ่มเล่น เวลาที่เนื้อเพลง ปรากฏ และวิธีที่เพลงดำเนินไป ดังนี้
Python
prompt = """
[0:00 - 0:10] Intro: Begin with a soft lo-fi beat and muffled
vinyl crackle.
[0:10 - 0:30] Verse 1: Add a warm Fender Rhodes piano melody
and gentle vocals singing about a rainy morning.
[0:30 - 0:50] Chorus: Full band with upbeat drums and soaring
synth leads. The lyrics are hopeful and uplifting.
[0:50 - 1:00] Outro: Fade out with the piano melody alone.
"""
interaction = client.interactions.create(
model="lyria-3.5",
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.5',
input: prompt,
});
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ResponseModality;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-generate-001"))
.responseModalities(Arrays.asList(ResponseModality.AUDIO))
.input(InteractionsInput.of("Upbeat electronic synthwave track"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Audio generated: " + interaction.outputAudio().isPresent());
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.5",
"input": "[0:00 - 0:10] Intro: ..."
}'
สร้างแทร็กบรรเลง
สำหรับเพลงประกอบ ซาวด์แทร็กของเกม หรือกรณีการใช้งานใดๆ ที่ไม่จำเป็นต้องมีเสียงร้อง คุณสามารถแจ้งให้โมเดลสร้างแทร็กที่มีเฉพาะดนตรีได้โดยทำดังนี้
Python
interaction = client.interactions.create(
model="lyria-3-clip-preview",
input="A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals.",
)
JavaScript
const interaction = await client.interactions.create({
model: 'lyria-3-clip-preview',
input: 'A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals.',
});
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ResponseModality;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-generate-001"))
.responseModalities(Arrays.asList(ResponseModality.AUDIO))
.input(InteractionsInput.of("Upbeat electronic synthwave track"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Audio generated: " + interaction.outputAudio().isPresent());
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "lyria-3-clip-preview",
"input": "A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals."
}'
สร้างเพลงในภาษาต่างๆ
Lyria 3.5 จะสร้างเนื้อเพลงในภาษาของพรอมต์ หากต้องการสร้างเพลง ที่มีเนื้อร้องเป็นภาษาฝรั่งเศส ให้เขียนพรอมต์เป็นภาษาฝรั่งเศส โมเดลจะปรับรูปแบบการร้อง และการออกเสียงให้ตรงกับภาษา
Python
interaction = client.interactions.create(
model="lyria-3.5",
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.5',
input: 'Crée une chanson pop romantique en français sur un coucher de soleil à Paris. Utilise du piano et de la guitare acoustique.',
});
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.ResponseModality;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-generate-001"))
.responseModalities(Arrays.asList(ResponseModality.AUDIO))
.input(InteractionsInput.of("Upbeat electronic synthwave track"))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println("Audio generated: " + interaction.outputAudio().isPresent());
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.5",
"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.5 จะวิเคราะห์กระบวนการพรอมต์ของคุณ โดยโมเดลจะพิจารณาโครงสร้างดนตรี (ท่อนนำ ท่อนร้อง คอรัส บริดจ์ ฯลฯ) ตามพรอมต์ของคุณ ซึ่งจะเกิดขึ้นก่อนที่จะสร้างเสียง และช่วยให้มั่นใจได้ถึงความสอดคล้องของโครงสร้างและความเป็นดนตรี
คำแนะนำในการเขียนพรอมต์
พรอมต์ของคุณอาจเรียบง่าย เช่น "เพลงโฟล์กเกี่ยวกับแมวน่ารักที่หลบหลีกแอ่งน้ำ เสียงร้องของผู้หญิงและเสียงฝน" หรืออาจมีรายละเอียดและโครงสร้าง เช่น
แทร็กซินธ์ป๊อปสไตล์ยุค 80 ที่มีบีทเร้าใจ ซินธิไซเซอร์ที่เปล่งประกาย และท่อนคอรัสที่ติดหูและเป็นเพลงประจำตัว เพลงควรให้ความรู้สึกย้อนยุคแบบอนาคต ชวนให้นึกถึงเพลงป๊อปฮิตคลาสสิกในยุค 80 พร้อมการปรับงานสร้างให้ทันสมัย เทมโปควรสนุกสนานและเต้นได้ โดยอยู่ที่ประมาณ 120 BPM พร้อม โครงสร้างท่อน-คอรัสที่ชัดเจนและท่อนฮุกที่เป็นเครื่องดนตรีที่น่าจดจำ เนื้อเพลงพูดถึง ความรู้สึกของการเตรียมตัวไปปาร์ตี้
ทั้งพรอมต์ที่เรียบง่ายและซับซ้อนสามารถให้เอาต์พุตที่ดีได้ ลองใช้เคล็ดลับเหล่านี้เพื่อหาวิธีที่เหมาะกับคุณที่สุด
ประเภท
นำหน้าพรอมต์ด้วยแนวเพลงที่คุณต้องการ เช่น ฮิปฮอป ร็อก และ แร็ป คุณระบุแนวเพลงผสมได้ดังนี้
- การผสมผสานระหว่างเมทัลกับแร็ป
- การผสมผสานระหว่างเดธเมทัลและโอเปร่า
- เพลงคลาสสิกที่มีองค์ประกอบเสียงโดรนอิเล็กทรอนิกส์
- เพลงอิเล็กทรอนิกส์แดนซ์ (EDM) สมัยใหม่ผสมกับเพลงป๊อปยุโรป
นอกจากนี้ คุณยังระบุยุคได้ด้วย
- ฮิปฮอปช่วงต้นยุค 90
- เพลงป๊อปเยเย่ฝรั่งเศสยุค 60
- การทดลองอิเล็กทรอนิกส์ในยุค 80
- เพลงป๊อปกระแสหลักยุค 2000
หากคุณป้อนพรอมต์สำหรับแนวเพลงเฉพาะหรือแนวเพลงย่อยในภูมิภาค เช่น "เทคโนเบอร์ลิน" หรือ "ไฮฟีในเบย์แอเรีย" โมเดลจะพยายามจับแก่นแท้ของแนวเพลงนั้นๆ แต่อาจไม่ถูกต้องเสมอไป
เครื่องดนตรี
โดยค่าเริ่มต้น Lyria 3.5 จะสร้างเพลงด้วยเครื่องดนตรีและเครื่องมือที่คุณ คาดหวังสำหรับแนวเพลงนั้นๆ คุณไม่จำเป็นต้องกำหนดแนวทาง
แต่แทร็กแดนซ์จะไม่มีแซกโซโฟน เว้นแต่คุณจะขอ ดังนั้นหากต้องการให้มีเสียงแซกโซโฟน คุณต้องป้อนพรอมต์ดังนี้
แทร็กเต้นรำที่มีบีทหนักแน่น ซินธิไซเซอร์ที่เปล่งประกาย และท่อนฮุกที่ติดหู ราวกับเป็นเพลงชาติ โซโลแซกโซโฟนควรเริ่มเล่นในช่วงท่อนบริดจ์
พรอมต์ของคุณอาจรวมถึงเครื่องดนตรีที่เฉพาะเจาะจง เสียงของเครื่องดนตรี และวิธีที่เครื่องดนตรี โต้ตอบกัน คุณใช้การผสมผสานนี้เพื่อสร้างอารมณ์หรือพื้นผิวบางอย่างได้
- เสียงเบสที่สกปรกและบิดเบี้ยวต่อสู้กับเสียงไฮแฮตที่สะอาดและคมชัด
- เสียงแพดซินธิไซเซอร์แอนะล็อกที่อบอุ่นซึ่งค่อยๆ ดังขึ้นใต้เสียงกีตาร์โปร่งที่แห้งและใกล้ชิด
- กำแพงเสียงที่สร้างขึ้นจากกีตาร์แตกพร่าหลายเลเยอร์ พร้อมเสียงร้องที่ฝังอยู่ ไกลๆ
โครงสร้างเพลง
คุณสามารถระบุความคืบหน้าของเพลงในพรอมต์ได้ ใช้ลูกศรหรือรายการ เพื่อกำหนดโฟลว์
[Intro]->[Verse 1]->[Chorus]->[Verse 2]->[Chorus]->[Bridge]->[Outro]- เริ่มด้วยอินโทรเปียโนที่เงียบสงบ ค่อยๆ เพิ่มระดับเสียงจนถึงท่อนร้องที่ดัง จากนั้นลดระดับเสียงลงจน เงียบ แล้วระเบิดออกมาเป็นท่อนคอรัส
นอกจากนี้ คุณยังระบุวิธีที่ระดับพลังงานเปลี่ยนแปลงระหว่างส่วนต่างๆ เหล่านี้ได้ด้วย
- สร้างความตึงเครียดในท่อนก่อนฮุก แล้วปล่อยให้เงียบก่อนจะเข้าท่อนฮุกที่หนักแน่น และทรงพลัง
- ค่อยๆ เพิ่มความเข้มข้นของเพลงทีละน้อย จนกระทั่งเกิดกำแพงเสียงที่วุ่นวาย
- หยุดกะทันหันหลังท่อนบริดจ์ ตามด้วยคอรัสแบบอะแคปเปลลา
นอกจากนี้ คุณยังป้อนเวลาที่ต้องการให้เกิดเหตุการณ์ได้ด้วย
- สร้างการดรอปที่ 12 วินาที
- มีคนพูดว่า "ว่าไงนะ" ทุกๆ 2 วินาที
- ท่อนคอรัสเริ่มที่ 22 วินาที
เนื้อเพลง
ระบบจะสร้างเสียงร้องและเนื้อเพลงโดยค่าเริ่มต้น คุณสามารถระบุเนื้อเพลงของคุณเอง ขอไม่ให้มีเนื้อเพลง (หรือขอเป็นเพลงบรรเลง) หรือกำหนดทิศทางการสร้างเนื้อเพลง ตามที่คุณต้องการได้
เนื้อเพลงจะเป็นภาษาเดียวกับที่คุณใช้เขียนพรอมต์ นอกจากนี้ คุณยังขอให้เขียนเนื้อเพลงเป็นภาษาอื่นได้ด้วย เช่น "เขียนเนื้อเพลงเป็นภาษาฝรั่งเศส"
การใช้เนื้อเพลงของคุณเอง
หากต้องการให้โมเดลใช้เนื้อเพลงของคุณเอง ให้ใส่เนื้อเพลงในพรอมต์โดยมีคำนำหน้า "เนื้อเพลง:"
Lyrics:
[Intro]
Oooh, oooh
[Verse 1]
Let's go
Let's go
Go with the flow
[Chorus]
...
คุณสามารถใส่คำนำหน้าส่วนต่างๆ ของเพลงด้วยชื่อส่วน เช่น [Intro],
[Verse 1], [Pre-chorus], [Chorus] และ [Outro]
หากต้องการให้คำหรือบรรทัดซ้ำ เช่น เสียงก้องหรือนักร้องประสานเสียง คุณสามารถใส่ไว้ในวงเล็บได้ เช่น "ไปกันเลย (ไป)"
การป้อนพรอมต์ให้โมเดลเขียนเนื้อเพลง
หากต้องการให้ Lyria 3.5 สร้างเนื้อเพลงให้ คุณควรใส่รายละเอียด เกี่ยวกับเนื้อหาของเนื้อเพลงในพรอมต์ ไม่เช่นนั้น โมเดลจะต้องอนุมานเรื่องจากพรอมต์เพลงของคุณ ซึ่งอาจไม่ใช่สิ่งที่คุณต้องการ
เนื้อเพลงพูดถึงความรักที่สูญเสียไปและความเจ็บปวดจากอกหัก นักร้องกำลัง หวนรำลึกถึงความสัมพันธ์ในอดีตและความทรงจำที่ หลั่งไหลกลับมา
หากต้องการให้มีท่อนคอรัสซ้ำๆ คุณควรระบุในพรอมต์
เนื้อเพลงพูดถึงความรักที่สูญเสียไปและความเจ็บปวดจากอกหัก นักร้องกำลัง หวนรำลึกถึงความสัมพันธ์ในอดีตและความทรงจำที่ หลั่งไหลกลับมา ท่อนคอรัสที่ทรงพลังมุ่งเน้นไปที่การก้าวข้ามความเจ็บปวดและเดินหน้าต่อไป
Lyria 3.5 จะกำหนดโครงสร้างของเนื้อเพลงให้สอดคล้องกับ ประเภทเพลงที่คุณขอโดยอัตโนมัติ แต่คุณก็สามารถเน้นย้ำเรื่องนี้ในพรอมต์ได้เช่นกัน เช่น
แทร็ก EDM ที่ใช้วลีเดียวกันซ้ำๆ
นอกจากนี้ คุณยังป้อนพรอมต์เพื่อขอเอฟเฟกต์เสียงร้องที่ไม่ใช่เนื้อเพลงโดยตรงได้ด้วย เช่น
- ตัวอย่างที่เล่นซ้ำจากภาพยนตร์พูดว่า "ฉันไม่อยากจะเชื่อเลย" ตลอดทั้งเพลง
- เพลงเทคโนที่มีพลังสูง ก่อนที่ดนตรีจะเริ่ม เสียงทั้งหมดจะหยุดลงและมีเสียงเล็กๆ พูดว่า "ฉันไม่รู้ว่าฉันกำลังทำอะไรอยู่" แล้วดนตรีก็เริ่มขึ้น
- โดยเพลงนี้เปิดด้วยการพูดคุยเกี่ยวกับภาพยนตร์ในยุค 90 ที่ ดีกว่าปัจจุบัน จากนั้นเพลงจะเปลี่ยนเป็นเพลงป๊อป
เสียงร้อง
คุณสามารถป้อนพรอมต์เพื่อระบุวิธีที่ต้องการให้แสดงเนื้อเพลงได้ ระบุโปรไฟล์นักร้องแบบละเอียดซึ่งครอบคลุมเพศ โทนเสียง และช่วงเสียงร้องเพื่อให้ได้ผลลัพธ์ที่ดีที่สุด
- เสียงโซปราโนหญิง: เสียงใสแจ๋วเหมือนแก้วเจียระไนที่มีคุณภาพสูง ร้องโน้ตสูงที่หวีดหวิวได้ด้วยเนื้อเสียงที่โปร่งและมีลม
- อัลโตหญิง: เสียงทุ้มที่อบอุ่นและแหบพร่า เสียงทุ้มต่ำที่มี เสียงแหบเล็กน้อย มีพลังและก้องกังวาน
- เสียงเทเนอร์ชาย: สดใส ก้องกังวาน และมีพลัง เสียงที่สดใสพร้อม เสียงขึ้นจมูกเล็กน้อยที่โดดเด่นในมิกซ์ด้วยพลังเสียงสูง
- เสียงบาริโทนชาย: เสียงทุ้ม นุ่มนวล และลื่นไหล เสียงทุ้มก้องกังวาน พร้อมการขับร้องที่นุ่มนวลและกล่อมเกลา
- ร็อกเกอร์รุ่นเก๋า (ชาย): เสียงแหบห้าวและมีเนื้อเสียงหยาบ ชวนให้นึกถึงเพลงกรันจ์ยุค 90 ช่วงเสียงสูงที่ตึงเครียดสำหรับความเข้มข้นทางอารมณ์
พารามิเตอร์พรอมต์อื่นๆ
คุณยังใส่พารามิเตอร์ต่อไปนี้เพื่อปรับแต่งพรอมต์เพิ่มเติมได้ด้วย
- BPM: ตั้งค่าเทมโป (เช่น "120 BPM", "เทมโปช้าประมาณ 70 BPM")
- คีย์/สเกล: ระบุคีย์เพลง (เช่น "ในคีย์ G เมเจอร์" "ในคีย์ D ไมเนอร์")
- อารมณ์และบรรยากาศ: ใช้คำคุณศัพท์ที่อธิบายรายละเอียด (เช่น "หวนรำลึก" "ดุดัน" "เหนือจริง" "เหมือนฝัน")
- ระยะเวลา: โมเดลคลิปจะสร้างคลิปความยาว 30 วินาทีเสมอ สำหรับโมเดล Pro ให้ระบุความยาวที่ต้องการในพรอมต์ (เช่น "สร้างเพลงยาว 2 นาที") หรือใช้การประทับเวลาเพื่อควบคุมระยะเวลา
ตัวอย่างพรอมต์
ตัวอย่างพรอมต์ที่มีประสิทธิภาพมีดังนี้
"A 30-second lofi hip hop beat with dusty vinyl crackle, mellow Rhodes piano chords, a slow boom-bap drum pattern at 85 BPM, and a jazzy upright bass line. Instrumental only.""An upbeat, feel-good pop song in G major at 120 BPM with bright acoustic guitar strumming, claps, and warm vocal harmonies about a summer road trip.""A dark, atmospheric trap beat at 140 BPM with heavy 808 bass, eerie synth pads, sharp hi-hats, and a haunting vocal sample. In D minor."
แนวทางปฏิบัติแนะนำ
- ทำซ้ำด้วยฟีเจอร์คลิปก่อน ใช้
lyria-3-clip-previewโมเดลที่เร็วกว่าเพื่อ ทดลองใช้พรอมต์ก่อนที่จะสร้างวิดีโอแบบเต็มด้วยlyria-3.5 - ใช้คำที่เฉพาะเจาะจง พรอมต์ที่คลุมเครือจะให้ผลลัพธ์ทั่วไป ระบุเครื่องดนตรี BPM, คีย์, อารมณ์ และโครงสร้างเพื่อให้ได้ผลลัพธ์ที่ดีที่สุด
- เลือกภาษาที่ต้องการ ป้อนพรอมต์ในภาษาที่คุณต้องการให้เนื้อเพลงเป็น
- ใช้แท็กส่วน แท็ก
[Verse],[Chorus],[Bridge]ช่วยให้โมเดลมีโครงสร้างที่ชัดเจน ให้ทำตาม - แยกเนื้อเพลงออกจากวิธีการ เมื่อระบุเนื้อเพลงที่กำหนดเอง ให้แยกเนื้อเพลงออกจากคำสั่งเกี่ยวกับทิศทางดนตรีอย่างชัดเจน
ข้อจำกัด
- ความปลอดภัย: ตัวกรองความปลอดภัยจะตรวจสอบพรอมต์ทั้งหมด ระบบจะบล็อกพรอมต์ที่ทริกเกอร์ ตัวกรอง ซึ่งรวมถึงพรอมต์ที่ขอเสียงของศิลปินที่เฉพาะเจาะจง หรือการสร้างเนื้อเพลงที่มีลิขสิทธิ์
- การทำลายน้ำ: เสียงที่สร้างขึ้นทั้งหมดจะมีลายน้ำที่เป็นเสียง SynthID สำหรับการระบุ ลายน้ำนี้จะมองไม่เห็นด้วยตาเปล่าและ ไม่มีผลต่อประสบการณ์การฟัง
- การแก้ไขแบบผ่านการสนทนาไปมา: การสร้างเพลงเป็นกระบวนการแบบครั้งเดียว การแก้ไขซ้ำหรือการปรับแต่งคลิปที่สร้างขึ้นผ่านพรอมต์หลายรายการ ไม่รองรับใน Lyria เวอร์ชัน 3.5 ปัจจุบัน
- ความยาว: โมเดลคลิปจะสร้างคลิปความยาว 30 วินาทีเสมอ โมเดล Pro สร้างเพลงที่มีความยาว 2-3 นาที โดยระยะเวลาที่แน่นอนจะ ขึ้นอยู่กับพรอมต์ของคุณ
- การกำหนด: ผลลัพธ์อาจแตกต่างกันไปในแต่ละการเรียกใช้ แม้จะใช้พรอมต์เดียวกันก็ตาม
ขั้นตอนถัดไป
- ดูราคาของโมเดล Lyria 3.5
- ลองการสร้างเพลงแบบสตรีมมิงแบบเรียลไทม์ ด้วย Lyria RealTime
- สร้างการสนทนาที่มีผู้พูดหลายคนด้วยโมเดล TTS
- ดูวิธีสร้างรูปภาพหรือวิดีโอ
- ดูว่า Gemini เข้าใจไฟล์เสียงได้อย่างไร
- สนทนากับ Gemini แบบเรียลไทม์โดยใช้ Live API