Lyria 3로 음악 생성하기

Lyria 3는 Gemini API를 통해 사용할 수 있는 Google의 음악 생성 모델 제품군입니다. Lyria 3를 사용하면 텍스트 프롬프트 또는 이미지에서 고품질의 44.1kHz 스테레오 오디오를 생성할 수 있습니다. 이러한 모델은 보컬, 시간 제한 가사, 전체 악기 편곡 등 구조적 일관성을 제공합니다.

Lyria 3 제품군에는 다음 두 가지 모델이 포함됩니다.

모델 모델 ID 권장 용도 기간 출력
Lyria 3 클립 lyria-3-clip-preview 짧은 클립, 연속 재생, 미리보기 30초 MP3
Lyria 3 Pro lyria-3-pro-preview 절, 후렴, 브리지가 있는 전체 길이 노래 몇 분 (프롬프트를 통해 제어 가능) MP3

두 모델 모두 표준 generateContent 메서드와 새로운 Interactions API를 사용하여 사용할 수 있으며, 멀티모달 입력 (텍스트 및 이미지)을 지원하고 44.1kHz 고음질 스테레오 오디오를 생성합니다.

음악 클립 생성

Lyria 3 Clip 모델은 항상 30초 길이의 클립을 생성합니다. 클립을 생성하려면 텍스트 프롬프트와 함께 generateContent 메서드를 호출합니다. 오디오와 함께 생성된 가사와 노래 구조가 항상 대답에 포함됩니다.

Python

from google import genai

client = genai.Client()

response = client.models.generate_content(
    model="lyria-3-clip-preview",
    contents="Create a 30-second cheerful acoustic folk song with "
             "guitar and harmonica.",
)

# Parse the response
for part in response.parts:
    if part.text is not None:
        print(part.text)
    elif part.inline_data is not None:
        with open("clip.mp3", "wb") as f:
            f.write(part.inline_data.data)
        print("Audio saved to clip.mp3")

자바스크립트

import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";

const ai = new GoogleGenAI({});

async function main() {
  const response = await ai.models.generateContent({
    model: "lyria-3-clip-preview",
    contents: "Create a 30-second cheerful acoustic folk song with " +
              "guitar and harmonica.",

  });

  for (const part of response.candidates[0].content.parts) {
    if (part.text) {
      console.log(part.text);
    } else if (part.inlineData) {
      const buffer = Buffer.from(part.inlineData.data, "base64");
      fs.writeFileSync("clip.mp3", buffer);
      console.log("Audio saved to clip.mp3");
    }
  }
}

main();

Go

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "google.golang.org/genai"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    result, err := client.Models.GenerateContent(
        ctx,
        "lyria-3-clip-preview",
        genai.Text("Create a 30-second cheerful acoustic folk song " +
                   "with guitar and harmonica."),
        nil,
    )
    if err != nil {
        log.Fatal(err)
    }

    for _, part := range result.Candidates[0].Content.Parts {
        if part.Text != "" {
            fmt.Println(part.Text)
        } else if part.InlineData != nil {
            err := os.WriteFile("clip.mp3", part.InlineData.Data, 0644)
            if err != nil {
                log.Fatal(err)
            }
            fmt.Println("Audio saved to clip.mp3")
        }
    }
}

자바

import com.google.genai.Client;
import com.google.genai.types.GenerateContentResponse;
import com.google.genai.types.Part;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class GenerateMusicClip {
  public static void main(String[] args) throws IOException {

    try (Client client = new Client()) {
      GenerateContentResponse response = client.models.generateContent(
          "lyria-3-clip-preview",
          "Create a 30-second cheerful acoustic folk song with "
              + "guitar and harmonica.");

      for (Part part : response.parts()) {
        if (part.text().isPresent()) {
          System.out.println(part.text().get());
        } else if (part.inlineData().isPresent()) {
          var blob = part.inlineData().get();
          if (blob.data().isPresent()) {
            Files.write(Paths.get("clip.mp3"), blob.data().get());
            System.out.println("Audio saved to clip.mp3");
          }
        }
      }
    }
  }
}

REST

curl -s -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/lyria-3-clip-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [
        {"text": "Create a 30-second cheerful acoustic folk song with guitar and harmonica."}
      ]
    }]
  }'

C#

using System.Threading.Tasks;
using Google.GenAI;
using Google.GenAI.Types;
using System.IO;

