إنشاء الموسيقى باستخدام Lyria 3.5

‫Lyria 3.5 هي مجموعة من نماذج إنشاء الموسيقى من Google، وهي متاحة من خلال Gemini API. باستخدام Lyria 3.5، يمكنك إنشاء ملفات صوتية استريو عالية الجودة بتردد 44.1 كيلوهرتز من الطلبات النصية أو من الصور. تقدّم هذه النماذج اتساقًا في البنية، بما في ذلك الغناء وكلمات الأغاني المحدّدة بوقت وترتيبات الآلات الموسيقية الكاملة.

تتضمّن مجموعة Lyria 3.5 نموذجين:

الطراز رقم تعريف الطراز الأفضل لـ المدة الناتج
Lyria 3.5 Clip lyria-3.5-clip-preview مقاطع قصيرة، حلقات، معاينات ‫30 ثانية MP3
Lyria 3.5 Pro lyria-3.5-pro-preview أغانٍ كاملة تتضمّن أبياتًا وجوقات وجسورًا بضع دقائق (يمكن التحكّم فيها باستخدام الطلب) MP3

يمكن استخدام كلا الطرازَين باستخدام Interactions API الجديد، الذي يتيح إدخال بيانات متعددة الوسائط (نصوص وصور)، وينتج ملفات صوتية استريو عالية الجودة بتردد 44.1 كيلوهرتز.

إنشاء مقطع موسيقي

ينشئ نموذج Lyria 3.5 Clip دائمًا مقطعًا مدته 30 ثانية. لإنشاء مقطع، استخدِم طريقة interactions.create مع طلب نصي. يتضمّن الرد دائمًا كلمات الأغنية التي تم إنشاؤها وبنية الأغنية بجانب الصوت في مخطط steps.

Python

import base64
from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="lyria-3.5-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.5-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.5-clip-preview",
    "input": "A short instrumental acoustic guitar piece."
}'

يمكنك استرداد بيانات الموسيقى التي تم إنشاؤها باستخدام السمة interaction.output_audio التي تعرض آخر كتلة صوتية تم إنشاؤها. يمكنك أيضًا استرداد كلمات الأغنية وبنيتها باستخدام السمة interaction.output_text. لمعرفة تفاصيل حول السمات المريحة، راجِع الـ نظرة عامة على التفاعلات.

إنشاء أغنية كاملة

استخدِم نموذج lyria-3.5-pro-preview لإنشاء أغانٍ كاملة تستغرق بضع دقائق. يفهم نموذج Pro البنية الموسيقية ويمكنه إنشاء مؤلفات تتضمّن أبياتًا وجوقات وجسورًا مميزة. يمكنك التأثير في المدة من خلال تحديدها في طلبك (مثل "إنشاء أغنية مدتها دقيقتان") أو باستخدام الطوابع الزمنية لتحديد البنية.

Python

interaction = client.interactions.create(
    model="lyria-3.5-pro-preview",
    input="An epic cinematic orchestral piece about a journey home. Starts with a solo piano intro, builds through sweeping strings, and climaxes with a massive wall of sound.",
)

JavaScript

