All Products
Search
Document Center

Alibaba Cloud Model Studio:Music generation

Last Updated:May 06, 2026

Bailing Music (Fun-Music) takes open-ended song creation prompts or custom lyrics and produces a complete vocal track sung in male or female voice, in Chinese or English.

Important

This model is currently in invitation-only preview. Apply for access through the Model Studio model gallery before use. The model is available only in the Chinese mainland deployment scope (Beijing region).

Key features

  • Automatically writes lyrics from a prompt and generates a complete song

  • Generates a song from custom lyrics

  • Supports male and female vocals

  • Accepts Chinese and English lyrics and prompts

  • Supports streaming and non-streaming output modes

  • Outputs audio in MP3 and WAV formats

Supported model

Music generation model: fun-music-v1

Supported languages:

  • Lyrics: Chinese, English

  • Prompts: Chinese, English

Quick start

Prerequisites

  • An API key. For details, see Get an API key.

  • The API key configured as an environment variable (recommended):

    export DASHSCOPE_API_KEY="sk-xxx"
Important

lyrics or prompt is required. If you pass both, only lyrics takes effect and prompt is ignored.

Generate music from a prompt

Pass the prompt parameter to describe the desired music style and scenario. The model automatically writes lyrics and generates a song.

curl

curl -X POST 'https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "fun-music-v1",
    "input": {
        "prompt": "Fresh summer folk song, acoustic guitar and harmonica accompaniment, upbeat rhythm, suitable as background music for travel vlogs",
        "gender": "female"
    }
}'

Python

import requests
import os
import json

api_key = os.getenv("DASHSCOPE_API_KEY")
url = "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer"

response = requests.post(url,
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    },
    json={
        "model": "fun-music-v1",
        "input": {
            "prompt": "Fresh summer folk song, acoustic guitar and harmonica accompaniment, upbeat rhythm, suitable as background music for travel vlogs",
            "gender": "female"
        }
    }
)

result = response.json()
audio_url = result["output"]["audio"]["url"]
print(f"Music generated successfully! Download URL: {audio_url}")

Java

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class FunMusicDemo {
    public static void main(String[] args) throws Exception {
        String apiKey = System.getenv("DASHSCOPE_API_KEY");
        String endpoint = "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer";

        HttpURLConnection conn = (HttpURLConnection) new URL(endpoint).openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Authorization", "Bearer " + apiKey);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setDoOutput(true);

        String jsonBody = "{\"model\":\"fun-music-v1\","
            + "\"input\":{\"prompt\":\"Fresh summer folk song, acoustic guitar and harmonica accompaniment, upbeat rhythm, suitable as background music for travel vlogs\","
            + "\"gender\":\"female\"}}";

        try (OutputStream os = conn.getOutputStream()) {
            os.write(jsonBody.getBytes("UTF-8"));
        }

        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(conn.getInputStream(), "UTF-8"))) {
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            System.out.println(sb.toString());
        }
    }
}

Generate music from lyrics

Pass the lyrics parameter with your custom lyrics. The model composes music and produces a vocal track based on your lyrics.

curl

curl -X POST 'https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "fun-music-v1",
    "input": {
        "lyrics": "[verse]\nMorning sunlight slips through the curtain,\nCoffee aroma fills up the room.\nOpen the book left unfinished yesterday,\nTime quietly drifts by this way.\n\n[chorus]\nTake it slow, there'\''s no hurry,\nLife should be this carefree.\nToss your worries into the wind,\nEmbrace every sunny day and rainy season.",
        "gender": "female"
    }
}'

Python

import requests
import os
import json

api_key = os.getenv("DASHSCOPE_API_KEY")
url = "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer"

lyrics = """[verse]
Morning sunlight slips through the curtain,
Coffee aroma fills up the room.
Open the book left unfinished yesterday,
Time quietly drifts by this way.

[chorus]
Take it slow, there's no hurry,
Life should be this carefree.
Toss your worries into the wind,
Embrace every sunny day and rainy season."""

response = requests.post(url,
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    },
    json={
        "model": "fun-music-v1",
        "input": {
            "lyrics": lyrics,
            "gender": "female"
        }
    }
)