public class GenerateMusicClip {
  public static async Task main() {
    var client = new Client();
    var response = await client.Models.GenerateContentAsync(
      model: "lyria-3-clip-preview",
      contents: "Create a 30-second cheerful acoustic folk song with guitar and harmonica."
    );

    foreach (var part in response.Candidates[0].Content.Parts) {
      if (part.Text != null) {
        Console.WriteLine(part.Text);
      } else if (part.InlineData != null) {
        await File.WriteAllBytesAsync("clip.mp3", part.InlineData.Data);
        Console.WriteLine("Audio saved to clip.mp3");
      }
    }
  }
}

전체 길이 노래 생성

lyria-3-pro-preview 모델을 사용하여 2분 길이의 전체 노래를 생성합니다. Pro 모델은 음악 구조를 이해하고 뚜렷한 절, 후렴, 브리지가 있는 곡을 만들 수 있습니다. 프롬프트에 지정하거나('2분 길이의 노래 만들기' 등) 타임스탬프를 사용하여 구조를 정의하여 길이에 영향을 줄 수 있습니다.

Python

response = client.models.generate_content(
    model="lyria-3-pro-preview",
    contents="An epic cinematic orchestral piece about a journey home. "
             "Starts with a solo piano intro, builds through sweeping "
             "strings, and climaxes with a massive wall of sound.",
)

자바스크립트

const response = await ai.models.generateContent({
  model: "lyria-3-pro-preview",
  contents: "An epic cinematic orchestral piece about a journey home. " +
            "Starts with a solo piano intro, builds through sweeping " +
            "strings, and climaxes with a massive wall of sound.",

});

Go

result, err := client.Models.GenerateContent(
    ctx,
    "lyria-3-pro-preview",
    genai.Text("An epic cinematic orchestral piece about a journey " +
               "home. Starts with a solo piano intro, builds through " +
               "sweeping strings, and climaxes with a massive wall of sound."),
    nil,
)

자바

GenerateContentResponse response = client.models.generateContent(
    "lyria-3-pro-preview",
    "An epic cinematic orchestral piece about a journey home. "
        + "Starts with a solo piano intro, builds through sweeping "
        + "strings, and climaxes with a massive wall of sound.");

REST

curl -s -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [
        {"text": "An epic cinematic orchestral piece about a journey home. Starts with a solo piano intro, builds through sweeping strings, and climaxes with a massive wall of sound."}
      ]
    }]
  }'

C#

var response = await client.Models.GenerateContentAsync(
  model: "lyria-3-pro-preview",
  contents: "An epic cinematic orchestral piece about a journey home. " +
            "Starts with a solo piano intro, builds through sweeping " +
            "strings, and climaxes with a massive wall of sound."
);

출력 형식 선택

기본적으로 Lyria 3 모델은 MP3 형식으로 오디오를 생성합니다. Lyria 3 Pro의 경우 generationConfig에서 response_mime_type를 설정하여 WAV 형식으로 출력을 요청할 수도 있습니다.

Python

response = client.models.generate_content(
    model="lyria-3-pro-preview",
    contents="An atmospheric ambient track.",
    config=types.GenerateContentConfig(
        response_modalities=["AUDIO", "TEXT"],
        response_mime_type="audio/wav",
    ),
)

자바스크립트

const response = await ai.models.generateContent({
  model: "lyria-3-pro-preview",
  contents: "An atmospheric ambient track.",
  config: {
    responseModalities: ["AUDIO", "TEXT"],
    responseMimeType: "audio/wav",
  },
});

Go

config := &genai.GenerateContentConfig{
    ResponseModalities: []string{"AUDIO", "TEXT"},
    ResponseMIMEType:   "audio/wav",
}

result, err := client.Models.GenerateContent(
    ctx,
    "lyria-3-pro-preview",
    genai.Text("An atmospheric ambient track."),
    config,
)

Java

GenerateContentConfig config = GenerateContentConfig.builder()
    .responseModalities("AUDIO", "TEXT")
    .responseMimeType("audio/wav")
    .build();

GenerateContentResponse response = client.models.generateContent(
    "lyria-3-pro-preview",
    "An atmospheric ambient track.",
    config);

C#

var config = new GenerateContentConfig {
  ResponseModalities = { "AUDIO", "TEXT" },
  ResponseMimeType = "audio/wav"
};

var response = await client.Models.GenerateContentAsync(
  model: "lyria-3-pro-preview",
  contents: "An atmospheric ambient track.",
  config: config
);