const interaction = await client.interactions.create({
    model: 'lyria-3.5-pro-preview',
    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-pro-preview",
    "input": "A beautiful piano melody."
}'

اختيار تنسيق الرد

تنشئ نماذج Lyria 3.5 الصوت بتنسيق MP3 تلقائيًا. بالنسبة إلى Lyria 3.5 Pro، يمكنك أيضًا طلب الناتج بتنسيق WAV من خلال ضبط response_format.

Python

interaction = client.interactions.create(
    model="lyria-3.5-pro-preview",
    input="A beautiful piano melody.",
    response_format={"type": "audio"},
)

JavaScript

const interaction = await client.interactions.create({
    model: 'lyria-3.5-pro-preview',
    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-pro-preview",
    "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-pro-preview",
    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-pro-preview",
    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-pro-preview",
    "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-pro-preview",
    input=prompt,
)

JavaScript

const prompt = `
Create a dreamy indie pop song with the following lyrics:

[Verse 1]
Walking through the neon glow,
city lights reflect below,
every shadow tells a story,
every corner, fading glory.

[Chorus]
We are the echoes in the night,
burning brighter than the light,
hold on tight, don't let me go,
we are the echoes down below.

[Verse 2]
Footsteps lost on empty streets,
rhythms sync to heartbeats,
whispers carried by the breeze,
dancing through the autumn leaves.
`;

const interaction = await client.interactions.create({
    model: 'lyria-3.5-pro-preview',
    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-pro-preview",
    "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-pro-preview",
    input=prompt,
)

JavaScript

const prompt = `
[0:00 - 0:10] Intro: Begin with a soft lo-fi beat and muffled
              vinyl crackle.
[0:10 - 0:30] Verse 1: Add a warm Fender Rhodes piano melody
              and gentle vocals singing about a rainy morning.
[0:30 - 0:50] Chorus: Full band with upbeat drums and soaring
              synth leads. The lyrics are hopeful and uplifting.
[0:50 - 1:00] Outro: Fade out with the piano melody alone.
`;

const interaction = await client.interactions.create({
    model: 'lyria-3.5-pro-preview',
    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-pro-preview",
    "input": "[0:00 - 0:10] Intro: ..."
  }'

إنشاء مقاطع موسيقية آلية

بالنسبة إلى الموسيقى في الخلفية أو الموسيقى التصويرية للألعاب أو أي حالة استخدام لا يكون فيها الغناء مطلوبًا، يمكنك أن تطلب من النموذج إنشاء مقاطع موسيقية آلية فقط:

Python

interaction = client.interactions.create(
    model="lyria-3.5-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.5-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.5-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-pro-preview",
    input="Crée une chanson pop romantique en français sur un coucher de soleil à Paris. Utilise du piano et de la guitare acoustique.",
)

JavaScript

const interaction = await client.interactions.create({
    model: 'lyria-3.5-pro-preview',
    input: 'Crée une chanson pop romantique en français sur un coucher de soleil à Paris. Utilise du piano et de la guitare acoustique.',
});

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-pro-preview",
    "input": "Crée une chanson pop romantique en français sur un coucher de soleil à Paris. Utilise du piano et de la guitare acoustique."
  }'

ذكاء النموذج

تحلّل Lyria 3.5 عملية الطلب التي يفسّر فيها النموذج البنية الموسيقية (المقدمة والبيت والجوقة والجسر وما إلى ذلك) استنادًا إلى طلبك. يحدث ذلك قبل إنشاء الصوت ويضمن الاتساق الهيكلي والموسيقى.

الدليل الإرشادي لكتابة الطلبات

كلما كان طلبك أكثر تحديدًا، كانت النتائج أفضل. إليك ما يمكنك تضمينه لتوجيه عملية الإنشاء:

  • النوع: حدِّد نوعًا أو مزيجًا من الأنواع (مثل "لو-فاي هيب هوب"، "جاز فيوجن"، "موسيقى أوركسترا سينمائية").
  • الآلات الموسيقية: اذكر آلات موسيقية معيّنة (مثل "بيانو Fender Rhodes" أو "غيتار slide" أو "آلة الطبول TR-808").
  • عدد النبضات في الدقيقة: اضبط الإيقاع (مثل "120 نبضة في الدقيقة" أو "إيقاع بطيء حوالي 70 نبضة في الدقيقة").
  • المفتاح/السلم الموسيقي: حدِّد مفتاحًا موسيقيًا (مثل "في سلم G الكبير" أو "في سلم D الصغير").
  • الحالة المزاجية والجو: استخدِم صفات وصفية (مثل "حنين"، "عدواني"، "أثيري"، "حالم").
  • البنية: استخدِم علامات مثل [Verse] و[Chorus] و[Bridge] و[Intro] و [Outro] أو الطوابع الزمنية للتحكّم في تقدّم الأغنية.
  • المدة: ينشئ نموذج Clip دائمًا مقاطع مدتها 30 ثانية. بالنسبة إلى نموذج Pro، حدِّد المدة المقصودة في طلبك (مثل "إنشاء أغنية مدتها دقيقتان") أو استخدِم الطوابع الزمنية للتحكّم في المدة.

أمثلة على الطلبات

في ما يلي بعض الأمثلة على الطلبات الفعّالة:

  • "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.5-clip-preview الأسرع لتجربة الطلبات قبل الالتزام بإنشاء أغنية كاملة باستخدام lyria-3.5-pro-preview.
  • الدقة تنتج الطلبات الغامضة نتائج عامة. اذكر الآلات الموسيقية وعدد النبضات في الدقيقة والمفتاح والحالة المزاجية والبنية للحصول على أفضل ناتج.
  • استخدِم لغتك. اكتب الطلب باللغة التي تريد أن تكون كلمات الأغنية بها.
  • استخدِم علامات الأقسام. تمنح العلامات [Verse] و[Chorus] و[Bridge] النموذج بنية واضحة ليتبعها.
  • افصل كلمات الأغنية عن التعليمات. عند تقديم كلمات أغنية مخصّصة، افصلها بوضوح عن تعليماتك المتعلقة بالاتجاه الموسيقي.

القيود

  • الأمان: تتحقّق فلاتر الأمان من جميع الطلبات. وسيتم حظر الطلبات التي تؤدي إلى تفعيل الفلاتر. ويشمل ذلك الطلبات التي تطلب أصوات فنانين معيّنين أو إنشاء كلمات أغنية محمية بموجب حقوق الطبع والنشر.
  • العلامة المائية: يتضمّن كل ملف صوتي تم إنشاؤه علامة مائية لمقطع صوتي من SynthID لتحديده. لا يمكن سماع هذه العلامة المائية بالأذن البشرية ولا تؤثر في تجربة الاستماع.
  • التعديل عبر سلسلة من الطلبات: إنشاء الموسيقى هو عملية تتم في خطوة واحدة. لا يتيح الإصدار الحالي من Lyria 3.5 التعديل التكراري أو تحسين مقطع تم إنشاؤه من خلال طلبات متعددة.
  • الطول: ينشئ نموذج Clip دائمًا مقاطع مدتها 30 ثانية. ينشئ نموذج Pro أغانٍ تستغرق بضع دقائق، ويمكن التأثير في المدة الدقيقة من خلال طلبك.
  • الحتمية: قد تختلف النتائج بين المكالمات، حتى مع استخدام الطلب نفسه.

الخطوات التالية