Lyria 3.5 是 Google 的音樂生成模型系列,可透過 Gemini API 使用。使用 Lyria 3.5,你可以根據文字提示或圖片生成高品質的 44.1 kHz 立體聲音訊。這些模型可提供結構一致的音樂,包括人聲、歌詞時間碼和完整樂器編曲。
Lyria 系列包含以下模型:
| 模型 | 模型 ID | 適用情境 | 時間長度 | 輸出內容 |
|---|---|---|---|---|
| Lyria 3 Clip | lyria-3-clip-preview |
短片、循環播放、預覽 | 30 秒 | MP3 |
| Lyria 3.5 | lyria-3.5 |
包含主歌、副歌和橋段的完整歌曲 | 幾分鐘 (可使用提示詞控制) | MP3 |
這兩款模型都可透過新的 Interactions API 使用,支援多模態輸入 (文字和圖片),並生成 44.1 kHz 高精準度立體聲音訊。
生成音樂短片
Lyria 3 Clip 模型一律會生成 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.operations.CreateInteractionRequestBody;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-clip-preview"))
.input(InteractionsInput.of("A short instrumental acoustic guitar piece."))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
if (interaction.outputAudio().isPresent() && interaction.outputAudio().get().data().isPresent()) {
byte[] audioBytes = Base64.getDecoder().decode(interaction.outputAudio().get().data().get());
Files.write(Paths.get("music.mp3"), audioBytes);
}
interaction.outputText().ifPresent(lyrics -> System.out.println("Lyrics:\n" + lyrics));
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 模型生成幾分鐘的完整歌曲。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.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3.5"))
.input(
InteractionsInput.of(
"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."))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
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,您也可以設定 response_format,要求以 WAV 格式輸出。
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.AudioResponseFormat;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat;
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.ResponseFormat;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3.5"))
.input(InteractionsInput.of("A beautiful piano melody."))
.responseFormat(
CreateModelInteractionResponseFormat.of(
ResponseFormat.of(AudioResponseFormat.builder().build())))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
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.operations.CreateInteractionRequestBody;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3.5"))
.input(InteractionsInput.of("A song about a starry night."))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
if (interaction.outputAudio().isPresent() && interaction.outputAudio().get().data().isPresent()) {
byte[] audioBytes = Base64.getDecoder().decode(interaction.outputAudio().get().data().get());
Files.write(Paths.get("output.mp3"), audioBytes);
}
if (interaction.outputText().isPresent()) {
System.out.println("Lyrics:\n" + interaction.outputText().get());
}
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.AudioContent;
import com.google.genai.gaos.models.interactions.Content;
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.ModelOutputStep;
import com.google.genai.gaos.models.interactions.Step;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3.5"))
.input(InteractionsInput.of("A song about a starry night."))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
List<String> lyrics = new ArrayList<>();
byte[] audioData = null;
if (interaction.steps().isPresent()) {
for (Step step : interaction.steps().get()) {
if (step instanceof ModelOutputStep) {
ModelOutputStep outputStep = (ModelOutputStep) step;
if (outputStep.content().isPresent()) {
for (Content contentBlock : outputStep.content().get()) {
if (contentBlock instanceof AudioContent) {
AudioContent audioBlock = (AudioContent) contentBlock;
if (audioBlock.data().isPresent()) {
audioData = Base64.getDecoder().decode(audioBlock.data().get());
}
} else if (contentBlock instanceof TextContent) {
TextContent textBlock = (TextContent) contentBlock;
textBlock.text().ifPresent(lyrics::add);
}
}
}
}
}
}
if (!lyrics.isEmpty()) {
System.out.println("Lyrics:\n" + String.join("\n", lyrics));
}
if (audioData != null) {
Files.write(Paths.get("output.mp3"), audioData);
}
根據圖片生成音樂
Lyria 3.5 支援多模態輸入內容,您可以在 input 清單中提供最多 10 張圖片和文字提示詞,模型就會根據視覺內容創作音樂。
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.Content;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.ImageContent;
import com.google.genai.gaos.models.interactions.ImageContentMimeType;
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.TextContent;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
Client client = new Client();
byte[] imageBytes = Files.readAllBytes(Paths.get("desert_sunset.jpg"));
String imageB64 = Base64.getEncoder().encodeToString(imageBytes);
Content textContent =
TextContent.builder()
.text("An atmospheric ambient track inspired by the mood and colors in this image.")
.build();
Content imageContent =
ImageContent.builder()
.mimeType(ImageContentMimeType.IMAGE_JPEG)
.data(imageB64)
.build();
List<Content> contents = Arrays.asList(textContent, imageContent);
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3.5"))
.input(InteractionsInput.ofContent(contents))
.build();
Interaction response =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
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.operations.CreateInteractionRequestBody;
Client client = new Client();
String prompt =
"Create a dreamy indie pop song with the following lyrics:\n\n"
+ "[Verse 1]\n"
+ "Walking through the neon glow,\n"
+ "city lights reflect below,\n"
+ "every shadow tells a story,\n"
+ "every corner, fading glory.\n\n"
+ "[Chorus]\n"
+ "We are the echoes in the night,\n"
+ "burning brighter than the light,\n"
+ "hold on tight, don't let me go,\n"
+ "we are the echoes down below.\n\n"
+ "[Verse 2]\n"
+ "Footsteps lost on empty streets,\n"
+ "rhythms sync to heartbeats,\n"
+ "whispers carried by the breeze,\n"
+ "dancing through the autumn leaves.";
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3.5"))
.input(InteractionsInput.of(prompt))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
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.operations.CreateInteractionRequestBody;
Client client = new Client();
String prompt =
"[0:00 - 0:10] Intro: Begin with a soft lo-fi beat and muffled vinyl crackle.\n"
+ "[0:10 - 0:30] Verse 1: Add a warm Fender Rhodes piano melody and gentle vocals singing about a rainy morning.\n"
+ "[0:30 - 0:50] Chorus: Full band with upbeat drums and soaring synth leads. The lyrics are hopeful and uplifting.\n"
+ "[0:50 - 1:00] Outro: Fade out with the piano melody alone.";
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3.5"))
.input(InteractionsInput.of(prompt))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
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.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3-clip-preview"))
.input(
InteractionsInput.of(
"A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals."))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
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.operations.CreateInteractionRequestBody;
Client client = new Client();
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("lyria-3.5"))
.input(
InteractionsInput.of(
"Crée une chanson pop romantique en français sur un coucher de soleil à Paris. Utilise du piano et de la guitare acoustique."))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
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 會分析提示程序,模型會根據提示推斷音樂結構 (前奏、主歌、副歌、橋段等)。這項程序會在生成音訊前執行,確保結構一致性和音樂性。
提示指南
如要瞭解如何撰寫有效的提示詞,指定音樂類型、樂器、歌曲結構、自訂歌詞和演唱風格,請參閱 Lyria 提示詞指南。
最佳做法
- 先使用 Clip 進行疊代。使用速度較快的
lyria-3-clip-preview模型測試提示,再使用lyria-3.5生成完整長度的內容。 - 提供清楚明確的說明,籠統的提示詞只會產出一般結果。提及樂器、BPM、調性、情境和結構,以獲得最佳輸出內容。
- 語言相符。以所需語言輸入提示。
- 使用章節標記。
[Verse]、[Chorus]、[Bridge]標記可為模型提供清楚的結構。 - 歌詞和指示分開。提供自訂歌詞時,請清楚區分歌詞和音樂方向指示。
限制
- 安全性:所有提示都會經過安全篩選器檢查。系統會封鎖觸發篩選器的提示。包括要求特定藝人聲音的提示,或是生成受著作權保護的歌詞。
- 浮水印:所有生成的音訊都會加上 SynthID 音訊浮水印,以利識別。這種浮水印人耳無法辨識,也不會影響聆聽體驗。
- 多輪遞進編輯:音樂生成是單輪程序。目前版本的 Lyria 3.5 不支援透過多個提示,反覆編輯或修正生成的片段。
- 長度:片段模型一律會生成 30 秒的片段。Pro 模型會生成幾分鐘的歌曲,確切時長取決於提示。
- 決定性:即使使用相同提示,每次通話的結果也可能不同。