REST

curl -s -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [
        {"text": "An atmospheric ambient track."}
      ]
    }],
    "generationConfig": {
      "responseModalities": ["AUDIO", "TEXT"],
      "responseMimeType": "audio/wav"
    }
  }'

응답 파싱

Lyria 3의 대답에는 여러 부분이 포함되어 있습니다. 텍스트 부분에는 생성된 가사 또는 노래 구조의 JSON 설명이 포함됩니다. inline_data이 있는 파트에는 오디오 바이트가 포함됩니다.

Python

lyrics = []
audio_data = None

for part in response.parts:
    if part.text is not None:
        lyrics.append(part.text)
    elif part.inline_data is not None:
        audio_data = part.inline_data.data

if lyrics:
    print("Lyrics:\n" + "\n".join(lyrics))

if audio_data:
    with open("output.mp3", "wb") as f:
        f.write(audio_data)

자바스크립트

const lyrics = [];
let audioData = null;

for (const part of response.candidates[0].content.parts) {
  if (part.text) {
    lyrics.push(part.text);
  } else if (part.inlineData) {
    audioData = Buffer.from(part.inlineData.data, "base64");
  }
}

if (lyrics.length) {
  console.log("Lyrics:\n" + lyrics.join("\n"));
}

if (audioData) {
  fs.writeFileSync("output.mp3", audioData);
}

Go

var lyrics []string
var audioData []byte

for _, part := range result.Candidates[0].Content.Parts {
    if part.Text != "" {
        lyrics = append(lyrics, part.Text)
    } else if part.InlineData != nil {
        audioData = part.InlineData.Data
    }
}

if len(lyrics) > 0 {
    fmt.Println("Lyrics:\n" + strings.Join(lyrics, "\n"))
}

if audioData != nil {
    err := os.WriteFile("output.mp3", audioData, 0644)
    if err != nil {
        log.Fatal(err)
    }
}

Java

List<String> lyrics = new ArrayList<>();
byte[] audioData = null;

for (Part part : response.parts()) {
  if (part.text().isPresent()) {
    lyrics.add(part.text().get());
  } else if (part.inlineData().isPresent()) {
    audioData = part.inlineData().get().data().get();
  }
}

if (!lyrics.isEmpty()) {
  System.out.println("Lyrics:\n" + String.join("\n", lyrics));
}

if (audioData != null) {
  Files.write(Paths.get("output.mp3"), audioData);
}

C#

var lyrics = new List<string>();
byte[] audioData = null;

foreach (var part in response.Candidates[0].Content.Parts) {
  if (part.Text != null) {
    lyrics.Add(part.Text);
  } else if (part.InlineData != null) {
    audioData = part.InlineData.Data;
  }
}

if (lyrics.Count > 0) {
  Console.WriteLine("Lyrics:\n" + string.Join("\n", lyrics));
}

if (audioData != null) {
  await File.WriteAllBytesAsync("output.mp3", audioData);
}

REST

# The output from the REST API is a JSON object containing base64 encoded data.
# You can extract the text or the audio data using a tool like jq.
# To extract the audio and save it to a file:
curl ... | jq -r '.candidates[0].content.parts[] | select(.inlineData) | .inlineData.data' | base64 -d > output.mp3

이미지에서 음악 생성

Lyria 3는 멀티모달 입력을 지원합니다. 텍스트 프롬프트와 함께 최대 10개의 이미지를 제공하면 모델이 시각적 콘텐츠에서 영감을 받은 음악을 작곡합니다.

Python

from PIL import Image

image = Image.open("desert_sunset.jpg")

response = client.models.generate_content(
    model="lyria-3-pro-preview",
    contents=[
        "An atmospheric ambient track inspired by the mood and "
        "colors in this image.",
        image,
    ],
)

자바스크립트

const imageData = fs.readFileSync("desert_sunset.jpg");
const base64Image = imageData.toString("base64");

const response = await ai.models.generateContent({
  model: "lyria-3-pro-preview",
  contents: [
    { text: "An atmospheric ambient track inspired by the mood " +
            "and colors in this image." },
    {
      inlineData: {
        mimeType: "image/jpeg",
        data: base64Image,
      },
    },
  ],

});

Go

imgData, err := os.ReadFile("desert_sunset.jpg")
if err != nil {
    log.Fatal(err)
}

