SPB Git

Repository Public

music-generation.md 33.7 KB 1,096 lines markdown

1Lyria 3.5 is Google's family of music generation models, available2through the Gemini API. With Lyria 3.5, you can generate high-quality, 44.1 kHz3stereo audio from text prompts or from images. These models deliver structural4coherence, including vocals, timed lyrics, and full instrumental arrangements.56The Lyria family includes models:78| Model | Model ID | Best for | Duration | Output |9|---|---|---|---|---|10| **Lyria 3 Clip** | `lyria-3-clip-preview` | Short clips, loops, previews | 30 seconds | MP3 |11| **Lyria 3.5** | `lyria-3.5` | Full-length songs with verses, choruses, bridges | A couple of minutes (controllable via prompt) | MP3 |1213Both models can be used using the standard `generateContent` method and the new14[Interactions API](https://ai.google.dev/gemini-api/docs/interactions-overview), supporting multimodal15inputs (text and images), and produce **44.1 kHz high-fidelity stereo** audio.1617> [!NOTE]18> **Note:** Looking for real-time, streaming music generation? See [Real-time music generation with Lyria RealTime](https://ai.google.dev/gemini-api/docs/generate-content/realtime-music-generation).1920## Generate a music clip2122The Lyria 3 Clip model always generates a **30-second** clip. To generate a23clip, call the `generateContent` method with a text prompt. The response always24includes the generated lyrics and song structure alongside the audio.2526### Python2728    from google import genai2930    client = genai.Client()3132    response = client.models.generate_content(33        model="lyria-3-clip-preview",34        contents="Create a 30-second cheerful acoustic folk song with "35                 "guitar and harmonica.",36    )3738    # Parse the response39    for part in response.parts:40        if part.text is not None:41            print(part.text)42        elif part.inline_data is not None:43            with open("clip.mp3", "wb") as f:44                f.write(part.inline_data.data)45            print("Audio saved to clip.mp3")4647### JavaScript4849    import { GoogleGenAI } from "@google/genai";50    import * as fs from "node:fs";5152    const ai = new GoogleGenAI({});5354    async function main() {55      const response = await ai.models.generateContent({56        model: "lyria-3-clip-preview",57        contents: "Create a 30-second cheerful acoustic folk song with " +58                  "guitar and harmonica.",5960      });6162      for (const part of response.candidates[0].content.parts) {63        if (part.text) {64          console.log(part.text);65        } else if (part.inlineData) {66          const buffer = Buffer.from(part.inlineData.data, "base64");67          fs.writeFileSync("clip.mp3", buffer);68          console.log("Audio saved to clip.mp3");69        }70      }71    }7273    main();7475### Go7677    package main7879    import (80        "context"81        "fmt"82        "log"83        "os"8485        "google.golang.org/genai"86    )8788    func main() {89        ctx := context.Background()90        client, err := genai.NewClient(ctx, nil)91        if err != nil {92            log.Fatal(err)93        }9495        result, err := client.Models.GenerateContent(96            ctx,97            "lyria-3-clip-preview",98            genai.Text("Create a 30-second cheerful acoustic folk song " +99                       "with guitar and harmonica."),100            nil,101        )102        if err != nil {103            log.Fatal(err)104        }105106        for _, part := range result.Candidates[0].Content.Parts {107            if part.Text != "" {108                fmt.Println(part.Text)109            } else if part.InlineData != nil {110                err := os.WriteFile("clip.mp3", part.InlineData.Data, 0644)111                if err != nil {112                    log.Fatal(err)113                }114                fmt.Println("Audio saved to clip.mp3")115            }116        }117    }118119### Java120121    import com.google.genai.Client;122    import com.google.genai.types.GenerateContentResponse;123    import com.google.genai.types.Part;124125    import java.io.IOException;126    import java.nio.file.Files;127    import java.nio.file.Paths;128129    public class GenerateMusicClip {130      public static void main(String[] args) throws IOException {131132        try (Client client = new Client()) {133          GenerateContentResponse response = client.models.generateContent(134              "lyria-3-clip-preview",135              "Create a 30-second cheerful acoustic folk song with "136                  + "guitar and harmonica.");137138          for (Part part : response.parts()) {139            if (part.text().isPresent()) {140              System.out.println(part.text().get());141            } else if (part.inlineData().isPresent()) {142              var blob = part.inlineData().get();143              if (blob.data().isPresent()) {144                Files.write(Paths.get("clip.mp3"), blob.data().get());145                System.out.println("Audio saved to clip.mp3");146              }147            }148          }149        }150      }151    }152153### REST154155    curl -s -X POST \156      "https://generativelanguage.googleapis.com/v1beta/models/lyria-3-clip-preview:generateContent" \157      -H "x-goog-api-key: $GEMINI_API_KEY" \158      -H "Content-Type: application/json" \159      -d '{160        "contents": [{161          "parts": [162            {"text": "Create a 30-second cheerful acoustic folk song with guitar and harmonica."}163          ]164        }]165      }'166167### C#168169    using System.Threading.Tasks;170    using Google.GenAI;171    using Google.GenAI.Types;172    using System.IO;173174    public class GenerateMusicClip {175      public static async Task main() {176        var client = new Client();177        var response = await client.Models.GenerateContentAsync(178          model: "lyria-3-clip-preview",179          contents: "Create a 30-second cheerful acoustic folk song with guitar and harmonica."180        );181182        foreach (var part in response.Candidates[0].Content.Parts) {183          if (part.Text != null) {184            Console.WriteLine(part.Text);185          } else if (part.InlineData != null) {186            await File.WriteAllBytesAsync("clip.mp3", part.InlineData.Data);187            Console.WriteLine("Audio saved to clip.mp3");188          }189        }190      }191    }192193> [!NOTE]194> **Objective:** For more examples, refer to the [Lyria 3.5 Notebook](https://colab.research.google.com/github/google-gemini/cookbook/blob/main/quickstarts/Get_started_Lyria.ipynb) in the Cookbooks repository.195196## Generate a full-length song197198Use the `lyria-3.5` model to generate full-length songs that last a199couple of minutes. The Pro model understands musical structure and can create200compositions with distinct verses, choruses, and bridges. You can influence the201duration by specifying it in your prompt (e.g., "create a 2-minute song") or by202using [timestamps](https://ai.google.dev/gemini-api/docs/generate-content/music-generation#timing) to define the structure.203204### Python205206    response = client.models.generate_content(207        model="lyria-3.5",208        contents="An epic cinematic orchestral piece about a journey home. "209                 "Starts with a solo piano intro, builds through sweeping "210                 "strings, and climaxes with a massive wall of sound.",211    )212213### JavaScript214215    const response = await ai.models.generateContent({216      model: "lyria-3.5",217      contents: "An epic cinematic orchestral piece about a journey home. " +218                "Starts with a solo piano intro, builds through sweeping " +219                "strings, and climaxes with a massive wall of sound.",220221    });222223### Go224225    result, err := client.Models.GenerateContent(226        ctx,227        "lyria-3.5",228        genai.Text("An epic cinematic orchestral piece about a journey " +229                   "home. Starts with a solo piano intro, builds through " +230                   "sweeping strings, and climaxes with a massive wall of sound."),231        nil,232    )233234### Java235236    GenerateContentResponse response = client.models.generateContent(237        "lyria-3.5",238        "An epic cinematic orchestral piece about a journey home. "239            + "Starts with a solo piano intro, builds through sweeping "240            + "strings, and climaxes with a massive wall of sound.");241242### REST243244    curl -s -X POST \245      "https://generativelanguage.googleapis.com/v1beta/models/lyria-3.5:generateContent" \246      -H "x-goog-api-key: $GEMINI_API_KEY" \247      -H "Content-Type: application/json" \248      -d '{249        "contents": [{250          "parts": [251            {"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."}252          ]253        }]254      }'255256### C#257258    var response = await client.Models.GenerateContentAsync(259      model: "lyria-3.5",260      contents: "An epic cinematic orchestral piece about a journey home. " +261                "Starts with a solo piano intro, builds through sweeping " +262                "strings, and climaxes with a massive wall of sound."263    );264265## Select output format266267By default, the Lyria 3.5 models generate audio in **MP3** format. For268Lyria 3.5, you can also request the output in **WAV** format by setting269the `response_format` in the `generationConfig`.270271### Python272273    from google.genai import types274275    response = client.models.generate_content(276        model="lyria-3.5",277        contents="An atmospheric ambient track.",278        config=types.GenerateContentConfig(279            response_modalities=["AUDIO", "TEXT"],280            response_format={"audio": {"mime_type": "audio/wav"}},281        ),282    )283284### JavaScript285286    const response = await ai.models.generateContent({287      model: "lyria-3.5",288      contents: "An atmospheric ambient track.",289      config: {290        responseModalities: ["AUDIO", "TEXT"],291        responseFormat: { audio: { mimeType: "audio/wav" } },292      },293    });294295### Go296297    config := &genai.GenerateContentConfig{298        ResponseModalities: []string{"AUDIO", "TEXT"},299        ResponseMIMEType:   "audio/wav",300    }301302    result, err := client.Models.GenerateContent(303        ctx,304        "lyria-3.5",305        genai.Text("An atmospheric ambient track."),306        config,307    )308309### Java310311    GenerateContentConfig config = GenerateContentConfig.builder()312        .responseModalities("AUDIO", "TEXT")313        .responseFormat(ResponseFormat.builder().audio(AudioFormat.builder().mimeType("audio/wav").build()).build())314        .build();315316    GenerateContentResponse response = client.models.generateContent(317        "lyria-3.5",318        "An atmospheric ambient track.",319        config);320321### C#322323    var config = new GenerateContentConfig {324      ResponseModalities = { "AUDIO", "TEXT" },325      ResponseMimeType = "audio/wav"326    };327328    var response = await client.Models.GenerateContentAsync(329      model: "lyria-3.5",330      contents: "An atmospheric ambient track.",331      config: config332    );333334### REST335336    curl -s -X POST \337      "https://generativelanguage.googleapis.com/v1beta/models/lyria-3.5:generateContent" \338      -H "x-goog-api-key: $GEMINI_API_KEY" \339      -H "Content-Type: application/json" \340      -d '{341        "contents": [{342          "parts": [343            {"text": "An atmospheric ambient track."}344          ]345        }],346        "generationConfig": {347          "responseModalities": ["AUDIO", "TEXT"],348          "responseFormat": { "audio": { "mimeType": "audio/wav" } }349        }350      }'351352## Parse the response353354The response from Lyria 3.5 contains multiple parts. Text parts contain the355generated lyrics or a JSON description of the song structure. Parts with356`inline_data` contain the audio bytes.357358> [!IMPORTANT]359> **Important:** You should not assume the lyrics are always the first part. Always iterate through all parts and check the type of each one.360361### Python362363    lyrics = []364    audio_data = None365366    for part in response.parts:367        if part.text is not None:368            lyrics.append(part.text)369        elif part.inline_data is not None:370            audio_data = part.inline_data.data371372    if lyrics:373        print("Lyrics:\n" + "\n".join(lyrics))374375    if audio_data:376        with open("output.mp3", "wb") as f:377            f.write(audio_data)378379### JavaScript380381    const lyrics = [];382    let audioData = null;383384    for (const part of response.candidates[0].content.parts) {385      if (part.text) {386        lyrics.push(part.text);387      } else if (part.inlineData) {388        audioData = Buffer.from(part.inlineData.data, "base64");389      }390    }391392    if (lyrics.length) {393      console.log("Lyrics:\n" + lyrics.join("\n"));394    }395396    if (audioData) {397      fs.writeFileSync("output.mp3", audioData);398    }399400### Go401402    var lyrics []string403    var audioData []byte404405    for _, part := range result.Candidates[0].Content.Parts {406        if part.Text != "" {407            lyrics = append(lyrics, part.Text)408        } else if part.InlineData != nil {409            audioData = part.InlineData.Data410        }411    }412413    if len(lyrics) > 0 {414        fmt.Println("Lyrics:\n" + strings.Join(lyrics, "\n"))415    }416417    if audioData != nil {418        err := os.WriteFile("output.mp3", audioData, 0644)419        if err != nil {420            log.Fatal(err)421        }422    }423424### Java425426    List<String> lyrics = new ArrayList<>();427    byte[] audioData = null;428429    for (Part part : response.parts()) {430      if (part.text().isPresent()) {431        lyrics.add(part.text().get());432      } else if (part.inlineData().isPresent()) {433        audioData = part.inlineData().get().data().get();434      }435    }436437    if (!lyrics.isEmpty()) {438      System.out.println("Lyrics:\n" + String.join("\n", lyrics));439    }440441    if (audioData != null) {442      Files.write(Paths.get("output.mp3"), audioData);443    }444445### C#446447    var lyrics = new List<string>();448    byte[] audioData = null;449450    foreach (var part in response.Candidates[0].Content.Parts) {451      if (part.Text != null) {452        lyrics.Add(part.Text);453      } else if (part.InlineData != null) {454        audioData = part.InlineData.Data;455      }456    }457458    if (lyrics.Count > 0) {459      Console.WriteLine("Lyrics:\n" + string.Join("\n", lyrics));460    }461462    if (audioData != null) {463      await File.WriteAllBytesAsync("output.mp3", audioData);464    }465466### REST467468    # The output from the REST API is a JSON object containing base64 encoded data.469    # You can extract the text or the audio data using a tool like jq.470    # To extract the audio and save it to a file:471    curl ... | jq -r '.candidates[0].content.parts[] | select(.inlineData) | .inlineData.data' | base64 -d > output.mp3472473## Generate music from images474475Lyria 3.5 supports multimodal inputs --- you can provide up to **10 images**476alongside your text prompt and the model will compose music inspired by the477visual content.478479### Python480481    from PIL import Image482483    image = Image.open("desert_sunset.jpg")484485    response = client.models.generate_content(486        model="lyria-3.5",487        contents=[488            "An atmospheric ambient track inspired by the mood and "489            "colors in this image.",490            image,491        ],492    )493494### JavaScript495496    const imageData = fs.readFileSync("desert_sunset.jpg");497    const base64Image = imageData.toString("base64");498499    const response = await ai.models.generateContent({500      model: "lyria-3.5",501      contents: [502        { text: "An atmospheric ambient track inspired by the mood " +503                "and colors in this image." },504        {505          inlineData: {506            mimeType: "image/jpeg",507            data: base64Image,508          },509        },510      ],511512    });513514### Go515516    imgData, err := os.ReadFile("desert_sunset.jpg")517    if err != nil {518        log.Fatal(err)519    }520521    parts := []*genai.Part{522        genai.NewPartFromText("An atmospheric ambient track inspired " +523            "by the mood and colors in this image."),524        &genai.Part{525            InlineData: &genai.Blob{526                MIMEType: "image/jpeg",527                Data:     imgData,528            },529        },530    }531532    contents := []*genai.Content{533        genai.NewContentFromParts(parts, genai.RoleUser),534    }535536    result, err := client.Models.GenerateContent(537        ctx,538        "lyria-3.5",539        contents,540        nil,541    )542543### Java544545    GenerateContentResponse response = client.models.generateContent(546        "lyria-3.5",547        Content.fromParts(548            Part.fromText("An atmospheric ambient track inspired by "549                + "the mood and colors in this image."),550            Part.fromBytes(551                Files.readAllBytes(Path.of("desert_sunset.jpg")),552                "image/jpeg")));553554### REST555556    curl -s -X POST \557      "https://generativelanguage.googleapis.com/v1beta/models/lyria-3.5:generateContent" \558      -H "x-goog-api-key: $GEMINI_API_KEY" \559      -H 'Content-Type: application/json' \560      -d "{561        \"contents\": [{562          \"parts\":[563              {\"text\": \"An atmospheric ambient track inspired by the mood and colors in this image.\"},564              {565                \"inline_data\": {566                  \"mime_type\":\"image/jpeg\",567                  \"data\": \"<BASE64_IMAGE_DATA>\"568                }569              }570          ]571        }]572      }"573574### C#575576    var response = await client.Models.GenerateContentAsync(577      model: "lyria-3.5",578      contents: new List<Part> {579        Part.FromText("An atmospheric ambient track inspired by the mood and colors in this image."),580        Part.FromBytes(await File.ReadAllBytesAsync("desert_sunset.jpg"), "image/jpeg")581      }582    );583584![](https://storage.googleapis.com/generativeai-downloads/images/desert_sunset.jpg)  585586## Provide custom lyrics587588You can write your own lyrics and include them in the prompt. Use section tags589like `[Verse]`, `[Chorus]`, and `[Bridge]` to help the model understand the590song structure:591592### Python593594    prompt = """595    Create a dreamy indie pop song with the following lyrics:596597    [Verse 1]598    Walking through the neon glow,599    city lights reflect below,600    every shadow tells a story,601    every corner, fading glory.602603    [Chorus]604    We are the echoes in the night,605    burning brighter than the light,606    hold on tight, don't let me go,607    we are the echoes down below.608609    [Verse 2]610    Footsteps lost on empty streets,611    rhythms sync to heartbeats,612    whispers carried by the breeze,613    dancing through the autumn leaves.614    """615616    response = client.models.generate_content(617        model="lyria-3.5",618        contents=prompt,619    )620621### JavaScript622623    const prompt = `624    Create a dreamy indie pop song with the following lyrics:625626    [Verse 1]627    Walking through the neon glow,628    city lights reflect below,629    every shadow tells a story,630    every corner, fading glory.631632    [Chorus]633    We are the echoes in the night,634    burning brighter than the light,635    hold on tight, don't let me go,636    we are the echoes down below.637638    [Verse 2]639    Footsteps lost on empty streets,640    rhythms sync to heartbeats,641    whispers carried by the breeze,642    dancing through the autumn leaves.643    `;644645    const response = await ai.models.generateContent({646      model: "lyria-3.5",647      contents: prompt,648649    });650651### Go652653    prompt := `654    Create a dreamy indie pop song with the following lyrics:655656    [Verse 1]657    Walking through the neon glow,658    city lights reflect below,659    every shadow tells a story,660    every corner, fading glory.661662    [Chorus]663    We are the echoes in the night,664    burning brighter than the light,665    hold on tight, don't let me go,666    we are the echoes down below.667668    [Verse 2]669    Footsteps lost on empty streets,670    rhythms sync to heartbeats,671    whispers carried by the breeze,672    dancing through the autumn leaves.673    `674675    result, err := client.Models.GenerateContent(676        ctx,677        "lyria-3.5",678        genai.Text(prompt),679        nil,680    )681682### Java683684    String prompt = """685        Create a dreamy indie pop song with the following lyrics:686687        [Verse 1]688        Walking through the neon glow,689        city lights reflect below,690        every shadow tells a story,691        every corner, fading glory.692693        [Chorus]694        We are the echoes in the night,695        burning brighter than the light,696        hold on tight, don't let me go,697        we are the echoes down below.698699        [Verse 2]700        Footsteps lost on empty streets,701        rhythms sync to heartbeats,702        whispers carried by the breeze,703        dancing through the autumn leaves.704        """;705706    GenerateContentResponse response = client.models.generateContent(707        "lyria-3.5",708        prompt);709710### C#711712    var prompt = @"713    Create a dreamy indie pop song with the following lyrics:714715    [Verse 1]716    Walking through the neon glow,717    city lights reflect below,718    every shadow tells a story,719    every corner, fading glory.720721    [Chorus]722    We are the echoes in the night,723    burning brighter than the light,724    hold on tight, don't let me go,725    we are the echoes down below.726727    [Verse 2]728    Footsteps lost on empty streets,729    rhythms sync to heartbeats,730    whispers carried by the breeze,731    dancing through the autumn leaves.732    ";733734    var response = await client.Models.GenerateContentAsync(735      model: "lyria-3.5",736      contents: prompt737    );738739### REST740741    curl -s -X POST \742      "https://generativelanguage.googleapis.com/v1beta/models/lyria-3.5:generateContent" \743      -H "x-goog-api-key: $GEMINI_API_KEY" \744      -H "Content-Type: application/json" \745      -d '{746        "contents": [{747          "parts": [748            {"text": "Create a dreamy indie pop song with the following lyrics: ..."}749          ]750        }]751      }'752753## Control timing and structure754755You can specify exactly what happens at specific moments in the song using756timestamps. This is useful for controlling when instruments enter, when lyrics757are delivered, and how the song progresses:758759### Python760761    prompt = """762    [0:00 - 0:10] Intro: Begin with a soft lo-fi beat and muffled763                  vinyl crackle.764    [0:10 - 0:30] Verse 1: Add a warm Fender Rhodes piano melody765                  and gentle vocals singing about a rainy morning.766    [0:30 - 0:50] Chorus: Full band with upbeat drums and soaring767                  synth leads. The lyrics are hopeful and uplifting.768    [0:50 - 1:00] Outro: Fade out with the piano melody alone.769    """770771    response = client.models.generate_content(772        model="lyria-3.5",773        contents=prompt,774    )775776### JavaScript777778    const prompt = `779    [0:00 - 0:10] Intro: Begin with a soft lo-fi beat and muffled780                  vinyl crackle.781    [0:10 - 0:30] Verse 1: Add a warm Fender Rhodes piano melody782                  and gentle vocals singing about a rainy morning.783    [0:30 - 0:50] Chorus: Full band with upbeat drums and soaring784                  synth leads. The lyrics are hopeful and uplifting.785    [0:50 - 1:00] Outro: Fade out with the piano melody alone.786    `;787788    const response = await ai.models.generateContent({789      model: "lyria-3.5",790      contents: prompt,791792    });793794### Go795796    prompt := `797    [0:00 - 0:10] Intro: Begin with a soft lo-fi beat and muffled798                  vinyl crackle.799    [0:10 - 0:30] Verse 1: Add a warm Fender Rhodes piano melody800                  and gentle vocals singing about a rainy morning.801    [0:30 - 0:50] Chorus: Full band with upbeat drums and soaring802                  synth leads. The lyrics are hopeful and uplifting.803    [0:50 - 1:00] Outro: Fade out with the piano melody alone.804    `805806    result, err := client.Models.GenerateContent(807        ctx,808        "lyria-3.5",809        genai.Text(prompt),810        nil,811    )812813### Java814815    String prompt = """816        [0:00 - 0:10] Intro: Begin with a soft lo-fi beat and muffled817                      vinyl crackle.818        [0:10 - 0:30] Verse 1: Add a warm Fender Rhodes piano melody819                      and gentle vocals singing about a rainy morning.820        [0:30 - 0:50] Chorus: Full band with upbeat drums and soaring821                      synth leads. The lyrics are hopeful and uplifting.822        [0:50 - 1:00] Outro: Fade out with the piano melody alone.823        """;824825    GenerateContentResponse response = client.models.generateContent(826        "lyria-3.5",827        prompt);828829### C#830831    var prompt = @"832    [0:00 - 0:10] Intro: Begin with a soft lo-fi beat and muffled833                  vinyl crackle.834    [0:10 - 0:30] Verse 1: Add a warm Fender Rhodes piano melody835                  and gentle vocals singing about a rainy morning.836    [0:30 - 0:50] Chorus: Full band with upbeat drums and soaring837                  synth leads. The lyrics are hopeful and uplifting.838    [0:50 - 1:00] Outro: Fade out with the piano melody alone.839    ";840841    var response = await client.Models.GenerateContentAsync(842      model: "lyria-3.5",843      contents: prompt844    );845846### REST847848    curl -s -X POST \849      "https://generativelanguage.googleapis.com/v1beta/models/lyria-3.5:generateContent" \850      -H "x-goog-api-key: $GEMINI_API_KEY" \851      -H "Content-Type: application/json" \852      -d '{853        "contents": [{854          "parts": [855            {"text": "[0:00 - 0:10] Intro: ..."}856          ]857        }]858      }'859860## Generate instrumental tracks861862For background music, game soundtracks, or any use case where vocals are not863required, you can prompt the model to produce instrumental-only tracks:864865### Python866867    response = client.models.generate_content(868        model="lyria-3-clip-preview",869        contents="A bright chiptune melody in C Major, retro 8-bit "870                 "video game style. Instrumental only, no vocals.",871    )872873### JavaScript874875    const response = await ai.models.generateContent({876      model: "lyria-3-clip-preview",877      contents: "A bright chiptune melody in C Major, retro 8-bit " +878                "video game style. Instrumental only, no vocals.",879880    });881882### Go883884    result, err := client.Models.GenerateContent(885        ctx,886        "lyria-3-clip-preview",887        genai.Text("A bright chiptune melody in C Major, retro 8-bit " +888                   "video game style. Instrumental only, no vocals."),889        nil,890    )891892### Java893894    GenerateContentResponse response = client.models.generateContent(895        "lyria-3-clip-preview",896        "A bright chiptune melody in C Major, retro 8-bit "897            + "video game style. Instrumental only, no vocals.");898899### C#900901    var response = await client.Models.GenerateContentAsync(902      model: "lyria-3-clip-preview",903      contents: "A bright chiptune melody in C Major, retro 8-bit " +904                "video game style. Instrumental only, no vocals."905    );906907### REST908909    curl -s -X POST \910      "https://generativelanguage.googleapis.com/v1beta/models/lyria-3-clip-preview:generateContent" \911      -H "x-goog-api-key: $GEMINI_API_KEY" \912      -H "Content-Type: application/json" \913      -d '{914        "contents": [{915          "parts": [916            {"text": "A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals."}917          ]918        }]919      }'920921> [!TIP]922> **Tip:** For [best results](https://ai.google.dev/gemini-api/docs/generate-content/music-generation#prompt-guide), include "Instrumental only, no vocals" explicitly in your prompt.923924## Generate music in different languages925926Lyria 3.5 generates lyrics in the language of your prompt. To generate a song927with French lyrics, write your prompt in French. The model adapts its vocal928style and pronunciation to match the language.929930### Python931932    response = client.models.generate_content(933        model="lyria-3.5",934        contents="Crée une chanson pop romantique en français sur un "935                 "coucher de soleil à Paris. Utilise du piano et de "936                 "la guitare acoustique.",937    )938939### JavaScript940941    const response = await ai.models.generateContent({942      model: "lyria-3.5",943      contents: "Crée une chanson pop romantique en français sur un " +944                "coucher de soleil à Paris. Utilise du piano et de " +945                "la guitare acoustique.",946947    });948949### Go950951    result, err := client.Models.GenerateContent(952        ctx,953        "lyria-3.5",954        genai.Text("Crée une chanson pop romantique en français sur un " +955                   "coucher de soleil à Paris. Utilise du piano et de " +956                   "la guitare acoustique."),957        nil,958    )959960### Java961962    GenerateContentResponse response = client.models.generateContent(963        "lyria-3.5",964        "Crée une chanson pop romantique en français sur un "965            + "coucher de soleil à Paris. Utilise du piano et de "966            + "la guitare acoustique.");967968### C#969970    var response = await client.Models.GenerateContentAsync(971      model: "lyria-3.5",972      contents: "Crée une chanson pop romantique en français sur un " +973                "coucher de soleil à Paris. Utilise du piano et de " +974                "la guitare acoustique."975    );976977### REST978979    curl -s -X POST \980      "https://generativelanguage.googleapis.com/v1beta/models/lyria-3.5:generateContent" \981      -H "x-goog-api-key: $GEMINI_API_KEY" \982      -H "Content-Type: application/json" \983      -d '{984        "contents": [{985          "parts": [986            {"text": "Crée une chanson pop romantique en français sur un coucher de soleil à Paris. Utilise du piano et de la guitare acoustique."}987          ]988        }]989      }'990991## Model intelligence992993Lyria 3.5 analyzes your prompt process where the994model reasons through musical structure (intro, verse, chorus, bridge, etc.)995based on your prompt.996This happens before the audio is generated and ensures structural coherence and997musicality.998999> [!IMPORTANT]1000> **Important:** While Lyria 3.5 uses a prompt rewriter internally to interpret natural language instructions, it does **not** expose intermediate "thought" blocks or thought signatures to the user.10011002## Interactions API10031004You can use Lyria 3.5 models with the [Interactions API](https://ai.google.dev/gemini-api/docs/interactions-overview);1005a unified interface for interacting with Gemini models and agents. It simplifies1006state management and long-running tasks for complex multimodal use cases.10071008### Python10091010    import base641011    from google import genai10121013    client = genai.Client()10141015    interaction = client.interactions.create(1016        model="lyria-3.5",1017        input="A melancholic jazz fusion track in D minor, " +1018              "featuring a smooth saxophone melody, walking bass line, " +1019              "and complex drum rhythms.",1020    )10211022    generated_audio = interaction.output_audio1023    if generated_audio:1024        with open("interaction_output.mp3", "wb") as f:1025            f.write(base64.b64decode(generated_audio.data))1026        print("Audio saved to interaction_output.mp3")10271028    lyrics = interaction.output_text1029    if lyrics:1030        print(f"Lyrics:\n{lyrics}")10311032### JavaScript10331034    import { GoogleGenAI } from '@google/genai';1035    import * as fs from 'fs';10361037    const client = new GoogleGenAI({});10381039    const interaction = await client.interactions.create({1040      model: 'lyria-3.5',1041      input: 'A melancholic jazz fusion track in D minor, ' +1042             'featuring a smooth saxophone melody, walking bass line, ' +1043             'and complex drum rhythms.',1044    });10451046    const generatedAudio = interaction.output_audio;1047    if (generatedAudio) {1048      fs.writeFileSync('interaction_output.mp3', Buffer.from(generatedAudio.data, 'base64'));1049      console.log('Audio saved to interaction_output.mp3');1050    }10511052    const lyrics = interaction.output_text;1053    if (lyrics) {1054      console.log(`Lyrics:\n${lyrics}`);1055    }10561057### REST10581059    curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \1060    -H "Content-Type: application/json" \1061    -H "x-goog-api-key: $GEMINI_API_KEY" \1062    -d '{1063        "model": "lyria-3.5",1064        "input": "A melancholic jazz fusion track in D minor, featuring a smooth saxophone melody, walking bass line, and complex drum rhythms."1065    }'10661067## Prompting guide10681069To learn how to craft effective prompts for music genres, instruments,1070song structure, custom lyrics, and vocal delivery styles, see the1071[Lyria prompt guide](https://ai.google.dev/gemini-api/docs/lyria-prompt-guide).10721073## Best practices10741075- **Iterate with Clip first.** Use the faster `lyria-3-clip-preview` model to experiment with prompts before committing to a full-length generation with `lyria-3.5`.1076- **Be specific.** Vague prompts produce generic results. Mention instruments, BPM, key, mood, and structure for the best output.1077- **Match your language.** Prompt in the language you want the lyrics in.1078- **Use section tags.** `[Verse]`, `[Chorus]`, `[Bridge]` tags give the model clear structure to follow.1079- **Separate lyrics from instructions.** When providing custom lyrics, clearly separate them from your musical direction instructions.10801081## Limitations10821083- **Safety**: All prompts are checked by safety filters. Prompts that trigger the filters will be blocked. This includes prompts that request specific artist voices or the generation of copyrighted lyrics.1084- **Watermarking** : All generated audio includes a [SynthID audio watermark](https://ai.google.dev/responsible/docs/safeguards/synthid) for identification. This watermark is imperceptible to the human ear and does not affect the listening experience.1085- **Multi-turn editing**: Music generation is a single-turn process. Iterative editing or refining a generated clip through multiple prompts is not supported in the current version of Lyria 3.5.1086- **Length**: The Clip model always generates 30-second clips. The Pro model generates songs that last a couple of minutes; exact duration can be influenced through your prompt.1087- **Determinism**: Results may vary between calls, even with the same prompt.10881089## What's next10901091- Check [pricing](https://ai.google.dev/gemini-api/docs/generate-content/pricing) for Lyria 3.5 models.1092- Try [real-time, streaming music generation](https://ai.google.dev/gemini-api/docs/generate-content/realtime-music-generation) with Lyria RealTime.1093- Generate multi-speaker conversations with the [TTS models](https://ai.google.dev/gemini-api/docs/generate-content/speech-generation).1094- Discover how to generate [images](https://ai.google.dev/gemini-api/docs/generate-content/image-generation) or [videos](https://ai.google.dev/gemini-api/docs/generate-content/video).1095- Find out how Gemini can [understand audio files](https://ai.google.dev/gemini-api/docs/generate-content/audio).1096- Have a real-time conversation with Gemini using the [Live API](https://ai.google.dev/gemini-api/docs/generate-content/live).
Files main
Menu

Theme