Skip to content

Commit c786cad

Browse files
committed
feat: add minimax 15 snippets and
1 parent 7c1872e commit c786cad

4 files changed

Lines changed: 116 additions & 0 deletions

File tree

packages/openapi/descriptions/audio.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ export default {
6767
desc: `The length of the song to generate in milliseconds. This parameter may not always be respected by the model, and the actual audio length can differ.`,
6868
},
6969
},
70+
output_format: {
71+
minimax: {
72+
desc: `The output format of the audio. Options: url or hex.`,
73+
},
74+
},
7075
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"title": "Generate an audio",
3+
"docs": "https://docs.aimlapi.com/api-references/music-models/minimax/music-15",
4+
"payload": {
5+
"baseUrl": "https://api.aimlapi.com/v2",
6+
"apiKey": "<YOUR_API_KEY>"
7+
}
8+
}

shared/snippets/minimax/15/js.hbs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import fs from "fs";
2+
import fetch from "node-fetch";
3+
4+
const main = async () => {
5+
const url = "{{baseUrl}}/generate/audio/minimax/generate";
6+
const promt = "A calm and soothing instrumental music with gentle piano and soft strings.";
7+
const lyrics = `[Verse]\nStreetlights flicker, the night breeze sighs\nShadows stretch as I walk alone\nAn old coat wraps my silent sorrow\nWandering, longing, where should I go\n[Chorus]\nPushing the wooden door, the aroma spreads\nIn a familiar corner, a stranger gazes back\nWarm lights flicker, memories awaken\nIn this small cafe, I find my way\n[Verse]\nRaindrops tap on the windowpane\nA melody plays, soft and low\nThe clink of cups, the murmur of dreams\nIn this haven, I find my home\n[Chorus]\nPushing the wooden door, the aroma spreads\nIn a familiar corner, a stranger gazes back\nWarm lights flicker, memories awaken\nIn this small cafe, I find my way`;
8+
const output_format = "hex";
9+
10+
const payload = {
11+
model: '{{model}}'',
12+
prompt: promt,
13+
lyrics: lyrics,
14+
output_format: output_format
15+
};
16+
17+
const headers = {
18+
"Content-Type": "application/json",
19+
"Authorization": `Bearer {{apiKey}}`,
20+
};
21+
22+
try {
23+
const response = await fetch(url, {
24+
method: "POST",
25+
headers: headers,
26+
body: JSON.stringify(payload),
27+
});
28+
29+
const data = await response.json();
30+
31+
if (response.ok) {
32+
const audioHex = data.data.audio;
33+
const decodedHex = Buffer.from(audioHex, "hex");
34+
35+
fs.writeFileSync("generated_audio.mp3", decodedHex);
36+
console.log("Audio file saved as generated_audio.mp3");
37+
} else {
38+
console.error("Failed to generate music:", data);
39+
}
40+
} catch (error) {
41+
console.error("Error during API request:", error);
42+
}
43+
}
44+
45+
main();

shared/snippets/minimax/15/py.hbs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import requests
2+
3+
def main():
4+
url = '{{baseUrl}}/generate/audio/minimax/generate'
5+
promt = "A calm and soothing instrumental music with gentle piano and soft strings."
6+
lyrics = """[Verse]
7+
Streetlights flicker, the night breeze sighs
8+
Shadows stretch as I walk alone
9+
An old coat wraps my silent sorrow
10+
Wandering, longing, where should I go
11+
[Chorus]
12+
Pushing the wooden door, the aroma spreads
13+
In a familiar corner, a stranger gazes back
14+
Warm lights flicker, memories awaken
15+
In this small cafe, I find my way
16+
[Verse]
17+
Raindrops tap on the windowpane
18+
A melody plays, soft and low
19+
The clink of cups, the murmur of dreams
20+
In this haven, I find my home
21+
[Chorus]
22+
Pushing the wooden door, the aroma spreads
23+
In a familiar corner, a stranger gazes back
24+
Warm lights flicker, memories awaken
25+
In this small cafe, I find my way"""
26+
output_format = "hex"
27+
28+
payload = {
29+
'model': '{{model}}',
30+
'prompt': promt,
31+
'lyrics': lyrics,
32+
'output_format': output_format
33+
}
34+
35+
headers = {
36+
'Content-Type': 'application/json',
37+
'Authorization': 'Bearer {{apiKey}}',
38+
}
39+
40+
try:
41+
response = requests.post(url, headers=headers, json=payload)
42+
data = response.json()
43+
44+
if response.ok:
45+
audio_hex = data['data']['audio']
46+
decoded_hex = bytes.fromhex(audio_hex)
47+
48+
with open('generated_audio.mp3', 'wb') as f:
49+
f.write(decoded_hex)
50+
51+
print("Audio file saved as generated_audio.mp3")
52+
else:
53+
print(f"Failed to generate music: {data}")
54+
except Exception as error:
55+
print(f"Error during API request: {error}")
56+
57+
if __name__ == '__main__':
58+
main()

0 commit comments

Comments
 (0)