parts := []*genai.Part{
    genai.NewPartFromText("An atmospheric ambient track inspired " +
        "by the mood and colors in this image."),
    &genai.Part{
        InlineData: &genai.Blob{
            MIMEType: "image/jpeg",
            Data:     imgData,
        },
    },
}

contents := []*genai.Content{
    genai.NewContentFromParts(parts, genai.RoleUser),
}

result, err := client.Models.GenerateContent(
    ctx,
    "lyria-3-pro-preview",
    contents,
    nil,
)

자바

GenerateContentResponse response = client.models.generateContent(
    "lyria-3-pro-preview",
    Content.fromParts(
        Part.fromText("An atmospheric ambient track inspired by "
            + "the mood and colors in this image."),
        Part.fromBytes(
            Files.readAllBytes(Path.of("desert_sunset.jpg")),
            "image/jpeg")));

REST

curl -s -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d "{
    \"contents\": [{
      \"parts\":[
          {\"text\": \"An atmospheric ambient track inspired by the mood and colors in this image.\"},
          {
            \"inline_data\": {
              \"mime_type\":\"image/jpeg\",
              \"data\": \"<BASE64_IMAGE_DATA>\"
            }
          }
      ]
    }]
  }"

C#

var response = await client.Models.GenerateContentAsync(
  model: "lyria-3-pro-preview",
  contents: new List<Part> {
    Part.FromText("An atmospheric ambient track inspired by the mood and colors in this image."),
    Part.FromBytes(await File.ReadAllBytesAsync("desert_sunset.jpg"), "image/jpeg")
  }
);

맞춤 가사 제공

직접 가사를 작성하여 프롬프트에 포함할 수 있습니다. [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.
"""

response = client.models.generate_content(
    model="lyria-3-pro-preview",
    contents=prompt,
)

자바스크립트

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

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

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

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

const response = await ai.models.generateContent({
  model: "lyria-3-pro-preview",
  contents: prompt,

});

Go

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

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

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

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

result, err := client.Models.GenerateContent(
    ctx,
    "lyria-3-pro-preview",
    genai.Text(prompt),
    nil,
)

Java

String prompt = """
    Create a dreamy indie pop song with the following lyrics:

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

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

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

GenerateContentResponse response = client.models.generateContent(
    "lyria-3-pro-preview",
    prompt);

C#

var prompt = @"
Create a dreamy indie pop song with the following lyrics:

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

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

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

var response = await client.Models.GenerateContentAsync(
  model: "lyria-3-pro-preview",
  contents: prompt
);

REST

curl -s -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [
        {"text": "Create a dreamy indie pop song with the following lyrics: ..."}
      ]
    }]
  }'

타이밍 및 구조 제어

타임스탬프를 사용하면 노래의 특정 순간에 정확히 어떤 일이 일어나는지 지정할 수 있습니다. 이는 악기가 언제 시작되고, 가사가 언제 전달되고, 노래가 어떻게 진행되는지 제어하는 데 유용합니다.

Python

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

response = client.models.generate_content(
    model="lyria-3-pro-preview",
    contents=prompt,
)

자바스크립트

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

const response = await ai.models.generateContent({
  model: "lyria-3-pro-preview",
  contents: prompt,

});

Go

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

result, err := client.Models.GenerateContent(
    ctx,
    "lyria-3-pro-preview",
    genai.Text(prompt),
    nil,
)

Java

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

GenerateContentResponse response = client.models.generateContent(
    "lyria-3-pro-preview",
    prompt);

C#

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

var response = await client.Models.GenerateContentAsync(
  model: "lyria-3-pro-preview",
  contents: prompt
);

REST

curl -s -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [
        {"text": "[0:00 - 0:10] Intro: ..."}
      ]
    }]
  }'

연주곡 트랙 생성

배경 음악, 게임 사운드트랙 또는 보컬이 필요하지 않은 사용 사례의 경우 모델에 연주곡 전용 트랙을 생성하도록 프롬프트를 지정할 수 있습니다.

Python

response = client.models.generate_content(
    model="lyria-3-clip-preview",
    contents="A bright chiptune melody in C Major, retro 8-bit "
             "video game style. Instrumental only, no vocals.",
)

자바스크립트

const response = await ai.models.generateContent({
  model: "lyria-3-clip-preview",
  contents: "A bright chiptune melody in C Major, retro 8-bit " +
            "video game style. Instrumental only, no vocals.",

});

Go

