Skip to content

Commit 448f10f

Browse files
committed
feat: add Lyria music generation example to README demonstrating audio output handling
1 parent b391021 commit 448f10f

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,37 @@ interaction.outputs().forEach(content -> {
189189
});
190190
```
191191

192+
### Lyria Music Generation
193+
```java
194+
import io.github.glaforge.gemini.interactions.model.Content.*;
195+
import io.github.glaforge.gemini.interactions.model.InteractionParams.ModelInteractionParams;
196+
import io.github.glaforge.gemini.interactions.model.Interaction.Modality;
197+
import java.nio.file.Files;
198+
import java.nio.file.Paths;
199+
200+
ModelInteractionParams request = ModelInteractionParams.builder()
201+
.model("models/lyria-3-clip-preview")
202+
.input("An epic song with opera voices about a quest. Deep synths and a speeding up tempo.")
203+
.responseModalities(Modality.AUDIO, Modality.TEXT)
204+
.build();
205+
206+
Interaction interaction = client.create(request);
207+
208+
interaction.outputs().forEach(content -> {
209+
if (content instanceof TextContent text) {
210+
System.out.println("Lyrics / Structure Generated:\\n" + text.text());
211+
}
212+
if (content instanceof AudioContent audio) {
213+
// Lyria directly returns an encoded MP3 byte stream!
214+
try {
215+
Files.write(Paths.get("quest-song.mp3"), audio.data());
216+
} catch (Exception e) {
217+
e.printStackTrace();
218+
}
219+
}
220+
});
221+
```
222+
192223
### Deep Research
193224
```java
194225
import io.github.glaforge.gemini.interactions.model.Interaction;

0 commit comments

Comments
 (0)