Skip to content

Generate Music With Lyrics

This example assumes using Google.Gemini; is in scope and apiKey contains your Google.Gemini API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using var client = new GeminiClient(apiKey);

try
{
    // Generate music with vocals using structure tags and lyrics.
    var result = await client.GenerateMusicAsync(
        prompt: """
            Pop ballad, female vocal, piano accompaniment, 90 BPM, C major

            [Verse]
            Walking through the morning light,
            Everything feels warm and bright.

            [Chorus]
            This is where I want to be,
            Under skies so wide and free.
            """);

}
catch (ApiException ex) when (IsTransientAvailabilityIssue(ex))
{
    AssertTransientAvailability(ex);
}
catch (ApiException ex) when (ex.StatusCode is System.Net.HttpStatusCode.BadRequest)
{
}