result, err := client.Models.GenerateContent(
    ctx,
    "lyria-3-clip-preview",
    genai.Text("A bright chiptune melody in C Major, retro 8-bit " +
               "video game style. Instrumental only, no vocals."),
    nil,
)

Java

GenerateContentResponse response = client.models.generateContent(
    "lyria-3-clip-preview",
    "A bright chiptune melody in C Major, retro 8-bit "
        + "video game style. Instrumental only, no vocals.");

C#

var response = await client.Models.GenerateContentAsync(
  model: "lyria-3-clip-preview",
  contents: "A bright chiptune melody in C Major, retro 8-bit " +
            "video game style. Instrumental only, no vocals."
);

REST

curl -s -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/lyria-3-clip-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [
        {"text": "A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals."}
      ]
    }]
  }'

다양한 언어로 음악 생성

Lyria 3는 프롬프트의 언어로 가사를 생성합니다. 프랑스어 가사가 포함된 노래를 생성하려면 프롬프트를 프랑스어로 작성하세요. 모델이 언어에 맞게 음성 스타일과 발음을 조정합니다.

Python

response = client.models.generate_content(
    model="lyria-3-pro-preview",
    contents="Crée une chanson pop romantique en français sur un "
             "coucher de soleil à Paris. Utilise du piano et de "
             "la guitare acoustique.",
)

자바스크립트

const response = await ai.models.generateContent({
  model: "lyria-3-pro-preview",
  contents: "Crée une chanson pop romantique en français sur un " +
            "coucher de soleil à Paris. Utilise du piano et de " +
            "la guitare acoustique.",

});

Go

result, err := client.Models.GenerateContent(
    ctx,
    "lyria-3-pro-preview",
    genai.Text("Crée une chanson pop romantique en français sur un " +
               "coucher de soleil à Paris. Utilise du piano et de " +
               "la guitare acoustique."),
    nil,
)

Java

GenerateContentResponse response = client.models.generateContent(
    "lyria-3-pro-preview",
    "Crée une chanson pop romantique en français sur un "
        + "coucher de soleil à Paris. Utilise du piano et de "
        + "la guitare acoustique.");

C#

var response = await client.Models.GenerateContentAsync(
  model: "lyria-3-pro-preview",
  contents: "Crée une chanson pop romantique en français sur un " +
            "coucher de soleil à Paris. Utilise du piano et de " +
            "la guitare acoustique."
);

REST

curl -s -X POST \
  "https://generativelanguage.googleapis.com/v1beta/models/lyria-3-pro-preview:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [
        {"text": "Crée une chanson pop romantique en français sur un coucher de soleil à Paris. Utilise du piano et de la guitare acoustique."}
      ]
    }]
  }'

모델 인텔리전스

Lyria 3는 프롬프트에 따라 모델이 음악 구조 (인트로, 벌스, 코러스, 브리지 등)를 통해 추론하는 프롬프트 프로세스를 분석합니다. 이는 오디오가 생성되기 전에 발생하며 구조적 일관성과 음악성을 보장합니다.

Interactions API

상호작용 API(Gemini 모델 및 에이전트와 상호작용하기 위한 통합 인터페이스)과 함께 Lyria 3 모델을 사용할 수 있습니다. 복잡한 멀티모달 사용 사례의 상태 관리와 장기 실행 작업을 간소화합니다.

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="lyria-3-pro-preview",
    input="A melancholic jazz fusion track in D minor, " +
          "featuring a smooth saxophone melody, walking bass line, " +
          "and complex drum rhythms.",
)

for output in interaction.outputs:
    if output.text:
        print(output.text)
    elif output.inline_data:
         with open("interaction_output.mp3", "wb") as f:
            f.write(output.inline_data.data)
         print("Audio saved to interaction_output.mp3")

자바스크립트

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
  model: 'lyria-3-pro-preview',
  input: 'A melancholic jazz fusion track in D minor, ' +
         'featuring a smooth saxophone melody, walking bass line, ' +
         'and complex drum rhythms.',
});

for (const output of interaction.outputs) {
  if (output.text) {
    console.log(output.text);
  } else if (output.inlineData) {
    const buffer = Buffer.from(output.inlineData.data, 'base64');
    fs.writeFileSync('interaction_output.mp3', buffer);
    console.log('Audio saved to interaction_output.mp3');
  }
}

