Fun-Music は、音楽スタイルやシーンを記述したテキストプロンプト、またはカスタム歌詞から、中国語または英語の男性・女性ボーカル付きの完成された楽曲を生成します。
重要このモデルは現在、限定プレビュー提供中です。使用する前に、モデルギャラリーからアクセス申請を行ってください。このモデルは中国 (北京) リージョンでのみ利用可能です。
概要
Fun-Music はエンドツーエンドの音楽生成モデルです。自然言語による説明またはカスタム歌詞を入力すると、完成された楽曲を返します。
prompt:音楽スタイル、シーン、ムード、楽器のプリファレンスを記述します。モデルが自動的に歌詞を作成し、楽曲を生成します。lyrics:カスタム歌詞を提供します。モデルはその歌詞に基づいて楽曲を構成・演奏します。gender:男性または女性のボーカルを選択します(fun-music-v1 のみ対応)。- ストリーミング出力と非ストリーミング出力
- MP3 および WAV 形式のオーディオ出力
2 つのモデルの違い
Fun-Music には以下の違いを持つ 2 つのモデルが用意されています。
機能 | fun-music-v1 | fun-music-preview |
|---|---|---|
prompt | 必須( | 必須 |
lyrics |
| 任意。指定した場合、 |
ボーカルの性別(gender) | 対応 | 非対応 |
オーディオ出力フォーマット
format パラメーターを設定して出力フォーマットを指定します。
フォーマット | 特徴 | 利用シーン |
|---|---|---|
| 可逆圧縮なし(ロッシー圧縮)、ファイルサイズが小さい | ストリーミング、オンライン再生、ストレージ |
| 可逆圧縮あり(ロスレス形式)、ファイルサイズが大きい | ポストプロダクション、高品質再生 |
前提条件
- API キー。詳細については、「API キーの取得」をご参照ください。
- 環境変数として設定された API キー(推奨):
export DASHSCOPE_API_KEY="sk-xxx"
注記サンプルコード内の {WorkspaceId} は、実際のワークスペース ID に置き換えてください。詳細については、「ワークスペース管理」をご参照ください。
クイックスタート
以下の例では、代表的なユースケースを 3 つ紹介します。
プロンプトから楽曲を生成する
音楽スタイルとシーンの説明を含む prompt パラメーターを渡します。モデルが歌詞を作成し、楽曲を構成します。
curl -X POST 'https://{WorkspaceId}.cn-beijing.maas.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"
}
}'
import requests
import os
import json
api_key = os.getenv("DASHSCOPE_API_KEY")
url = "https://{WorkspaceId}.cn-beijing.maas.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, accompanied by acoustic guitar and harmonica, upbeat tempo, suitable as travel vlog background music",
"gender": "female"
}
}
)
result = response.json()
audio_url = result["output"]["audio"]["url"]
print(f"Music generated successfully! Download URL: {audio_url}")
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://{WorkspaceId}.cn-beijing.maas.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, accompanied by acoustic guitar and harmonica, upbeat tempo, suitable as travel vlog background music\","
+ "\"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 -X POST 'https://{WorkspaceId}.cn-beijing.maas.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"
}
}'
import requests
import os
import json
api_key = os.getenv("DASHSCOPE_API_KEY")
url = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/music/generation"
lyrics = """[verse]
Morning sunlight filters through the curtains,
The aroma of coffee fills the room.
Opening the book left unfinished yesterday,
Time quietly slips away.
[chorus]
Take it slow, no rush,
Life should be this easy.
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}")
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://{WorkspaceId}.cn-beijing.maas.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 filters through the curtains,\\n"
+ "The aroma of coffee fills the room.\\n"
+ "Opening the book left unfinished yesterday,\\n"
+ "Time quietly slips away.\\n\\n"
+ "[chorus]\\nTake it slow, no rush,\\n"
+ "Life should be this easy.\\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());
}
}
}
構成ガイド
プロンプト
prompt は、音楽制作の意図を記述するための主要なパラメーターです。モデルはこの説明に基づいて歌詞を作成し、楽曲を構成・生成します。
記述のヒント:より良い結果を得るには、ムード、シーン、楽器のプリファレンスを具体的に記述してください。
- 推奨例:
切ないピアノ、雨の夜の想い - 非推奨例:
切ない音楽(曖昧すぎる)
注記プロンプトには、楽器(「ピアノ伴奏」、「サックスソロ」、「箏と尺八」など)、テンポ(「アップテンポ」、「スロー」、「密なドラムビート」など)、感情的トーン(「温かみのある」、「切ない」、「激しい」、「リラックスした」など)を指定してください。モデルはこれらの記述を可能な限り忠実に再現します。プロンプトが具体的であるほど、より正確な結果が得られます。
スタイル | プロンプト例 |
|---|---|
Folk | アコースティックギターを使った温かみのあるヒーリング系フォークソングで、カフェでののんびりとした午後の物語を描きます。 |
Traditional Chinese | 古筝(グージェン)と竹笛を使った伝統的な中国風楽曲で、霧に包まれた風景や旅人同士の別れを表現します。 |
Rock | 歪んだエレキギターと密度の高いドラムビートが特徴の激しいロックで、若者の反骨心と自由を歌います。 |
Ballad | ピアノ伴奏によるゆったりとしたバラードで、静かで深みがあり、ほのかなメランコリーを帯びながら、切なさや思い出を表現します。 |
Rap | 鋭いビートと 808 ベースドラムを特徴とするヒップホップラップで、ストリートのエネルギーに満ちており、都市生活の物語を語ります。 |
Children's song | 木琴とハンドドラムを使った明るく楽しい童謡で、シンプルで耳に残るリズムを通じて、子どもたちに自然について教えます。 |
歌詞
lyrics パラメーターには、ユーザーの歌詞を入力します。モデルはその歌詞に忠実に楽曲を構成します。楽曲セクションの構成を制御するために、楽曲セクションタグを使用できます。
タグ | 説明 |
|---|---|
| イントロ。ムードを設定します。 |
| ヴァース。物語を伝えます。 |
| コーラス。感情のクライマックスです。 |
| ブリッジ。視点を切り替えます。 |
| アウトロ。徐々にフェードアウトします。 |
[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 profile.
Borrowing half an eraser, fingertips spark an electric line.
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 end.
[chorus]
Youth is an unopened letter, filled with brave promises.
Even if the world flickers bright and dark, with you I see the light.
Love is like the sweet rain of early summer, soaking dreams without fear of distance.
We run toward tomorrow with laughter, hand in hand, never looking back.
[bridge]
Later, wind and rain scattered the paper umbrella, silence replaced the answers.
But the song in my heart is unfinished, still waiting for "don't drift apart."
[chorus]
Youth is an unopened letter, filled with brave promises.
Even if the world flickers bright and dark, with you I see the light.
Love is like the sweet rain of early summer, soaking dreams without fear of distance.
We run toward tomorrow with laughter, hand in hand, never looking back.
[outro]
The piano fades, starlight paves the long street.
The story is unfinished, the next page is still passionate.
記述要件
- 独創性:既存の楽曲の歌詞、韻律、特徴的なフレーズをコピーまたは模倣しないでください。
- コンテンツの安全性:政治、暴力、ポルノ、下品さ、ホラー、薬物に関連するコンテンツを含めないでください。前向きで感情的に誠実な内容にしてください。
- 言語:中国語および英語の歌詞のみサポートされています。日本語、韓国語、その他の言語はサポートされていません。
ボーカルの性別(gender)
gender パラメーターでボーカルの性別を選択します。fun-music-v1 モデルでのみサポートされています。デフォルトは female です。
female:女性ボーカル(デフォルト)male:男性ボーカル
高度な機能
ストリーミング出力
ストリーミングモードでは、生成中にオーディオデータを逐次返すため、リアルタイム再生に最適です。fun-music-v1 および fun-music-preview の両方でこのモードがサポートされています。ストリーミング出力を有効にするには、リクエストヘッダーに X-DashScope-SSE: enable を追加します。
注記ストリーミングモードと非ストリーミングモードでは文字数制限が異なります。
- 非ストリーミングモード:
lyricsは中国語 5~350 文字または英語 5~2,000 文字を受け付けます。promptは 1~2,000 文字を受け付けます。 - ストリーミングモード:
lyricsは中国語 300~350 文字または英語 200~250 語を受け付けます。promptは中国語または英語で 5~1,000 文字を受け付けます。
curl -X POST 'https://{WorkspaceId}.cn-beijing.maas.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 workout scenes",
"gender": "male"
}
}'
import requests
import os
import json
import base64
api_key = os.getenv("DASHSCOPE_API_KEY")
url = "https://{WorkspaceId}.cn-beijing.maas.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 workout scenes",
"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}")
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://{WorkspaceId}.cn-beijing.maas.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 workout scenes\","
+ "\"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);
}
}
}
}
}
}
サポートされるモデルとリージョン
中国 (北京)
以下のモデルを呼び出すには、北京リージョンのAPI キーを使用します。
- fun-music-v1
- fun-music-preview
API リファレンス
よくある質問
楽器、テンポ、ムードを指定できますか?
はい。これらを直接 prompt に記述してください(例:「ピアノ伴奏、スローテンポ、切ない」)。モデルはこれらの記述を可能な限り忠実に再現します。プロンプトの記述に関する詳細なヒントについては、「プロンプト」をご参照ください。
どのモデルを選べばよいですか?
fun-music-v1 はボーカルの性別選択をサポートしており、より高品質なオーディオを生成します。fun-music-preview はカスタム歌詞およびプロンプトベースの生成をサポートしています。詳細な比較については、「2 つのモデルの違い」をご参照ください。
オーディオダウンロード URL の有効期間はどのくらいですか?
オーディオファイルのダウンロード URL は 24 時間有効です。この期間内にファイルをダウンロードしてください。URL の有効期限が切れたら、再度 API を呼び出して新しい URL を生成してください。
歌詞とプロンプトの違いは何ですか?
lyrics パラメーターにはユーザーの歌詞を入力し、モデルはその歌詞に基づいて楽曲を構成します。prompt パラメーターには音楽スタイルやシーンの自然言語による説明を入力し、モデルが自動的に歌詞を作成して楽曲を生成します。パラメーターの要件はモデルによって異なります。fun-music-v1 では、2 つのパラメーターのうち少なくとも 1 つが必要です。両方を指定した場合、lyrics が有効になります。fun-music-preview では、prompt が必須で、lyrics は任意であり、指定した場合は prompt よりも優先されます。
ストリーミングモードと非ストリーミングモードはどのように使い分けますか?
最終的なオーディオファイルのみが必要な場合は、非ストリーミングモードを使用します。API 呼び出しがシンプルです。生成中にオーディオデータを逐次受け取りたい場合(例:リアルタイム再生)は、ストリーミングモードを使用します。
ストリーミングモードと非ストリーミングモードのパラメーター制限の違いは何ですか?
lyrics および prompt の文字数制限は、2 つのモードで異なります。非ストリーミングモードでは、lyrics は中国語 5~350 文字または英語 5~2,000 文字を受け付け、prompt は 1~2,000 文字を受け付けます。ストリーミングモードでは、lyrics は中国語 300~350 文字または英語 200~250 語を受け付け、prompt は中国語または英語で 5~1,000 文字を受け付けます。