Lyria 3 की मदद से संगीत जनरेट करना
Lyria 3, संगीत जनरेट करने वाले Google के मॉडल का परिवार है. यह Gemini API के ज़रिए उपलब्ध है. Lyria 3 की मदद से, टेक्स्ट प्रॉम्प्ट या इमेज से हाई-क्वालिटी वाला 44.1 kHz स्टीरियो ऑडियो जनरेट किया जा सकता है. ये मॉडल, गाने के स्ट्रक्चर को सही तरीके से पेश करते हैं. इनमें वोकल, समय के हिसाब से सेट किए गए बोल, और पूरे इंस्ट्रुमेंटल अरेंजमेंट शामिल हैं.
Lyria 3 फ़ैमिली में दो मॉडल शामिल हैं:
| मॉडल | मॉडल आईडी | इन स्थितियों में बेहतर है | कुल समय | आउटपुट |
|---|---|---|---|---|
| Lyria 3 Clip | lyria-3-clip-preview |
छोटी क्लिप, लूप, झलक | 30 सेकंड | MP3 |
| Lyria 3 Pro | lyria-3-pro-preview |
पूरे गाने, जिनमें वर्स, कोरस, और ब्रिज शामिल हों | कुछ मिनट (प्रॉम्प्ट का इस्तेमाल करके कंट्रोल किया जा सकता है) | MP3 |
दोनों मॉडल का इस्तेमाल, नए Interactions API की मदद से किया जा सकता है. यह मल्टीमॉडल इनपुट (टेक्स्ट और इमेज) के साथ काम करता है. साथ ही, 44.1 kHz हाई-फ़िडेलिटी स्टीरियो ऑडियो जनरेट करता है.
म्यूज़िक क्लिप जनरेट करना
Lyria 3 Clip मॉडल हमेशा 30 सेकंड की क्लिप जनरेट करता है. क्लिप जनरेट करने के लिए, टेक्स्ट प्रॉम्प्ट के साथ interactions.create तरीके को कॉल करें. जवाब में, steps स्कीमा में ऑडियो के साथ-साथ, जनरेट किए गए बोल और गाने का स्ट्रक्चर हमेशा शामिल होता है.
Python
import base64
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="lyria-3-clip-preview",
input="Create a 30-second cheerful acoustic folk song with guitar and harmonica.",
)
for step in interaction.steps:
if step.type == "model_output":
for content_block in step.content:
if content_block.type == "audio":
print(f"Generated audio with mime_type: {content_block.mime_type}")
with open("music.mp3", "wb") as f:
f.write(base64.b64decode(content_block.data))
elif content_block.type == "text":
print(f"Lyrics: {content_block.text}")
JavaScript
import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: 'lyria-3-clip-preview',
input: 'Create a 30-second cheerful acoustic folk song with ' +
'guitar and harmonica.',
});
for (const step of interaction.steps) {
if (step.type === 'model_output') {
for (const contentBlock of step.content) {
if (contentBlock.type === 'audio') {
console.log(`Generated audio with mime_type: ${contentBlock.mimeType}`);
fs.writeFileSync('music.mp3', Buffer.from(contentBlock.data, 'base64'));
} else if (contentBlock.type === 'text') {
console.log(`Lyrics: ${contentBlock.text}`);
}
}
}
}
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-clip-preview",
"input": "Create a 30-second cheerful acoustic folk song with guitar and harmonica."
}'
पूरा गाना जनरेट करना
lyria-3-pro-preview मॉडल का इस्तेमाल करके, पूरे गाने जनरेट करें. इनकी अवधि कुछ मिनट होती है. Pro मॉडल, संगीत की संरचना को समझता है. साथ ही, अलग-अलग वर्स, कोरस, और ब्रिज के साथ कंपोज़िशन बना सकता है. अपने प्रॉम्प्ट में अवधि तय करके (जैसे, "दो मिनट का गाना बनाओ") या स्ट्रक्चर तय करने के लिए टाइमस्टैंप का इस्तेमाल करके, अवधि पर असर डाला जा सकता है.
Python
interaction = client.interactions.create(
model="lyria-3-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-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.',
});
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": "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 के लिए, response_mime_type सेट करके WAV फ़ॉर्मैट में आउटपुट का अनुरोध भी किया जा सकता है.
Python
interaction = client.interactions.create(
model="lyria-3-pro-preview",
input="An atmospheric ambient track.",
response_modalities=["audio", "text"],
response_mime_type="audio/wav",
)
JavaScript
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: 'An atmospheric ambient track.',
responseModalities: ["audio", "text"],
responseMimeType: "audio/wav",
});
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-pro-preview",
"input": "An atmospheric ambient track.",
"responseModalities": ["audio", "text"],
"responseMimeType": "audio/wav"
}'
जवाब को पार्स करना
Lyria 3 के जवाब में, steps स्कीमा के अंदर कई कॉन्टेंट ब्लॉक शामिल हैं.
इंटरैक्शन से चरणों का क्रम मिलता है. इनमें से model_output चरणों में जनरेट किया गया कॉन्टेंट होता है.
टेक्स्ट कॉन्टेंट ब्लॉक में, जनरेट किए गए बोल या गाने की संरचना का JSON ब्यौरा शामिल होता है.
audio टाइप वाले कॉन्टेंट ब्लॉक में, base64 के कोड में बदला गया ऑडियो डेटा होता है.
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);
}
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 में मल्टीमॉडल इनपुट का इस्तेमाल किया जा सकता है. input सूची में टेक्स्ट प्रॉम्प्ट के साथ-साथ, ज़्यादा से ज़्यादा 10 इमेज दी जा सकती हैं. इसके बाद, मॉडल विज़ुअल कॉन्टेंट से मिलता-जुलता संगीत तैयार करेगा.
Python
uploaded_image = client.files.upload(file="desert_sunset.jpg")
response = client.interactions.create(
model="lyria-3-pro-preview",
input=[
{"type": "text", "text": "An atmospheric ambient track inspired by the mood and colors in this image."},
{
"type": "image",
"uri": uploaded_image.uri,
"mime_type": uploaded_image.mime_type
}
],
)
JavaScript
const uploadedImage = await client.files.upload({
file: "desert_sunset.jpg",
config: { mimeType: "image/jpeg" }
});
const interaction = await client.interactions.create({
model: 'lyria-3-pro-preview',
input: [
{ type: 'text', text: 'An atmospheric ambient track inspired by the mood and colors in this image.' },
{
type: 'image',
uri: uploadedImage.uri,
mimeType: uploadedImage.mimeType
}
],
});
REST
# First upload the image using the Files API, then use the URI:
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-pro-preview",
"input": [
{"type": "text", "text": "An atmospheric ambient track inspired by the mood and colors in this image."},
{"type": "image", "uri": "YOUR_FILE_URI", "mime_type": "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.
"""
interaction = client.interactions.create(
model="lyria-3-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-pro-preview',
input: prompt,
});
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-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-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-pro-preview',
input: prompt,
});
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-pro-preview",
"input": "[0:00 - 0:10] Intro: ..."
}'
इंस्ट्रुमेंटल ट्रैक जनरेट करना
बैकग्राउंड संगीत, गेम के साउंडट्रैक या ऐसे किसी भी इस्तेमाल के उदाहरण के लिए जहां वोकल की ज़रूरत नहीं है, मॉडल को सिर्फ़ इंस्ट्रुमेंटल ट्रैक बनाने के लिए कहा जा सकता है:
Python
interaction = client.interactions.create(
model="lyria-3-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-clip-preview',
input: 'A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals.',
});
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-clip-preview",
"input": "A bright chiptune melody in C Major, retro 8-bit video game style. Instrumental only, no vocals."
}'
अलग-अलग भाषाओं में संगीत जनरेट करना
Lyria 3, प्रॉम्प्ट में इस्तेमाल की गई भाषा में गाने के बोल जनरेट करता है. फ़्रेंच भाषा में बोल वाला गाना जनरेट करने के लिए, प्रॉम्प्ट को फ़्रेंच भाषा में लिखें. यह मॉडल, भाषा के हिसाब से अपनी आवाज़ और उच्चारण को बदलता है.
Python
interaction = client.interactions.create(
model="lyria-3-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-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.',
});
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-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, आपके प्रॉम्प्ट का विश्लेषण करता है. इसमें मॉडल, आपके प्रॉम्प्ट के आधार पर म्यूज़िकल स्ट्रक्चर (इंट्रो, वर्स, कोरस, ब्रिज वगैरह) के बारे में बताता है. यह प्रोसेस, ऑडियो जनरेट होने से पहले होती है. इससे यह पक्का किया जाता है कि ऑडियो में स्ट्रक्चरल कोहेरेंस और म्यूज़िकैलिटी हो.
प्रॉम्प्ट से जुड़ी गाइड
आपका प्रॉम्प्ट जितना सटीक होगा, नतीजे उतने ही बेहतर मिलेंगे. जनरेट करने की प्रोसेस को बेहतर बनाने के लिए, यहां दी गई जानकारी शामिल करें:
- शैली: किसी शैली या शैलियों के मिश्रण के बारे में बताएं. जैसे, "लो-फ़ाई हिप हॉप", "जैज़ फ़्यूज़न", "सिनेमैटिक ऑर्केस्ट्रल").
- वाद्य यंत्र: खास वाद्य यंत्रों के नाम (जैसे, "फ़ेंडर रोड्स पियानो", "स्लाइड गिटार", "टीआर-808 ड्रम मशीन").
- बीपीएम: टेंपो सेट करें. जैसे, "120 बीपीएम", "70 बीपीएम के आस-पास का धीमा टेंपो".
- की/स्केल: म्यूज़िकल की के बारे में बताएं. जैसे, "जी मेजर में", "डी माइनर".
- मूड और माहौल: जानकारी देने वाले विशेषणों का इस्तेमाल करें. जैसे, "यादें ताज़ा करने वाला", "आक्रामक", "अलौकिक", "सपनों जैसा".
- स्ट्रक्चर: गाने के स्ट्रक्चर को कंट्रोल करने के लिए,
[Verse],[Chorus],[Bridge],[Intro],[Outro]जैसे टैग या टाइमस्टैंप का इस्तेमाल करें. - अवधि: क्लिप मॉडल हमेशा 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-pro-previewकी मदद से पूरा कॉन्टेंट जनरेट करने से पहले, प्रॉम्प्ट आज़माने के लिएlyria-3-clip-previewमॉडल का इस्तेमाल करें. - सटीक जानकारी दें. अस्पष्ट प्रॉम्प्ट से सामान्य नतीजे मिलते हैं. बेहतरीन आउटपुट पाने के लिए, इंस्ट्रूमेंट, बीपीएम, की, मूड, और स्ट्रक्चर के बारे में जानकारी दें.
- अपनी भाषा से मिलती-जुलती भाषा चुनें. आपको जिस भाषा में गाने के बोल चाहिए उस भाषा में प्रॉम्प्ट लिखें.
- सेक्शन टैग इस्तेमाल करें.
[Verse],[Chorus],[Bridge]टैग की मदद से, मॉडल को जवाब देने के लिए एक साफ़ स्ट्रक्चर मिलता है. - बोल को निर्देशों से अलग करें. अपनी पसंद के मुताबिक़ बोल देते समय, उन्हें संगीत से जुड़े निर्देशों से अलग रखें.
सीमाएं
- सुरक्षा: सभी प्रॉम्प्ट की जांच सुरक्षा फ़िल्टर करते हैं. ऐसे प्रॉम्प्ट ब्लॉक कर दिए जाएंगे जिनसे फ़िल्टर ट्रिगर होते हैं. इसमें ऐसे प्रॉम्प्ट शामिल हैं जिनमें किसी खास कलाकार की आवाज़ में गाने बनाने या कॉपीराइट वाले बोल जनरेट करने का अनुरोध किया गया हो.
- वॉटरमार्क लगाना: जनरेट किए गए सभी ऑडियो में, पहचान के लिए SynthID ऑडियो वॉटरमार्क शामिल होता है. यह वॉटरमार्क लोगों को सुनाई नहीं देता. साथ ही, इससे सुनने के अनुभव पर कोई असर नहीं पड़ता.
- एक से ज़्यादा बार बदलाव करना: संगीत जनरेट करने की प्रोसेस एक बार में पूरी हो जाती है. Lyria 3 के मौजूदा वर्शन में, जनरेट की गई क्लिप में कई बार बदलाव करने या उसे बेहतर बनाने के लिए, कई प्रॉम्प्ट इस्तेमाल नहीं किए जा सकते.
- अवधि: क्लिप मॉडल हमेशा 30 सेकंड की क्लिप जनरेट करता है. Pro मॉडल, कुछ मिनट की अवधि वाले गाने जनरेट करता है. हालांकि, प्रॉम्प्ट में अवधि के बारे में जानकारी देकर, गाने की अवधि को बदला जा सकता है.
- निश्चितता: एक ही प्रॉम्प्ट के लिए, कॉल के हिसाब से नतीजे अलग-अलग हो सकते हैं.
आगे क्या करना है
- Lyria 3 मॉडल के लिए कीमत देखें,
- Lyria RealTime की मदद से, रीयल टाइम में म्यूज़िक जनरेट करने और उसे स्ट्रीम करने की सुविधा आज़माएँ,
- टीटीएस मॉडल की मदद से, एक से ज़्यादा स्पीकर वाली बातचीत जनरेट करें,
- इमेज या वीडियो जनरेट करने का तरीका जानें,
- जानें कि Gemini ऑडियो फ़ाइलों को कैसे समझ सकता है,
- Live API का इस्तेमाल करके, Gemini के साथ रीयल-टाइम में बातचीत करें.