REST

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "lyria-3-pro-preview",
    "input": "A melancholic jazz fusion track in D minor, featuring a smooth saxophone melody, walking bass line, and complex drum rhythms."
}'

프롬프트 작성 가이드

프롬프트는 '물웅덩이를 피하는 귀여운 고양이에 관한 포크송, 여성 보컬, 빗소리'와 같이 간단할 수도 있고 다음과 같이 상세하고 구조적일 수도 있습니다.

강렬한 비트, 반짝이는 신시사이저, 중독성 있는 앤섬 스타일의 코러스가 특징인 1980년대 스타일의 신스팝 트랙 이 곡은 80년대 클래식 팝 히트곡을 연상시키는 레트로 퓨처리즘 느낌을 주면서도 현대적인 세련미를 갖춰야 합니다. 템포는 120BPM 정도의 신나고 춤추기 좋은 템포여야 하며, 명확한 절-후렴 구조와 기억에 남는 연주곡 후크가 있어야 합니다. 가사는 파티를 준비하는 기분에 관한 내용입니다.

간단한 프롬프트와 복잡한 프롬프트 모두 좋은 출력을 제공할 수 있습니다. 이러한 팁을 실험하여 자신에게 가장 적합한 방법을 찾는 것이 좋습니다.

장르

원하는 음악 장르(예: 힙합, 록, 랩)로 프롬프트를 시작합니다. 다음과 같이 여러 장르를 지정할 수 있습니다.

  • 메탈과 랩의 융합
  • 데스 메탈과 오페라의 조합
  • 전자 드론 요소가 포함된 클래식 곡
  • 유로팝과 혼합된 현대적인 일렉트로닉 댄스 음악 (EDM)

연대를 포함할 수도 있습니다.

  • 1990년대 초반 힙합
  • 60년대 프랑스 예예 팝
  • 80년대 전자 음악 실험
  • 2000년대 메인스트림 팝

'베를린 테크노' 또는 '베이 지역 하이피'와 같은 맞춤 장르나 지역 변형을 요청하면 모델이 해당 본질을 포착하려고 시도하지만 항상 올바르게 파악하지는 못할 수 있습니다.

악기

기본적으로 Lyria 3는 장르에 적합한 악기와 도구를 사용하여 노래를 만듭니다. 명령형일 필요는 없습니다.

하지만 색소폰을 요청하지 않는 한 댄스 트랙에 색소폰이 포함되지는 않습니다. 따라서 색소폰 솔로를 원한다면 다음과 같이 프롬프트를 입력해야 합니다.

강한 비트, 반짝이는 신시사이저, 중독성 있는 앤섬 스타일의 코러스가 있는 댄스 트랙입니다. 브리지 중에 색소폰 솔로가 나와야 합니다.

프롬프트에는 특정 악기, 소리, 서로 상호작용하는 방식이 포함될 수 있습니다. 이 조합을 사용하여 특정 분위기나 질감을 만들 수 있습니다.

  • 더럽고 왜곡된 베이스 라인이 깨끗하고 선명한 하이햇과 싸우는 모습
  • 따뜻한 아날로그 신시사이저 패드가 드라이하고 친근한 어쿠스틱 기타 아래에서 부풀어 오릅니다.
  • 여러 겹의 퍼지 기타로 만들어진 사운드 벽, 묻혀 있고 멀리 있는 보컬

노래 구조

프롬프트에서 노래의 진행을 간략하게 설명할 수 있습니다. 화살표나 목록을 사용하여 흐름을 정의합니다.

  • [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]과 같은 섹션 제목을 접두사로 붙일 수 있습니다.

'Let's go (go)'와 같이 에코나 백킹 싱어처럼 단어나 줄을 반복하려면 괄호 안에 포함하면 됩니다.

모델에 가사 작성 요청

Lyria 3가 가사를 만들어 주길 바란다면 프롬프트에 가사의 내용을 자세히 포함하는 것이 좋습니다. 그렇지 않으면 모델이 음악 프롬프트에서 주제를 추론해야 하며, 원하는 결과가 아닐 수 있습니다.

가사는 잃어버린 사랑과 실연의 고통에 관한 내용입니다. 가수는 과거의 관계와 그 관계에서 떠오르는 기억들을 회상합니다.

반복되는 후렴구를 원한다면 프롬프트에서 요청하는 것이 좋습니다.

