すべてのプロダクト
Search
ドキュメントセンター

Alibaba Cloud Model Studio:音楽生成

最終更新日:Jun 13, 2026

Fun-Music は、中国語または英語の男性・女性ボーカルによるフルレングスの楽曲を生成します。クリエイティブなプロンプトまたはカスタム歌詞を提供すると、モデルが楽曲を構成して歌唱します。

重要

このモデルは現在、招待プレビュー段階です。使用前に、Models ページからアクセス申請を行ってください。このモデルサービスは中国 (北京) リージョンでのみ利用可能です。

主な特徴

  • プロンプトから歌詞を構成し、完成した楽曲を生成

  • カスタム歌詞から楽曲を生成

  • 男性および女性のボーカルスタイル

  • 中国語および英語の歌詞とプロンプトに対応

  • ストリーミング出力および非ストリーミング出力モード

  • MP3 および WAV のオーディオ出力フォーマット

サポートされるモデル

音楽生成モデル:

  • fun-music-preview

  • fun-music-v1

サポート言語:

  • 歌詞:中国語、英語

  • プロンプト:中国語、英語

クイックスタート

前提条件

  • API キー。詳細については、「API キーを取得する」をご参照ください。

  • 環境変数として設定された API キー(推奨):

    export DASHSCOPE_API_KEY="sk-xxx"
重要

lyrics および prompt のいずれか一方は必須です。両方指定された場合、lyrics のみが有効となり、prompt は無視されます。

プロンプトから音楽を生成

prompt パラメーターを渡して、希望する音楽スタイルやシーンを記述します。モデルが自動的に歌詞を構成し、楽曲を生成します。

curl

curl -X POST 'https://dashscope.aliyuncs.com/api/v1/services/audio/music/generation' \
-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 tempo, 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/music/generation"

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 tempo, 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/music/generation";

        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 tempo, 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());
        }
    }
}

歌詞から音楽を生成

カスタム歌詞を含む lyrics パラメーターを渡します。モデルがその歌詞に曲をつけ、歌唱します。

curl