result = response.json()
audio_url = result["output"]["audio"]["url"]
print(f"Music generated successfully! Download URL: {audio_url}")

Java

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class FunMusicLyricsDemo {
    public static void main(String[] args) throws Exception {
        String apiKey = System.getenv("DASHSCOPE_API_KEY");
        String endpoint = "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer";

        HttpURLConnection conn = (HttpURLConnection) new URL(endpoint).openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Authorization", "Bearer " + apiKey);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setDoOutput(true);

        String lyrics = "[verse]\\nMorning sunlight slips through the curtain,\\n"
            + "Coffee aroma fills up the room.\\n"
            + "Open the book left unfinished yesterday,\\n"
            + "Time quietly drifts by this way.\\n\\n"
            + "[chorus]\\nTake it slow, there's no hurry,\\n"
            + "Life should be this carefree.\\n"
            + "Toss your worries into the wind,\\n"
            + "Embrace every sunny day and rainy season.";

        String jsonBody = "{\"model\":\"fun-music-v1\","
            + "\"input\":{\"lyrics\":\"" + lyrics + "\","
            + "\"gender\":\"female\"}}";

        try (OutputStream os = conn.getOutputStream()) {
            os.write(jsonBody.getBytes("UTF-8"));
        }

        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(conn.getInputStream(), "UTF-8"))) {
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            System.out.println(sb.toString());
        }
    }
}

Streaming

Streaming mode returns audio data incrementally as it's generated. Use it for real-time playback. To enable streaming, add the X-DashScope-SSE: enable header to your request.

Note

Character limits differ between streaming and non-streaming modes:

  • Non-streaming: lyrics accepts 5-350 Chinese characters or 5-2,000 English characters; prompt accepts 1-2,000 characters.

  • Streaming: lyrics accepts 300-350 Chinese characters or 200-250 English words; prompt accepts 5-1,000 Chinese characters or English words.

curl

curl -X POST 'https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-DashScope-SSE: enable" \
-d '{
    "model": "fun-music-v1",
    "input": {
        "prompt": "High-energy electronic dance music, synthesizer effects, full of energy, suitable for fitness and workout scenarios",
        "gender": "male"
    }
}'

Python

import requests
import os
import json
import base64

api_key = os.getenv("DASHSCOPE_API_KEY")
url = "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer"

response = requests.post(url,
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
        "X-DashScope-SSE": "enable"
    },
    json={
        "model": "fun-music-v1",
        "input": {
            "prompt": "High-energy electronic dance music, synthesizer effects, full of energy, suitable for fitness and workout scenarios",
            "gender": "male"
        }
    },
    stream=True
)

output_file = "output.mp3"
with open(output_file, "wb") as f:
    for line in response.iter_lines():
        if not line:
            continue
        decoded = line.decode("utf-8")
        if decoded.startswith("data:"):
            data = json.loads(decoded[5:])
            finish_reason = data.get("output", {}).get("finish_reason")
            if finish_reason == "null":
                audio_data = data["output"]["audio"].get("data", "")
                if audio_data:
                    f.write(base64.b64decode(audio_data))
            elif finish_reason == "stop":
                print(f"Music generation complete! Saved to {output_file}")

Java

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;