가사는 잃어버린 사랑과 실연의 고통에 관한 내용입니다. 가수는 과거의 관계와 그 관계에서 떠오르는 기억들을 회상합니다. 강렬한 후렴구는 고통을 극복하고 앞으로 나아가는 데 초점을 맞춥니다.

Lyria 3는 요청한 음악 유형에 맞게 가사의 구조를 자동으로 조정하지만 프롬프트에서 이를 다시 강조할 수도 있습니다. 예를 들면 다음과 같습니다.

동일한 활기찬 문구를 계속 반복하는 EDM 트랙

엄밀히 말해 가사가 아닌 보컬 효과를 요청할 수도 있습니다. 예를 들면 다음과 같습니다.

  • 영화의 반복되는 샘플이 노래 전체에 걸쳐 '믿을 수 없어!'라고 말합니다.
  • 드롭 직전까지 신나는 테크노 트랙이 재생되다가 갑자기 소리가 멈추고 작은 목소리가 '여기서 뭘 해야 할지 모르겠어'라고 말한 후 음악이 드롭됩니다.
  • 이 트랙은 90년대 영화가 요즘 영화보다 낫다는 대화로 시작됩니다. 그런 다음 트랙이 팝송으로 전환됩니다.

보컬

가사를 어떤 방식으로 전달할지 묻는 메시지를 표시할 수 있습니다. 최상의 결과를 얻으려면 성별, 음색, 음역대를 포함한 자세한 가수 프로필을 지정하세요.

  • 여성 소프라노: 민첩하고 솟아오르는 듯한 느낌을 주는 선명하고 수정 같은 음색 공기처럼 가볍고 숨소리가 섞인 질감으로 휘파람 소리처럼 높은 음을 낼 수 있습니다.
  • 여성 알토: 풍부하고 따뜻하며 허스키한 낮은 음역대 보컬 프라이가 가미된 스모키한 음색으로, 소울풀하고 공명합니다.
  • 남성 테너: 밝고, 날카롭고, 활기찬 느낌입니다. 약간의 비음이 섞인 젊은 음색으로, 높은 벨팅 파워로 믹스를 뚫고 나옵니다.
  • 남성 바리톤: 깊고 초콜릿처럼 부드러우며 벨벳처럼 매끄럽습니다. 부드러운 크루닝 스타일로 전달되는 공명하는 가슴 소리
  • Weathered Rocker (남성): 90년대 그런지를 연상시키는 거칠고 질감이 있으며 자갈 같은 음색입니다. 감정 강도의 상한이 부담스럽습니다.

기타 프롬프트 매개변수

다음 매개변수를 포함하여 프롬프트를 추가로 세부 조정할 수도 있습니다.

  • 조/스케일: 음악적 조 (예: '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-pro-preview로 전체 길이 생성을 커밋하기 전에 프롬프트를 실험합니다.
  • 자세히 설명합니다. 모호한 프롬프트는 일반적인 결과를 생성합니다. 최상의 결과를 위해 악기, BPM, 키, 분위기, 구조를 언급해 줘.
  • 섹션 태그를 사용합니다. [Verse], [Chorus], [Bridge] 태그는 모델이 따라야 할 명확한 구조를 제공합니다.
  • 가사와 안내를 구분하세요. 맞춤 가사를 제공할 때는 음악적 방향 지침과 명확하게 구분하세요.

제한사항

  • 안전: 모든 프롬프트는 안전 필터로 확인됩니다. 필터를 트리거하는 프롬프트는 차단됩니다. 여기에는 특정 아티스트의 음성을 요청하거나 저작권이 있는 가사를 생성하도록 요청하는 프롬프트가 포함됩니다.
  • 워터마킹: 생성된 모든 오디오에는 식별을 위한 SynthID 오디오 워터마크가 포함됩니다. 이 워터마크는 사람의 귀에 들리지 않으며 청취 환경에 영향을 주지 않습니다.
  • 멀티턴 편집: 음악 생성은 싱글턴 프로세스입니다. 현재 버전의 Lyria 3에서는 여러 프롬프트를 통해 생성된 클립을 반복적으로 수정하거나 다듬는 것이 지원되지 않습니다.
  • 길이: 클립 모델은 항상 30초 길이의 클립을 생성합니다. Pro 모델은 몇 분 길이의 노래를 생성합니다. 정확한 길이는 프롬프트에 따라 달라질 수 있습니다.
  • 결정론: 동일한 프롬프트를 사용하더라도 호출마다 결과가 다를 수 있습니다.

다음 단계