curl -X POST 'https://dashscope.aliyuncs.com/api/v1/services/audio/music/generation' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "fun-music-v1",
    "input": {
        "lyrics": "[verse]\nMorning sunlight streams through the curtains,\nThe aroma of coffee fills the room.\nOpening a book left unfinished yesterday,\nTime quietly slips away like this.\n\n[chorus]\nTake it slow, no need to rush,\nLife should be this easygoing.\nToss all the 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/music/generation"

lyrics = """[verse]
Morning sunlight streams through the curtains,
The aroma of coffee fills the room.
Opening a book left unfinished yesterday,
Time quietly slips away like this.

[chorus]
Take it slow, no need to rush,
Life should be this easygoing.
Toss all the 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/music/generation";

        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 streams through the curtains,\\n"
            + "The aroma of coffee fills the room.\\n"
            + "Opening a book left unfinished yesterday,\\n"
            + "Time quietly slips away like this.\\n\\n"
            + "[chorus]\\nTake it slow, no need to rush,\\n"
            + "Life should be this easygoing.\\n"
            + "Toss all the 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());
        }
    }
}

ストリーミング

ストリーミングモードでは、生成中にオーディオデータを増分的に返します。リアルタイム再生にご利用ください。ストリーミングを有効にするには、リクエストに Server-Sent Events (SSE) ヘッダー X-DashScope-SSE: enable を追加します。

説明

ストリーミングモードと非ストリーミングモードでは文字数制限が異なります。

  • 非ストリーミングモード:lyrics は中国語で 5~350 文字、英語で 5~2,000 文字をサポートします。prompt は 1~2,000 文字をサポートします。

  • ストリーミングモード:lyrics は中国語で 300~350 文字、英語で 200~250 語をサポートします。prompt は中国語および英語で 5~1,000 文字(または語)をサポートします。

curl

curl -X POST 'https://dashscope.aliyuncs.com/api/v1/services/audio/music/generation' \
-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/music/generation"

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/music/generation";

        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);
                    }
                }
            }
        }
    }
}

歌詞作成ガイドライン

カスタム歌詞を提供する際は、以下のガイドラインに従うことで、より良い結果が得られます。

構造タグ

歌詞には以下の構造タグを含めることができます。

タグ

説明

[intro]

イントロ — 気分を設定

[verse]

ヴァース — 物語を伝える

[chorus]

コーラス — 感情のクライマックス

[bridge]

ブリッジ — 視点を変える

[outro]

アウトロ — フェードアウト

歌詞の例

[intro]
Piano keys fall gently, the evening breeze is cool.
That summer, heartbeats quietly grew warm.

[verse]
By the classroom window, sunlight slants across your face.
Borrowing half an eraser, fingertips spark like electric traces.
On the way home from school, bicycle bells chase the clouds.
You said the future is far away, but I wanted to walk to the very 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 early summer rain, sweet even when it soaks the dream.
We run toward tomorrow with laughter, hand in hand, never looking back.

[bridge]
Later, wind and rain tore apart the paper umbrella, silence replaced the answers.
But the song in my heart is still unfinished, waiting for one last "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 early summer rain, sweet even when it soaks the dream.
We run toward tomorrow with laughter, hand in hand, never looking back.

[outro]
The piano fades into the distance, starlight paves the long street.
The story is not over, the next page is still ablaze.

コンテンツ要件

  • 独創性:公開済みの楽曲の歌詞をコピーしたり、有名な楽曲の韻律や特徴的な表現を模倣したりしないでください。

  • コンテンツの安全性:歌詞には政治的、暴力的、ポルノ的、卑わい的、ホラー的、薬物関連の内容を含めないでください。健全かつ感情的に誠実な内容にしてください。

  • 言語:中国語および英語のみサポートされています。

ベストプラクティス

効果的なプロンプトの作成

気分、シーン、楽器の好みなどを詳細に記述してください。プロンプトが具体的であるほど、出力結果が意図に近くなります。

  • 推奨例:Melancholic piano, rainy night yearning

  • 非推奨例:Melancholic music(曖昧すぎる)

スタイル別のプロンプト例

スタイル

プロンプト例

フォーク

A warm, soothing folk song with acoustic guitar, telling a story of lazy afternoons at a café

中国古典風

A Chinese-style song with guzheng and bamboo flute, evoking ink-wash landscapes and tales of farewell

ロック

High-energy rock with distorted electric guitar and driving drums, singing about youthful rebellion and freedom

バラード

A slow, emotional ballad with piano accompaniment, quiet and deep, expressing longing and bittersweet memories

ヒップホップ

An upbeat hip-hop track with punchy 808 bass, full of street energy, rapping about city life

童謡

A cheerful children's song with xylophone and hand drum, simple catchy rhythm, teaching kids about nature

オーディオフォーマットの選択

  • mp3:ネットワーク転送およびストレージに最適です。デフォルトのフォーマットです。

  • wav:後処理および高品質再生に最適です。

API リファレンス

音楽生成 API リファレンス

よくある質問

歌詞とプロンプトの違いは何ですか?

lyrics パラメーターには、ユーザー自身の歌詞を指定します。モデルはこれらの歌詞に厳密に従って楽曲を構成・歌唱します。prompt パラメーターには、希望する音楽スタイルやシーンの自然言語による記述を指定します。モデルはこの記述に基づいて歌詞を作成し、楽曲を自動生成します。いずれか一方のパラメーターは必須です。両方指定された場合、lyrics のみが有効となります。

ストリーミングモードと非ストリーミングモードはどのように使い分けますか?

最終的なオーディオファイルのみが必要な場合は非ストリーミングモードをご利用ください。生成中にオーディオデータを増分的に受信したい場合(例:生成中のオーディオをリアルタイムで再生する場合)は、ストリーミングモードをご利用ください。

オーディオダウンロード URL の有効期間はどのくらいですか?

オーディオダウンロード URL の有効期限は 24 時間です。この期間内にファイルをダウンロードしてください。URL の有効期限が切れた場合は、再度 API を呼び出して新しい URL を生成してください。

ストリーミングモードと非ストリーミングモードのパラメーター制限は異なりますか?

lyrics および prompt の文字数制限は、モードによって異なります。非ストリーミングモードでは、lyrics は中国語で 5~350 文字、英語で 5~2,000 文字をサポートし、prompt は 1~2,000 文字をサポートします。ストリーミングモードでは、lyrics は中国語で 300~350 文字、英語で 200~250 語をサポートし、prompt は中国語および英語で 5~1,000 文字(または語)をサポートします。