Qwen-Omni モデルは、マルチモーダル入力を受け付け、テキストまたは音声で応答を生成します。人間のような音声を生成し、複数の言語や方言での音声出力をサポートします。ユースケースには、コンテンツモデレーション、テキスト作成、視覚認識、音声ビデオインタラクションなどがあります。
サポートリージョン:シンガポール、北京。ご利用のリージョンの API キー を使用してください。
クイックスタート
前提条件
-
Qwen-Omni モデルは OpenAI 互換の呼び出しのみをサポートします。最新の SDK をインストールする必要があります。最小要件バージョンは、OpenAI Python SDK で 1.52.0、Node.js SDK で 4.68.0 です。
この例では、テキストプロンプトを Qwen-Omni API に送信し、テキストと音声の両方を含むストリーミング応答を返します。
import os
import base64
import soundfile as sf
import numpy as np
from openai import OpenAI
# 1. クライアントを初期化します
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # 環境変数が設定されていることを確認します
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
# 2. リクエストを送信します
try:
completion = client.chat.completions.create(
model="qwen3.5-omni-plus",
messages=[{"role": "user", "content": "Who are you?"}],
modalities=["text", "audio"], # テキストと音声の出力を指定します
audio={"voice": "Tina", "format": "wav"},
stream=True, # True に設定する必要があります
stream_options={"include_usage": True},
)
# 3. ストリーミング応答を処理し、音声をデコードします
print("Model response:")
audio_base64_string = ""
for chunk in completion:
# テキスト部分を処理します
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
# 音声部分を収集します
if chunk.choices and hasattr(chunk.choices[0].delta, "audio") and chunk.choices[0].delta.audio:
audio_base64_string += chunk.choices[0].delta.audio.get("data", "")
# 4. 音声ファイルを保存します
if audio_base64_string:
wav_bytes = base64.b64decode(audio_base64_string)
audio_np = np.frombuffer(wav_bytes, dtype=np.int16)
sf.write("audio_assistant.wav", audio_np, samplerate=24000)
print("\nAudio file saved to: audio_assistant.wav")
except Exception as e:
print(f"リクエストに失敗しました: {e}")// このコードを実行する前に:
// Windows/Mac/Linux の場合:
// 1. Node.js バージョン >= 14 がインストールされていることを確認します。
// 2. 次のコマンドを実行して、必要な依存関係をインストールします:
// npm install openai wav
import OpenAI from "openai";
import { createWriteStream } from 'node:fs';
import { Writer } from 'wav';
// Base64 文字列を変換し、標準の WAV 音声ファイルとして保存する関数を定義します
async function convertAudio(audioString, audioPath) {
try {
// Base64 文字列をバッファにデコードします
const wavBuffer = Buffer.from(audioString, 'base64');
// WAV ファイルの書き込みストリームを作成します
const writer = new Writer({
sampleRate: 24000, // サンプルレート
channels: 1, // モノラル
bitDepth: 16 // 16 ビット深度
});
// 出力ファイルストリームを作成し、パイプ接続を確立します
const outputStream = createWriteStream(audioPath);
writer.pipe(outputStream);
// PCM データを書き込み、書き込みを終了します
writer.write(wavBuffer);
writer.end();
// Promise を使用して、ファイルの書き込みが完了するのを待ちます
await new Promise((resolve, reject) => {
outputStream.on('finish', resolve);
outputStream.on('error', reject);
});
// 音声の整合性を確保するために、追加の待機時間を加えます
await new Promise(resolve => setTimeout(resolve, 800));
console.log(`\nAudio file saved to: ${audioPath}`);
} catch (error) {
console.error('Error during processing:', error);
}
}
// 1. クライアントを初期化します
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
// 2. リクエストを送信します
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus",
messages: [
{
"role": "user",
"content": "Who are you?"
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
let audioString = "";
console.log("Model response:")
// 3. ストリーミング応答を処理し、音声をデコードします
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
// テキストコンテンツを処理します
if (chunk.choices[0].delta.content) {
process.stdout.write(chunk.choices[0].delta.content);
}
// 音声コンテンツを処理します
if (chunk.choices[0].delta.audio) {
if (chunk.choices[0].delta.audio["data"]) {
audioString += chunk.choices[0].delta.audio["data"];
}
}
}
}
// 4. 音声ファイルを保存します
convertAudio(audioString, "audio_assistant.wav");# ======= 重要事項 =======
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。/chat/completions
# === 実行前にこのコメントを削除してください ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-omni-plus",
"messages": [
{
"role": "user",
"content": "Who are you?"
}
],
"stream":true,
"stream_options":{
"include_usage":true
},
"modalities":["text","audio"],
"audio":{"voice":"Tina","format":"wav"}
}'
モデルの選択
-
Qwen3.5-Omni シリーズ:長編動画分析、会議の要約、字幕生成、コンテンツモデレーション、音声ビデオインタラクションに最適です。
-
入力制限:最大 3 時間の音声または 1 時間の動画
-
音声コントロール:命令による音量、話速、感情の調整をサポート
-
視覚能力:Qwen3.5 のレベルに匹敵します。画像、音声、効果音、その他のマルチモーダル入力を理解します
-
複合マルチモーダル入力:1 つのリクエストで、テキストと画像、音声、動画の任意の組み合わせをサポートします
-
複合マルチモーダル入力は、Qwen3.5-Omni シリーズでのみサポートされています。 1 つのリクエストで、イメージ、オーディオ、テキスト、またはビデオ、イメージ、テキストなど、複数のモダリティを任意に組み合わせてデータを提供できます。
-
-
Qwen3-Omni-Flash シリーズ:短編動画分析やコストに敏感なシナリオに最適です。
-
入力制限:音声と動画の入力は最大 150 秒
-
思考モード:思考モードをサポートする唯一の Qwen-Omni シリーズモデル
-
入力モダリティ:テキストと他の単一モダリティ (画像、音声、または動画) の組み合わせのみをサポートします。
-
-
Qwen-Omni-Turbo シリーズ
このシリーズは更新されなくなり、機能も限定されています。Qwen3.5-Omni または Qwen3-Omni-Flash シリーズへの移行を推奨します。
|
シリーズ |
音声・動画の説明 |
ディープシンキング |
Web 検索 |
入力音声言語 |
出力音声言語 |
サポートされている音声 |
|
Qwen3.5-Omni 最新世代のオムニモーダルモデル |
強力 |
非サポート |
サポート |
113 |
36 |
55 |
|
Qwen3-Omni-Flash ハイブリッド思考モデル |
比較的弱い |
サポート |
非サポート |
19 |
19 |
17~49 バージョンによって異なります |
|
Qwen-Omni-Turbo 更新停止 |
なし |
非サポート |
非サポート |
中国語、英語 |
中国語、英語 |
4 |
モデル名、コンテキストウィンドウ、価格、スナップショットバージョンについては、Model Studio コンソールでご確認ください。レート制限については、「レート制限」をご参照ください。
モデルのパフォーマンス
音声・動画コンテンツ分析
この動画のタイムスタンプ付きの詳細な説明を生成してください。 |
00:00.000 – 00:02.500 雨に濡れた街の通りがワイドスクリーンのフレームいっぱいに広がる。長時間露光撮影により、濡れた舗道に赤と青の車のライトが筋状に伸びている。暗い膝丈のトレンチコートと明るいシャツにネクタイを締めた一人の男が、右側の歩道をカメラに向かって歩いてくる。雨粒が彼の肩と髪に付着している。一歩ごとに、湿ったコンクリートの上でくぐもった音がする。低く不吉な電子音のハミングが環境音の下に響き、絶え間なく降る雨が周囲でパチパチと音を立てる。彼の横のレンガの壁はカラフルなグラフィティで覆われ、遠くにはネオンサインが光っている。1 つはオレンジがかった赤の筆記体で「Nice」とはっきりと表示され、もう 1 つの縦長のサインは下部に「AT」の文字が見える。 ...... 00:12.300 – 00:14.533 カメラが下に傾く。懐中電灯の光の中で、黄ばんで古びた一枚の紙が浅い水たまりに横たわっており、その端は焦げ、角は丸まっている。インクで書かれた段落がその表面のほとんどを覆っているが、湿気と焦げ跡でテキストは判読不能である。男はひざまずき、手袋をはめた指をドキュメントに向かって伸ばす。彼の手が近づくにつれて、波紋が外側に広がる。サイレンの音がピークに達した後、わずかに遠ざかり始めるが、環境音のハミングは一定のままである。震える紙に触れる直前でシーンはフリーズし、クリップは終了する。 一部のタイムスタンプのみ表示されています。 |
多方言理解
異なる中国語の方言を話す歌手の声の特徴、感情状態、および完全な歌詞を記述してください。 |
この音声は、中国のさまざまな地域の歌手によるラップパフォーマンスを特集しており、豊かな方言の多様性を示しています。以下は、各歌手の声の特徴、感情状態、および対応する歌詞の詳細な説明です: 杭州方言 (呉語) 声の特徴: 男性歌手の声は柔らかく穏やかで、呉語特有の滑らかさと温かみがあります。彼のイントネーションは穏やかに上下し、リズムは軽快で速く、リラックスした語り口の効果を生み出しています。 感情状態: リラックスして快適で、日常生活に満ちています。彼は杭州のゆったりとしたライフスタイルと都市の変化を描写し、故郷への愛情と現代の発展についての考察を表現しています。全体的に、彼は居心地が良く、親しみやすいと感じています。 歌詞: > 杭州方言、よく聞いて!私たちの文化には、地元の児化音の発音が含まれています。 > 西湖のほとりに咲く花のように、文化調査は必要ありません。私たちが一番よく理解しています。 > あなたたちは誰も理解していません。「三不打門」、「哥儿」、「老儿」、「份儿」、「丫儿」...部外者がこれらをどうやって見分けることができるでしょうか? > 行こう!交通は速い。どこにでも地下鉄がある。確認してみよう。 > 東南アジアとタイを歓迎し、「十三太」のショーを見る。私たちの街を誇りに思い、性格は率直です。 > あなたは「橋渡り」の経験のためだけに来て、味が違うから帰らないのですか? 一部の結果のみ表示されています。 |
歌詞字幕生成
歌詞を書き起こし、各行にこのフォーマットでタイムスタンプを付けてください:[00:00:15,020 --> 00:00:28,085] : When you walk through a storm, hold your head up high.[00:00:28,085 --> 00:00:40,200] And don't be afraid of the dark. ...... |
[00:00:12,680 --> 00:00:16,960] 猫の糸が木々の月明かりをかすめて揺れる。 [00:00:18,400 --> 00:00:22,800] ラジエーターが 1998 年のチャートヒットをハミングする。 [00:00:24.160 → 00:00:28.080] 時間が霧のような熱波を分ける。 [00:00:28,920 --> 00:00:33,000] 画面からのネオンが私の鼻筋を照らす。 ...... [00:03:16,720 --> 00:03:21,680] 私たちは木の幹の最も柔らかい輪の中に寄り添う。 [00:03:22,400 --> 00:03:27,000] 呼吸が残りの暖かさを蜂蜜砂糖に変える。 [00:03:28,160 --> 00:03:33,200] ソファが雲のようなふわふわの形に沈む。 [00:03:34,000 --> 00:03:38,800] すべての毛穴が太陽の光を吸収する。 [00:04:09,000 --> 00:04:10,020] (終了) 一部の結果のみ表示されています。 |
音声・動画プログラミング
使用方法
ストリーミング出力
Qwen-Omni へのすべてのリクエストは stream=True をセットする必要があります。
モデル構成
コスト、速度、品質のバランスをとるために、パラメーター、プロンプト、メディアの長さを構成します。
音声・動画理解
|
ユースケース |
推奨動画長 |
推奨プロンプト |
推奨 max_pixels |
|
高速レビュー、低コスト |
≤60 分 |
50 ワード以内の簡単なプロンプト |
230,400 |
|
コンテンツ抽出 (長編動画のセグメンテーション) |
≤60 分 |
921,600~2,073,600 |
|
|
標準分析 (短編動画のタグ付け) |
≤4 分 |
以下の構造化プロンプトを使用してください |
921,600~2,073,600 |
|
詳細な分析 (複数の話者/複雑なシーン) |
≤2 分 |
2,073,600 |
最初に長編動画をセグメント化して、詳細な説明を取得できます。
音声理解
音声の長さとプロンプトの複雑さを制御することで、コストと品質のバランスをとることができます。
|
ユースケース |
推奨音声長 |
推奨プロンプト |
|
高速レビュー、低コスト |
≤60 分 |
50 ワード以内の簡単なプロンプト |
|
コンテンツ抽出 (長編音声のセグメント化) |
≤60 分 |
|
|
標準分析 (音声タグ付け) |
≤2 分 |
構造化プロンプトを使用 |
|
詳細な分析 (複数の話者/複雑なシーン) |
≤1 分 |
最初に長編音声をセグメント化して、詳細な説明を取得できます。
複合マルチモーダル入力
複合マルチモーダル入力は、Qwen3.5-Omni シリーズでのみサポートされています。画像、音声、テキストの任意の組み合わせ、または動画、画像、テキストなど、複数のモダリティのデータを同じリクエストで提供できます。
次の例は、マルチモーダル分析のために 1 つのリクエストで画像と音声を提供する方法を示しています。
OpenAI 互換
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3.5-omni-plus",
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg"
},
},
{
"type": "input_audio",
"input_audio": {
"data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20250211/tixcef/cherry.wav",
"format": "wav"
},
},
{"type": "text", "text": "Describe the image content and tell me what the audio is about."},
],
},
],
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus",
messages: [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": { "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg" },
},
{
"type": "input_audio",
"input_audio": {
"data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20250211/tixcef/cherry.wav",
"format": "wav"
},
},
{ "type": "text", "text": "Describe the image content and tell me what the audio is about." }
]
}
],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}# シンガポールリージョンと北京リージョンの API キーは異なります。 API キーの取得: https://www.alibabacloud.com/help/en/model-studio/get-api-key
# 次の URL はシンガポールリージョン用です。 呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。 URL はリージョンによって異なります。/chat/completions
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-omni-plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
}
},
{
"type": "input_audio",
"input_audio": {
"data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
"format": "wav"
}
},
{
"type": "text",
"text": "イメージの内容を説明し、音声が何についてのものか教えてください。"
}
]
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"modalities": ["text", "audio"],
"audio": {"voice": "Tina", "format": "wav"}
}'単一モダリティ入力
各リクエストには、テキストと他の 1 つのモダリティ (動画、音声、または画像) が含まれます。すべての Qwen-Omni モデルがこれをサポートしています。
動画とテキストの入力
動画を画像リストまたは動画ファイル (音声サポート付き) として提供します。
動画ファイル (動画内の音声をサポート)
-
ファイル数:
-
Qwen3.5-Omni シリーズ:パブリック URL を使用して最大 512 ファイル、Base64 エンコーディングを使用して最大 250 ファイル。
-
Qwen3-Omni-Flash および Qwen-Omni-Turbo シリーズ:1 ファイルのみ許可されます。
-
-
ファイルサイズ:
-
パブリック URL の使用:
-
Qwen3.5-Omni シリーズ:最大 2 GB
-
Qwen3-Omni-Flash:最大 256 MB
-
Qwen-Omni-Turbo:最大 150 MB
-
-
Base64 エンコーディングの使用:エンコードされた Base64 文字列は 10 MB 未満である必要があります
-
-
持続時間制限:
-
Qwen3.5-Omni シリーズ:1 時間
-
Qwen3-Omni-Flash:150 秒
-
Qwen-Omni-Turbo:40 秒
-
-
ファイル形式:MP4、AVI、MKV、MOV、FLV、WMV。
-
動画ファイル内の視覚情報と音声情報は別々に課金されます。
OpenAI 互換
import os
from openai import OpenAI
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3.5-omni-plus", # Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[
{
"role": "user",
"content": [
{
"type": "video_url",
"video_url": {
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241115/cqqkru/1.mp4"
},
},
{"type": "text", "text": "What is the video about?"},
],
},
],
# 出力モダリティを設定します。現在、["text","audio"] と ["text"] の 2 つのオプションがサポートされています
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
# stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンの API キーは異なります。 API キーの取得: https://www.alibabacloud.com/help/en/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。 呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。 URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus", // Qwen3-Omni-Flash の場合、ノンシンキングモードで実行します。
messages: [
{
"role": "user",
"content": [{
"type": "video_url",
"video_url": { "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241115/cqqkru/1.mp4" },
},
{ "type": "text", "text": "What is the video about?" }]
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}# ======= 重要事項 =======
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。/chat/completions
# === 実行前にこのコメントを削除してください ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-omni-plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "video_url",
"video_url": {
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241115/cqqkru/1.mp4"
}
},
{
"type": "text",
"text": "What is the video about"
}
]
}
],
"stream":true,
"stream_options": {
"include_usage": true
},
"modalities":["text","audio"],
"audio":{"voice":"Tina","format":"wav"}
}'
画像リスト形式
画像数
-
Qwen3.5-Omni シリーズ:最小 2 枚、最大 2048 枚
-
Qwen3-Omni-Flash:最小 2 枚、最大 128 枚
-
Qwen-Omni-Turbo:最小 4 枚、最大 80 枚
OpenAI 互換
import os
from openai import OpenAI
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3.5-omni-plus", # Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[
{
"role": "user",
"content": [
{
"type": "video",
"video": [
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/xzsgiz/football1.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/tdescd/football2.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/zefdja/football3.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/aedbqh/football4.jpg",
],
},
{"type": "text", "text": "Describe the process shown in this video"},
],
}
],
# 出力モダリティを設定します。現在、["text","audio"] と ["text"] の 2 つのオプションがサポートされています
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
# stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンの API キーは異なります。 API キーの取得: https://www.alibabacloud.com/help/en/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。 呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。 URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus", // Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages: [{
role: "user",
content: [
{
type: "video",
video: [
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/xzsgiz/football1.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/tdescd/football2.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/zefdja/football3.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241108/aedbqh/football4.jpg"
]
},
{
type: "text",
text: "このビデオに映っているプロセスを説明してください"
}
]
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}# ======= 重要事項 =======
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。/chat/completions
# === 実行前にこのコメントを削除してください ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-omni-plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "video",
"video": [
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/xzsgiz/football1.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/tdescd/football2.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/zefdja/football3.jpg",
"https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241108/aedbqh/football4.jpg"
]
},
{
"type": "text",
"text": "Describe the process shown in this video"
}
]
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"modalities": ["text", "audio"],
"audio": {
"voice": "Tina",
"format": "wav"
}
}'
音声とテキストの入力
-
ファイル数:
-
Qwen3.5-Omni シリーズ:パブリック URL を使用して最大 2048 ファイル、Base64 エンコーディングを使用して最大 250 ファイル。
-
Qwen3-Omni-Flash および Qwen-Omni-Turbo シリーズ:1 ファイルのみ許可されます。
-
-
ファイルサイズ:
-
パブリック URL の使用:
-
Qwen3.5-Omni シリーズ:最大 2 GB
-
Qwen3-Omni-Flash:最大 100 MB
-
Qwen-Omni-Turbo:最大 10 MB
-
-
Base64 エンコーディングの使用:エンコードされた Base64 文字列は 10 MB 未満である必要があります
-
-
持続時間制限:
-
Qwen3.5-Omni シリーズ:最大 3 時間
-
Qwen3-Omni-Flash:最大 20 分
-
Qwen-Omni-Turbo:最大 3 分
-
-
ファイル形式:AMR、WAV、3GP、3GPP、AAC、MP3。
この例では、パブリック音声 URL を使用します。ローカルファイルを使用するには、「Base64 エンコーディングでローカルファイルを送信」をご参照ください。呼び出しではストリーミング出力のみがサポートされています。
OpenAI 互換
import os
from openai import OpenAI
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3.5-omni-plus",# Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20250211/tixcef/cherry.wav",
"format": "wav",
},
},
{"type": "text", "text": "What is this audio about"},
],
},
],
# 出力モダリティを設定します。現在、["text","audio"] と ["text"] の 2 つのオプションがサポートされています
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
# stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus", // Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages: [
{
"role": "user",
"content": [{
"type": "input_audio",
"input_audio": { "data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20250211/tixcef/cherry.wav", "format": "wav" },
},
{ "type": "text", "text": "What is this audio about" }]
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}# ======= 重要な注意点 =======
# シンガポールリージョンと北京リージョンの API キーは異なります。API キーの取得: https://www.alibabacloud.com/help/en/model-studio/get-api-key
# 以下の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。/chat/completions
# === 実行前にこのコメントを削除してください ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-omni-plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250211/tixcef/cherry.wav",
"format": "wav"
}
},
{
"type": "text",
"text": "What is this audio about"
}
]
}
],
"stream":true,
"stream_options":{
"include_usage":true
},
"modalities":["text","audio"],
"audio":{"voice":"Tina","format":"wav"}
}'
画像とテキストの入力
Qwen-Omni モデルは、リクエストごとに複数の画像をサポートします。画像の要件:
-
画像数:
-
パブリック URL の使用:最大 2048 枚
-
Base64 エンコーディングの使用:最大 250 枚
-
-
画像サイズ:
-
パブリック URL の使用:
-
Qwen3.5-Omni シリーズ:各画像ファイルは 20 MB を超えてはなりません
-
Qwen3-Omni-Flash および Qwen-Omni-Turbo シリーズ:各画像ファイルは 10 MB を超えてはなりません
-
-
Base64 エンコーディングの使用:エンコードされた Base64 文字列は 10 MB 未満である必要があります。
-
-
幅と高さの両方が 10 ピクセルを超える必要があります。縦横比は 200:1 または 1:200 を超えてはなりません。
-
サポートされている画像タイプ:詳細については、「画像と動画の理解」をご参照ください。
この例では、パブリック画像 URL を使用します。ローカルファイルを使用するには、「Base64 エンコードされたローカルファイルの入力」をご参照ください。ストリーミング出力が必要です。
OpenAI 互換
import os
from openai import OpenAI
client = OpenAI(
# シンガポールリージョンと北京リージョンの API キーは異なります。API キーの取得: https://www.alibabacloud.com/help/en/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出す際、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンごとに異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3.5-omni-plus", # Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"
},
},
{"type": "text", "text": "What scene is depicted in the image?"},
],
},
],
# 出力モダリティを設定します。現在、["text","audio"] と ["text"] の 2 つのオプションがサポートされています。
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
# stream は True に設定する必要があります。設定しない場合、エラーが発生します。
stream=True,
stream_options={
"include_usage": True
}
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus", // Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages: [
{
"role": "user",
"content": [{
"type": "image_url",
"image_url": { "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg" },
},
{ "type": "text", "text": "What scene is depicted in the image?" }]
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}# ======= 重要事項 =======
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。/chat/completions
# === 実行前にこのコメントを削除してください ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-omni-plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/20241022/emyrja/dog_and_girl.jpeg"
}
},
{
"type": "text",
"text": "What scene is depicted in the image?"
}
]
}
],
"stream":true,
"stream_options":{
"include_usage":true
},
"modalities":["text","audio"],
"audio":{"voice":"Tina","format":"wav"}
}'
Web 検索
Qwen3.5-Omni シリーズは、Web 検索をサポートしてリアルタイム情報を取得し、推論を実行します。
-
ウェブ検索は Qwen3.5-Omni シリーズでのみサポートされています。
search_strategyパラメーターにはagentのみを指定できます。 -
課金については、課金の
agentポリシーをご参照ください。
Web 検索を有効にするには、enable_search と search_strategy を agent に設定します:
OpenAI 互換
# 前提条件:
# pip install openai
import os
from openai import OpenAI
# クライアントを初期化します
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
# リクエストを送信します (Web 検索を有効)
try:
completion = client.chat.completions.create(
model="qwen3.5-omni-plus",
messages=[{
"role": "user",
"content": "What is today's date and day of the week, and what important holidays are there today?"
}],
stream=True,
stream_options={"include_usage": True},
# Web 検索を有効にします
extra_body={
"enable_search": True
}
)
print("モデルの応答 (リアルタイム情報あり):")
for chunk in completion:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
print()
except Exception as e:
print(f"リクエストに失敗しました:{e}")
// 前提条件:
// npm install openai
import OpenAI from "openai";
// クライアントを初期化します
const openai = new OpenAI({
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
});
// リクエストを送信します (Web 検索を有効)
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus",
messages: [{
"role": "user",
"content": "What is today's date and day of the week, and what important holidays are there today?"
}],
stream: true,
stream_options: {
include_usage: true
},
// Web 検索を有効にします
extra_body: {
enable_search: true
}
});
console.log("モデルの応答 (リアルタイム情報あり):");
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
if (chunk.choices[0].delta.content) {
process.stdout.write(chunk.choices[0].delta.content);
}
}
}
console.log();
# ======= 重要 =======
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。/chat/completions
# === 実行前にこのコメントを削除してください ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-omni-plus",
"messages": [
{
"role": "user",
"content": "What is today's date and day of the week, and what important holidays are there today?"
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"enable_search": true
}'
思考モードの有効化/無効化
Qwen-Omni シリーズでは、Qwen3-Omni-Flash モデルのみがハイブリッド思考モデルです。enable_thinking パラメーターを使用して、思考モードを有効化または無効化できます:
-
true -
false(デフォルト)
思考モードでは、音声出力はサポートされていません。
OpenAI 互換
import os
from openai import OpenAI
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3-omni-flash",
messages=[{"role": "user", "content": "Who are you?"}],
# 思考モードを有効または無効にします。思考モードでは音声出力はサポートされていません。Qwen-Omni-Turbo は enable_thinking をサポートしていません。
extra_body={'enable_thinking': True},
# 出力モダリティを設定します。ノンシンキングモードでは ["text","audio"] と ["text"] の 2 つのオプションがサポートされています。思考モードでは ["text"] のみがサポートされています。
modalities=["text"],
# 音声を設定します。audio パラメーターは思考モードではサポートされていません。
# audio={"voice": "Tina", "format": "wav"},
# stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const completion = await openai.chat.completions.create({
model: "qwen3-omni-flash",
messages: [
{ role: "user", content: "Who are you?" }
],
// stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream: true,
stream_options: {
include_usage: true
},
// 思考モードを有効または無効にします。思考モードでは音声出力はサポートされていません。Qwen-Omni-Turbo は enable_thinking をサポートしていません。
extra_body:{'enable_thinking': true},
// 出力モダリティを設定します。ノンシンキングモードでは ["text","audio"] と ["text"] の 2 つのオプションがサポートされています。思考モードでは ["text"] のみがサポートされています。
modalities: ["text"],
// 音声を設定します。audio パラメーターは思考モードではサポートされていません。
//audio: { voice: "Tina", format: "wav" }
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}# ======= 重要事項 =======
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。/chat/completions
# === 実行前にこのコメントを削除してください ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-omni-flash",
"messages": [
{
"role": "user",
"content": "Who are you?"
}
],
"stream":true,
"stream_options":{
"include_usage":true
},
"modalities":["text"],
"enable_thinking": true
}'
マルチターン対話
Qwen-Omni モデルをマルチターン対話で使用する場合、次の点にご注意ください:
-
アシスタントメッセージ
messages 配列のアシスタントメッセージには、テキストデータのみを含めることができます。
-
ユーザーメッセージ
ユーザーメッセージには、テキストと他の 1 つのモダリティを含めることができます。マルチターン対話では、異なるユーザーメッセージで異なるモダリティを入力できます。
OpenAI 互換
import os
from openai import OpenAI
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3.5-omni-plus", # Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3",
"format": "mp3",
},
},
{"type": "text", "text": "What is this audio about"},
],
},
{
"role": "assistant",
"content": [{"type": "text", "text": "This audio says: Welcome to Alibaba Cloud"}],
},
{
"role": "user",
"content": [{"type": "text", "text": "Tell me about this company."}],
},
],
# 出力モダリティを設定します。現在、["text","audio"] と ["text"] の 2 つのオプションがサポートされています
modalities=["text"],
# stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus", // Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages: [
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3",
"format": "mp3",
},
},
{ "type": "text", "text": "What is this audio about" },
],
},
{
"role": "assistant",
"content": [{ "type": "text", "text": "This audio says: Welcome to Alibaba Cloud" }],
},
{
"role": "user",
"content": [{ "type": "text", "text": "Tell me about this company." }]
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text"]
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}# ======= 重要事項 =======
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。/chat/completions
# === 実行前にこのコメントを削除してください ===
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-omni-plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"
}
},
{
"type": "text",
"text": "What is this audio about"
}
]
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "This audio says: Welcome to Alibaba Cloud"
}
]
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "Tell me about this company."
}
]
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"modalities": ["text"]
}'Base64 エンコードされた出力音声データの解析
Qwen-Omni モデルは、音声をストリーミング Base64 エンコードデータとして出力します。生成中に、文字列変数を維持し、返された各チャンクからの Base64 エンコードデータを追加します。生成が完了したら、完全な文字列を Base64 デコードして音声ファイルを取得します。または、各チャンクをリアルタイムでデコードして再生することもできます。
# pyaudio のインストール手順:
# APPLE Mac OS X
# brew install portaudio
# pip install pyaudio
# Debian/Ubuntu
# sudo apt-get install python-pyaudio python3-pyaudio
# or
# pip install pyaudio
# CentOS
# sudo yum install -y portaudio portaudio-devel && pip install pyaudio
# Microsoft Windows
# python -m pip install pyaudio
import os
from openai import OpenAI
import base64
import numpy as np
import soundfile as sf
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3.5-omni-plus", # Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[{"role": "user", "content": "Who are you?"}],
# 出力モダリティを設定します。現在、["text","audio"] と ["text"] の 2 つのオプションがサポートされています
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
# stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream=True,
stream_options={"include_usage": True},
)
# 方法 1:生成完了後にデコード
audio_string = ""
for chunk in completion:
if chunk.choices:
if hasattr(chunk.choices[0].delta, "audio"):
try:
audio_string += chunk.choices[0].delta.audio["data"]
except Exception as e:
print(chunk.choices[0].delta.content)
else:
print(chunk.usage)
wav_bytes = base64.b64decode(audio_string)
audio_np = np.frombuffer(wav_bytes, dtype=np.int16)
sf.write("audio_assistant_py.wav", audio_np, samplerate=24000)
# 方法 2:生成中にデコード (方法 2 を使用するには、方法 1 のコードをコメントアウトします)
# # PyAudio を初期化します
# import pyaudio
# import time
# p = pyaudio.PyAudio()
# # 音声ストリームを作成します
# stream = p.open(format=pyaudio.paInt16,
# channels=1,
# rate=24000,
# output=True)
# for chunk in completion:
# if chunk.choices:
# if hasattr(chunk.choices[0].delta, "audio"):
# try:
# audio_string = chunk.choices[0].delta.audio["data"]
# wav_bytes = base64.b64decode(audio_string)
# audio_np = np.frombuffer(wav_bytes, dtype=np.int16)
# # 音声データを直接再生します
# stream.write(audio_np.tobytes())
# except Exception as e:
# print(chunk.choices[0].delta.content)
# time.sleep(0.8)
# # リソースをクリーンアップします
# stream.stop_stream()
# stream.close()
# p.terminate()// 実行前:
// Windows/Mac/Linux の場合:
// 1. Node.js バージョン >= 14 がインストールされていることを確認します。
// 2. 次のコマンドを実行して、必要な依存関係をインストールします:
// npm install openai wav
//
// リアルタイム再生機能 (方法 2) を使用するには、以下も必要です:
// Windows:
// npm install speaker
// Mac:
// brew install portaudio
// npm install speaker
// Linux (Ubuntu/Debian):
// sudo apt-get install libasound2-dev
// npm install speaker
import OpenAI from "openai";
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus", // Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages: [
{
"role": "user",
"content": "Who are you?"
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
// 方法 1:生成完了後にデコード
// インストールが必要です: npm install wav
import { createWriteStream } from 'node:fs'; // node:fs は Node.js の組み込みモジュールであり、インストールは不要です
import { Writer } from 'wav';
async function convertAudio(audioString, audioPath) {
try {
// Base64 文字列をバッファにデコードします
const wavBuffer = Buffer.from(audioString, 'base64');
// WAV ファイルの書き込みストリームを作成します
const writer = new Writer({
sampleRate: 24000, // サンプルレート
channels: 1, // モノラル
bitDepth: 16 // 16 ビット深度
});
// 出力ファイルストリームを作成し、パイプ接続を確立します
const outputStream = createWriteStream(audioPath);
writer.pipe(outputStream);
// PCM データを書き込み、書き込みを終了します
writer.write(wavBuffer);
writer.end();
// Promise を使用して、ファイルの書き込みが完了するのを待ちます
await new Promise((resolve, reject) => {
outputStream.on('finish', resolve);
outputStream.on('error', reject);
});
// 音声の整合性を確保するために、追加の待機時間を加えます
await new Promise(resolve => setTimeout(resolve, 800));
console.log(`Audio file successfully saved as ${audioPath}`);
} catch (error) {
console.error('An error occurred during processing:', error);
}
}
let audioString = "";
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
if (chunk.choices[0].delta.audio) {
if (chunk.choices[0].delta.audio["data"]) {
audioString += chunk.choices[0].delta.audio["data"];
}
}
} else {
console.log(chunk.usage);
}
}
// 変換を実行します
convertAudio(audioString, "audio_assistant_mjs.wav");
// 方法 2:リアルタイムで生成して再生します
// 上記のシステムの手順に従って、必要なコンポーネントをインストールします。
// import Speaker from 'speaker'; // 音声再生ライブラリをインポートします
// // スピーカーインスタンスを作成します (構成は WAV ファイルのパラメーターと一致します)
// const speaker = new Speaker({
// sampleRate: 24000, // サンプルレート
// channels: 1, // サウンドチャンネル数
// bitDepth: 16, // ビット深度
// signed: true // 符号付き PCM
// });
// for await (const chunk of completion) {
// if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
// if (chunk.choices[0].delta.audio) {
// if (chunk.choices[0].delta.audio["data"]) {
// const pcmBuffer = Buffer.from(chunk.choices[0].delta.audio.data, 'base64');
// // 再生のためにスピーカーに直接書き込みます
// speaker.write(pcmBuffer);
// }
// }
// } else {
// console.log(chunk.usage);
// }
// }
// speaker.on('finish', () => console.log('Playback complete'));
// speaker.end(); // API ストリームの実際の終了に基づいて呼び出しますBase64 エンコードされたローカルファイルの入力
Base64 エンコーディングを使用してファイルを送信する場合、エンコードされた Base64 文字列は 10 MB 未満である必要があります。
画像
この例では、ローカルに保存されたファイル eagle.png を使用します。
import os
from openai import OpenAI
import base64
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
# Base64 エンコード形式
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
base64_image = encode_image("eagle.png")
completion = client.chat.completions.create(
model="qwen3.5-omni-plus", # Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {"url": f"data:image/png;base64,{base64_image}"},
},
{"type": "text", "text": "What scene is depicted in the image?"},
],
},
],
# 出力モダリティを設定します。現在、["text","audio"] と ["text"] の 2 つのオプションがサポートされています
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
# stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
import { readFileSync } from 'fs';
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const encodeImage = (imagePath) => {
const imageFile = readFileSync(imagePath);
return imageFile.toString('base64');
};
const base64Image = encodeImage("eagle.png")
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus",// Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages: [
{
"role": "user",
"content": [{
"type": "image_url",
"image_url": { "url": `data:image/png;base64,${base64Image}` },
},
{ "type": "text", "text": "What scene is depicted in the image?" }]
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}音声
この例では、ローカルに保存されたファイル welcome.mp3 を使用します。
import os
from openai import OpenAI
import base64
import numpy as np
import soundfile as sf
import requests
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
def encode_audio(audio_path):
with open(audio_path, "rb") as audio_file:
return base64.b64encode(audio_file.read()).decode("utf-8")
base64_audio = encode_audio("welcome.mp3")
completion = client.chat.completions.create(
model="qwen3.5-omni-plus", # Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[
{
"role": "user",
"content": [
{
"type": "input_audio",
"input_audio": {
"data": f"data:;base64,{base64_audio}",
"format": "mp3",
},
},
{"type": "text", "text": "What is this audio about"},
],
},
],
# 出力モダリティを設定します。現在、["text","audio"] と ["text"] の 2 つのオプションがサポートされています
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
# stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
import { readFileSync } from 'fs';
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const encodeAudio = (audioPath) => {
const audioFile = readFileSync(audioPath);
return audioFile.toString('base64');
};
const base64Audio = encodeAudio("welcome.mp3")
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus", // Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages: [
{
"role": "user",
"content": [{
"type": "input_audio",
"input_audio": { "data": `data:;base64,${base64Audio}`, "format": "mp3" },
},
{ "type": "text", "text": "What is this audio about" }]
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}動画
動画ファイル
この例では、ローカルに保存されたファイル spring_mountain.mp4 を使用します。
import os
from openai import OpenAI
import base64
import numpy as np
import soundfile as sf
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
# Base64 エンコード形式
def encode_video(video_path):
with open(video_path, "rb") as video_file:
return base64.b64encode(video_file.read()).decode("utf-8")
base64_video = encode_video("spring_mountain.mp4")
completion = client.chat.completions.create(
model="qwen3.5-omni-plus", # Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[
{
"role": "user",
"content": [
{
"type": "video_url",
"video_url": {"url": f"data:;base64,{base64_video}"},
},
{"type": "text", "text": "What is she singing?"},
],
},
],
# 出力モダリティを設定します。現在、["text","audio"] と ["text"] の 2 つのオプションがサポートされています
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
# stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
import { readFileSync } from 'fs';
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const encodeVideo = (videoPath) => {
const videoFile = readFileSync(videoPath);
return videoFile.toString('base64');
};
const base64Video = encodeVideo("spring_mountain.mp4")
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus", // Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages: [
{
"role": "user",
"content": [{
"type": "video_url",
"video_url": { "url": `data:;base64,${base64Video}` },
},
{ "type": "text", "text": "What is she singing?" }]
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}画像リスト
たとえば、ローカルに保存されたファイル football1.jpg、football2.jpg、football3.jpg、football4.jpg を考えます。
import os
from openai import OpenAI
import base64
import numpy as np
import soundfile as sf
client = OpenAI(
# シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
)
# Base64 エンコード形式
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
base64_image_1 = encode_image("football1.jpg")
base64_image_2 = encode_image("football2.jpg")
base64_image_3 = encode_image("football3.jpg")
base64_image_4 = encode_image("football4.jpg")
completion = client.chat.completions.create(
model="qwen3.5-omni-plus", # Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[
{
"role": "user",
"content": [
{
"type": "video",
"video": [
f"data:image/jpeg;base64,{base64_image_1}",
f"data:image/jpeg;base64,{base64_image_2}",
f"data:image/jpeg;base64,{base64_image_3}",
f"data:image/jpeg;base64,{base64_image_4}",
],
},
{"type": "text", "text": "Describe the process shown in this video"},
],
}
],
# 出力モダリティを設定します。現在、["text","audio"] と ["text"] の 2 つのオプションがサポートされています
modalities=["text", "audio"],
audio={"voice": "Tina", "format": "wav"},
# stream は True に設定する必要があります。そうしないと、エラーが発生します。
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
if chunk.choices:
print(chunk.choices[0].delta)
else:
print(chunk.usage)import OpenAI from "openai";
import { readFileSync } from 'fs';
const openai = new OpenAI(
{
// シンガポールリージョンと北京リージョンでは API キーが異なります。API キーの取得:https://www.alibabacloud.com/help/model-studio/get-api-key
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。呼び出し時に、WorkspaceId を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
}
);
const encodeImage = (imagePath) => {
const imageFile = readFileSync(imagePath);
return imageFile.toString('base64');
};
const base64Image1 = encodeImage("football1.jpg")
const base64Image2 = encodeImage("football2.jpg")
const base64Image3 = encodeImage("football3.jpg")
const base64Image4 = encodeImage("football4.jpg")
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus", // Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages: [{
role: "user",
content: [
{
type: "video",
video: [
`data:image/jpeg;base64,${base64Image1}`,
`data:image/jpeg;base64,${base64Image2}`,
`data:image/jpeg;base64,${base64Image3}`,
`data:image/jpeg;base64,${base64Image4}`
]
},
{
type: "text",
text: "Describe the process shown in this video"
}
]
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
for await (const chunk of completion) {
if (Array.isArray(chunk.choices) && chunk.choices.length > 0) {
console.log(chunk.choices[0].delta);
} else {
console.log(chunk.usage);
}
}
API リファレンス
入力および出力パラメーターについては、「OpenAI 互換チャット」をご参照ください。
課金とレート制限
課金ルール
Qwen-Omni は、モダリティ (音声、画像、動画) 全体で消費されたトークンに基づいて課金されます。課金の詳細はコンソールでご確認ください。
無料クォータ
無料クォータの申請、クエリ、または使用については、「新規ユーザー向けの無料クォータ」をご参照ください。
レート制限
レート制限ルールとよくある質問については、「レート制限」をご参照ください。
エラーコード
モデルの呼び出しが失敗し、エラーメッセージが返された場合は、「エラーコード」で解決策をご参照ください。
音声リスト
Qwen-Omni モデルの音声リストについては、「音声リスト」をご参照ください。