|
| 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