public class FunMusicStreamDemo {
    public static void main(String[] args) throws Exception {
        String apiKey = System.getenv("DASHSCOPE_API_KEY");
        String endpoint = "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer";

        HttpURLConnection conn = (HttpURLConnection) new URL(endpoint).openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Authorization", "Bearer " + apiKey);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("X-DashScope-SSE", "enable");
        conn.setDoOutput(true);

        String jsonBody = "{\"model\":\"fun-music-v1\","
            + "\"input\":{\"prompt\":\"High-energy electronic dance music, synthesizer effects, full of energy, suitable for fitness and workout scenarios\","
            + "\"gender\":\"male\"}}";

        try (OutputStream os = conn.getOutputStream()) {
            os.write(jsonBody.getBytes("UTF-8"));
        }

        String outputFile = "output.mp3";
        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(conn.getInputStream(), "UTF-8"));
             FileOutputStream fos = new FileOutputStream(outputFile)) {
            String line;
            while ((line = reader.readLine()) != null) {
                if (line.startsWith("data:")) {
                    String data = line.substring(5);
                    if (data.contains("\"finish_reason\":\"null\"")) {
                        int start = data.indexOf("\"data\":\"") + 8;
                        int end = data.indexOf("\"", start);
                        if (start > 8 && end > start) {
                            byte[] chunk = Base64.getDecoder().decode(
                                data.substring(start, end));
                            fos.write(chunk);
                        }
                    } else if (data.contains("\"finish_reason\":\"stop\"")) {
                        System.out.println("Music generation complete! Saved to " + outputFile);
                    }
                }
            }
        }
    }
}

Lyrics writing guidelines

Fun-Music includes a built-in lyrics composer. To get better results with custom lyrics, follow these guidelines.

Structure tags

Include the following structural tags in your lyrics:

Tag

Description

[intro]

Intro, sets the atmosphere

[verse]

Verse, tells the story

[chorus]

Chorus, emotional climax

[bridge]

Bridge, shifts perspective

[outro]

Outro, fades out

Lyrics example

[intro]
Piano keys fall softly, the evening breeze is cool.
That summer, heartbeats quietly began to glow.

[verse]
By the classroom window, sunlight slants across your face.
Borrowing half an eraser, fingertips spark an electric trace.
On the walk home from school, bicycle bells chase the clouds.
You said the future is far away, but I wanted to walk to the end.

[chorus]
Youth is an unopened letter, filled with brave vows.
Even if the world flickers bright and dark, with you I see the light.
Love is like the sweet rain of early summer, drenching dreams without fear of distance.
We run laughing toward tomorrow, hand in hand, never looking back.

[bridge]
Later the storm broke the paper umbrella, silence replaced the answers.
But the song in my heart isn't over, still waiting for "don't drift apart."

[chorus]
Youth is an unopened letter, filled with brave vows.
Even if the world flickers bright and dark, with you I see the light.
Love is like the sweet rain of early summer, drenching dreams without fear of distance.
We run laughing toward tomorrow, hand in hand, never looking back.

[outro]
The piano fades, starlight paves the long street.
The story isn't over, the next page is still burning bright.

Writing requirements

  • Originality: Don't copy lyrics from published songs or imitate the rhyme schemes or signature phrases of well-known songs.

  • Content safety: Lyrics must not contain political, violent, pornographic, vulgar, horrific, or drug-related content. Keep the content positive and emotionally authentic.

  • Language: Only Chinese and English are supported. Japanese, Korean, and other languages aren't supported.

Best practices

Write effective prompts

Describing the mood, scene, and instrument preferences in detail produces more targeted results.

  • Recommended: Melancholic piano, rainy night yearning

  • Not recommended: Melancholic music (too vague)

Choose an audio format

  • mp3: Best for web delivery and storage. This is the default format.

  • wav: Best for post-processing and high-quality playback.

API reference

Music generation API reference

FAQ

What's the difference between lyrics and prompt?

The lyrics parameter takes your own lyrics. The model strictly follows the lyrics to compose and produce a vocal track. The prompt parameter takes a natural-language description of the desired music style and scenario. The model then writes lyrics and generates the corresponding music. Provide at least one of these parameters. If you pass both, only lyrics takes effect.

When should I use streaming vs. non-streaming?

Use non-streaming mode if you need only the final audio file. Use streaming mode to receive audio data incrementally, for example, to play audio in real time.

How long is the audio URL valid?

Audio download URLs expire after 24 hours. To get a new URL after expiration, call the API again.

How do character limits differ between streaming and non-streaming?

The character limits for lyrics and prompt differ between the two modes. Non-streaming: lyrics accepts 5-350 Chinese characters or 5-2,000 English characters; prompt accepts 1-2,000 characters. Streaming: lyrics accepts 300-350 Chinese characters or 200-250 English words; prompt accepts 5-1,000 Chinese characters or English words.