Qwen-Omni モデルは、テキストに加えて画像・音声・動画のいずれか 1 つの追加モダリティを入力として受け付け、テキストまたは音声で応答を生成します。人間のような自然な音声を提供し、多言語および方言ベースの音声出力をサポートします。コンテンツモデレーション、テキスト作成、視覚認識、音声・動画インタラクションアシスタントなど、さまざまな用途にご利用いただけます。
サポート対象リージョン: シンガポール、中国 (北京)。ご利用のリージョンに対応する API キー を使用してください。
クイックスタート
前提条件
すでに API キーの設定 および 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://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
# 2. リクエストの送信
try:
completion = client.chat.completions.create(
model="qwen3.5-omni-plus",
messages=[{"role": "user", "content": "あなたは誰ですか?"}],
modalities=["text", "audio"], # テキストおよび音声出力を指定
audio={"voice": "Tina", "format": "wav"},
stream=True, # 必ず True に設定してください
stream_options={"include_usage": True},
)
# 3. ストリーミング応答の処理および音声のデコード
print("モデル応答:")
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("\n音声ファイルを次の場所に保存しました:audio_assistant.wav")
except Exception as e:
print(f"リクエストに失敗しました:{e}")// 実行前に:
// 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 文字列を Buffer にデコード
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();
// ファイルの書き込み完了を待機
await new Promise((resolve, reject) => {
outputStream.on('finish', resolve);
outputStream.on('error', reject);
});
// 音声の整合性を確保するために追加の待機時間を設定
await new Promise(resolve => setTimeout(resolve, 800));
console.log(`\n音声ファイルを次の場所に保存しました:${audioPath}`);
} catch (error) {
console.error('音声処理中にエラーが発生しました:', error);
}
}
// 1. クライアントの初期化
const openai = new OpenAI(
{
// 環境変数が設定されていない場合は、次の行を Alibaba Cloud Model Studio の API キーに置き換えてください:apiKey: "sk-xxx"
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
}
);
// 2. リクエストの送信
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus",
messages: [
{
"role": "user",
"content": "あなたは誰ですか?"
}],
stream: true,
stream_options: {
include_usage: true
},
modalities: ["text", "audio"],
audio: { voice: "Tina", format: "wav" }
});
let audioString = "";
console.log("モデル応答:")
// 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/zh/model-studio/get-api-key をご参照ください。
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions に置き換えてください。
# === 実行前にこのコメントを削除してください ===
curl -X POST https://dashscope-intl.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": "あなたは誰ですか?"
}
],
"stream":true,
"stream_options":{
"include_usage":true
},
"modalities":["text","audio"],
"audio":{"voice":"Tina","format":"wav"}
}'モデル選択
Qwen3.5-Omni シリーズ:長時間動画分析、会議要約、キャプション生成、コンテンツモデレーション、音声・動画インタラクションに最適です。
入力制限:最大 3 時間の音声または 1 時間の動画
音声制御:命令によりボリューム、話速、感情を調整可能
視覚機能:Qwen3.5 と同等のレベル。画像、音声、環境音、その他のマルチモーダル情報を理解可能
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 種類 |
モデル名、コンテキストウィンドウ、価格、スナップショットバージョンについては、「モデル一覧」をご参照ください。同時実行数のレート制限条件については、「レート制限」をご参照ください。
モデル性能
音声および動画コンテンツ分析
この動画のタイムスタンプ付き詳細な説明を生成します。 | 00:00.000 – 00:02.500 雨に打たれた都市の通りがワイドスクリーンフレームを埋め尽くしています。ロングエクスポージャー撮影により、濡れた路面に赤と青の車のライトが光条状に伸びています。右側の歩道をカメラに向かって歩いている、膝丈の暗色トレンチコートとネクタイを締めた明るい色のシャツを着た男性がいます。雨粒が彼の肩や髪に付着し、それぞれの一歩が湿ったコンクリート上で鈍い「ポロッ」という音を立てています。低く不気味な電子音が周囲の音を背景に鳴り響き、一定の雨音が周囲でパチパチと鳴っています。彼の横にあるレンガ壁にはカラフルなグラフィティが描かれ、遠くにはネオンサインが輝いています。そのうちの一つはオレンジ・レッドの筆記体で「Nice」と明瞭に読み取れ、もう一つの縦型サインには下部に「AT」という文字が見えます。 ...... 00:12.300 – 00:14.533 カメラが下方に傾きます。懐中電灯の光の中に、黄色く変色し、古びた単一枚の紙が浅い水たまりに浮かんでいます。紙の端は焦げて黒くなっており、角は巻き上がっています。インクで書かれた段落が紙面の大部分を占めていますが、水分と焦げ跡により文字は読めません。男性は膝をつき、手袋をはめた指をその文書に向かって伸ばしています。手が近づくにつれて、水面に同心円状の波紋が広がります。サイレンの音がピークに達した後、わずかに弱まり始めますが、周囲の低音は一定のままです。シーンは、震えている紙が触れられる直前にフリーズし、クリップが終了します。 一部のタイムスタンプのみを表示しています。 |
多方言理解
中国の異なる方言で歌う歌手の声質、感情状態、および歌詞全文を説明します。 | この音声は、中国各地域から来た歌手によるラップ演奏で、豊かな方言の多様性を示しています。以下に、各歌手の声質、感情状態、および対応する歌詞について詳細に説明します。 杭州話(呉語) 声質: 男性歌手の声は柔らかく穏やかで、呉語特有の滑らかさと温かみがあります。彼のイントネーションは穏やかに上下し、リズムは軽快で素早く、リラックスした物語風の効果を生み出します。 感情状態: リラックスし、心地よく、日常的な雰囲気を感じさせます。彼は杭州のゆっくりとした生活スタイルと都市の変化について述べており、故郷への愛情と現代の発展に対する考察を表現しています。全体として、居心地の良さと親しみやすさを感じさせます。 歌詞: > 杭州話、聞いてください!私たちの文化には、地元の「児化」発音が含まれます。 > 西湖のそばで花が咲くように、文化的調査は必要ありません——私たちはそれを最もよく理解しています。 > 外国人にはわかりません。「個」「老兒」「粉兒」「丫兒」——外国人はそれらを区別できますか? > 行きましょう!交通は高速です——地下鉄が至る所にあります。チェックしてみましょう。 > 東南アジアとタイを歓迎し、「十三塔」の番組を見ています。私たちの街を誇りに思い、性格は率直です。 > だからあなたはただ「橋を渡る」体験だけのために来ましたか?そして味が違うから、戻らないのですか? 一部の結果のみを表示しています。 |
歌詞キャプション生成
この曲の歌詞を書き起こし、各ラインに対して次のような形式でタイムスタンプを付与します:[00:00:15,020 --> 00:00:28,085] : 風雨の中を歩くときは、頭を高く上げてください。[00:00:28,085 --> 00:00:40,200] 暗闇を恐れないでください。…… | [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 シリーズ:パブリック URL を使用する場合最大 512 個、Base64 エンコーディングを使用する場合最大 250 個
Qwen3-Omni-Flash および Qwen-Omni-Turbo シリーズ:1 個のみ許可
ファイルサイズ:
Qwen3.5-Omni:最大 2 GB、最大 1 時間の再生時間
Qwen3-Omni-Flash:最大 256 MB、最大 150 秒の再生時間
Qwen-Omni-Turbo:最大 150 MB、最大 40 秒の再生時間
ファイル形式:MP4、AVI、MKV、MOV、FLV、WMV など
動画ファイル内の視覚および音声情報は、別々に課金されます。
OpenAI 互換
import os
from openai import OpenAI
client = OpenAI(
# API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得方法については、https://www.alibabacloud.com/help/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.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/zh-CN/20241115/cqqkru/1.mp4"
},
},
{"type": "text", "text": "この動画は何についてですか?"},
],
},
],
# 出力モダリティを設定します。現在サポートされているのは ["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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.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": "この動画は何についてですか?" }]
}],
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/zh/model-studio/get-api-key をご参照ください
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions に置き換えてください
# === 実行前にこのコメントを削除してください ===
curl -X POST https://dashscope-intl.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/zh-CN/20241115/cqqkru/1.mp4"
}
},
{
"type": "text",
"text": "この動画は何についてですか?"
}
]
}
],
"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/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.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/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": "この動画で示されているプロセスを説明してください"},
],
}
],
# 出力モダリティを設定します。現在サポートされているのは ["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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.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/zh/model-studio/get-api-key をご参照ください
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions に置き換えてください
# === 実行前にこのコメントを削除してください ===
curl -X POST https://dashscope-intl.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/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"
}
}'音声およびテキスト入力
ファイル数:
Qwen3.5-Omni シリーズ:パブリック URL を使用する場合最大 2048 個、Base64 エンコーディングを使用する場合最大 250 個
Qwen3-Omni-Flash および Qwen-Omni-Turbo シリーズ:1 個のみ許可
ファイルサイズ:
Qwen3.5-Omni:最大 2 GB、最大 3 時間の再生時間
Qwen3-Omni-Flash:最大 100 MB、最大 20 分の再生時間
Qwen-Omni-Turbo:最大 10 MB、最大 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/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.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/zh-CN/20250211/tixcef/cherry.wav",
"format": "wav",
},
},
{"type": "text", "text": "この音声は何についてですか?"},
],
},
],
# 出力モダリティを設定します。現在サポートされているのは ["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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.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/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" }
});
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/zh/model-studio/get-api-key をご参照ください
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions に置き換えてください
# === 実行前にこのコメントを削除してください ===
curl -X POST https://dashscope-intl.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": "この音声は何についてですか?"
}
]
}
],
"stream":true,
"stream_options":{
"include_usage":true
},
"modalities":["text","audio"],
"audio":{"voice":"Tina","format":"wav"}
}'
画像およびテキスト入力
Qwen-Omni は、1 回のリクエストで複数の画像をサポートしています。画像の要件は以下のとおりです。
画像数:
パブリック URL:最大 2048 枚
Base64 エンコーディング:最大 250 枚
画像サイズ:
Qwen3.5 シリーズ:各画像ファイルは ≤20 MB であること
Qwen3-Omni-Flash および Qwen-Omni-Turbo シリーズ:各画像ファイルは ≤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/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.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": "画像に描かれているシーンは何ですか?"},
],
},
],
# 出力モダリティを設定します。現在サポートされているのは ["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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.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/zh-CN/20241022/emyrja/dog_and_girl.jpeg" },
},
{ "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/zh/model-studio/get-api-key をご参照ください
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions に置き換えてください
# === 実行前にこのコメントを削除してください ===
curl -X POST https://dashscope-intl.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": "text",
"text": "画像に描かれているシーンは何ですか?"
}
]
}
],
"stream":true,
"stream_options":{
"include_usage":true
},
"modalities":["text","audio"],
"audio":{"voice":"Tina","format":"wav"}
}'
Web 検索
Qwen3.5-Omni シリーズは Web 検索をサポートしており、リアルタイムの情報を取得して推論を実行できます。
enable_search パラメーターを使用して Web 検索を有効化し、search_strategy を agent に設定します。以下の例では、リアルタイムクエリに対して Web 検索を有効化する方法を示しています。
OpenAI 互換
# このコードを実行する前に:
# pip install openai
import os
from openai import OpenAI
# クライアントの初期化
client = OpenAI(
# API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得方法については、https://www.alibabacloud.com/help/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
# リクエストの実行(Web 検索を有効化)
try:
completion = client.chat.completions.create(
model="qwen3.5-omni-plus",
messages=[{
"role": "user",
"content": "今日の日付と曜日を調べ、その日に祝われる主な祝日を教えてください。"
}],
stream=True,
stream_options={"include_usage": True},
# Web 検索を有効化
extra_body={
"enable_search": True,
"search_options": {
# Web 検索戦略。"agent" のみがサポートされています。
"search_strategy": "agent"
}
}
)
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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
});
// リクエストの実行(Web 検索を有効化)
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus",
messages: [{
"role": "user",
"content": "今日の日付と曜日を調べ、その日に祝われる主な祝日を教えてください。"
}],
stream: true,
stream_options: {
include_usage: true
},
// Web 検索を有効化
extra_body: {
enable_search: true,
search_options: {
// Web 検索戦略。"agent" のみがサポートされています。
search_strategy: "agent"
}
}
});
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/zh/model-studio/get-api-key をご参照ください
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions に置き換えてください
# === 実行前にこのコメントを削除してください ===
curl -X POST https://dashscope-intl.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": "今日の日付と曜日を調べ、その日に祝われる主な祝日を教えてください。"
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"enable_search": true,
"search_options": {
"search_strategy": "agent"
}
}'注意事項
Web 検索は Qwen3.5-Omni シリーズでのみサポートされています。
search_strategyパラメーターはagentのみを受け付けます。agent戦略に関連する課金ルールについては、「課金詳細」をご参照ください。
思考モードの有効化/無効化
Qwen3-Omni-Flash モデルのみがハイブリッド思考をサポートしています。enable_thinking パラメーターを使用して思考モードを制御します。
true:思考モードを有効化false(デフォルト):思考モードを無効化
OpenAI 互換
import os
from openai import OpenAI
client = OpenAI(
# API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得方法については、https://www.alibabacloud.com/help/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3-omni-flash",
messages=[{"role": "user", "content": "あなたは誰ですか?"}],
# 思考モードの有効化/無効化。思考モードでは音声出力はサポートされていません。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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
}
);
const completion = await openai.chat.completions.create({
model: "qwen3-omni-flash",
messages: [
{ role: "user", content: "あなたは誰ですか?" }
],
// 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/zh/model-studio/get-api-key をご参照ください
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions に置き換えてください
# === 実行前にこのコメントを削除してください ===
curl -X POST https://dashscope-intl.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": "あなたは誰ですか?"
}
],
"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/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.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": "この音声は何についてですか?"},
],
},
{
"role": "assistant",
"content": [{"type": "text", "text": "この音声は「Welcome to Alibaba Cloud」と言っています"}],
},
{
"role": "user",
"content": [{"type": "text", "text": "この会社について教えてください。"}],
},
],
# 出力モダリティを設定します。現在サポートされているのは ["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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.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": "この音声は何についてですか?" },
],
},
{
"role": "assistant",
"content": [{ "type": "text", "text": "この音声は「Welcome to Alibaba Cloud」と言っています" }],
},
{
"role": "user",
"content": [{ "type": "text", "text": "この会社について教えてください。" }]
}],
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/zh/model-studio/get-api-key をご参照ください
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions に置き換えてください
# === 実行前にこのコメントを削除してください ===
curl -X POST https://dashscope-intl.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": "この音声は何についてですか?"
}
]
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "この音声は「Welcome to Alibaba Cloud」と言っています"
}
]
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "この会社について教えてください。"
}
]
}
],
"stream": true,
"stream_options": {
"include_usage": true
},
"modalities": ["text"]
}'出力された Base64 エンコード音声データの解析
方法 1:完了後にデコードQwen-Omni モデルは、音声をストリーミング形式の Base64 エンコードデータとして出力します。モデル生成中に文字列変数を保持し、返される各チャンクの Base64 エンコードデータをその変数に追加できます。生成が完了した後、完全な文字列を Base64 デコードして音声ファイルを取得します。または、返される各チャンクの Base64 エンコードデータをリアルタイムでデコードして再生することもできます。
# pyaudio のインストール手順:
# APPLE Mac OS X
# brew install portaudio
# pip install pyaudio
# Debian/Ubuntu
# sudo apt-get install python-pyaudio python3-pyaudio
# または
# 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/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope-intl.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen3.5-omni-plus", # Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages=[{"role": "user", "content": "あなたは誰ですか?"}],
# 出力モダリティを設定します。現在サポートされているのは ["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()// 実行前に:
// 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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope-intl.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
}
);
const completion = await openai.chat.completions.create({
model: "qwen3.5-omni-plus", // Qwen3-Omni-Flash の場合は、ノンシンキングモードで実行します。
messages: [
{
"role": "user",
"content": "あなたは誰ですか?"
}],
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 文字列を Buffer にデコード
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();
// ファイルの書き込み完了を待機
await new Promise((resolve, reject) => {
outputStream.on('finish', resolve);
outputStream.on('error', reject);
});
// 音声の整合性を確保するために追加の待機時間を設定
await new Promise(resolve => setTimeout(resolve, 800));
console.log(`音声ファイルが ${audioPath} として正常に保存されました`);
} catch (error) {
console.error('処理中にエラーが発生しました:', 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('再生完了'));
// speaker.end(); // API ストリームの実際の終了に基づいて呼び出しBase64 エンコーディングでローカルファイルを送信
画像
この例では、ローカルに保存されたファイル eagle.png を使用します。
import os
from openai import OpenAI
import base64
client = OpenAI(
# API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得方法については、https://www.alibabacloud.com/help/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope-intl.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.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": "画像に描かれているシーンは何ですか?"},
],
},
],
# 出力モダリティを設定します。現在サポートされているのは ["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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope-intl.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.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": "画像に描かれているシーンは何ですか?" }]
}],
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/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope-intl.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.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": "この音声は何についてですか?"},
],
},
],
# 出力モダリティを設定します。現在サポートされているのは ["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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope-intl.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.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": "この音声は何についてですか?" }]
}],
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/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope-intl.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.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": "彼女は何を歌っていますか?"},
],
},
],
# 出力モダリティを設定します。現在サポートされているのは ["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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope-intl.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.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": "彼女は何を歌っていますか?" }]
}],
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/zh/model-studio/get-api-key をご参照ください
api_key=os.getenv("DASHSCOPE_API_KEY"),
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope-intl.aliyuncs.com/compatible-mode/v1 に置き換えてください
base_url="https://dashscope-intl.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_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": "この動画で示されているプロセスを説明してください"},
],
}
],
# 出力モダリティを設定します。現在サポートされているのは ["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/zh/model-studio/get-api-key をご参照ください
apiKey: process.env.DASHSCOPE_API_KEY,
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/compatible-mode/v1 に置き換えてください
baseURL: "https://dashscope-intl.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: "この動画の具体的な手順を説明してください。"
}
]
}],
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 リファレンス
入力および出力パラメーターの完全な仕様については、「Qwen API リファレンス」をご参照ください。
課金とレート制限
課金ルール
Qwen-Omni は、異なるモダリティ(音声、画像、動画)で消費されたトークンに基づいて課金されます。価格の詳細については、「モデル」をご参照ください。
無料クォータ
無料クォータの申請、照会、使用方法については、「新規ユーザー向け無料クォータ」をご参照ください。
レート制限
レート制限ルールおよびよくある質問については、「レート制限」をご参照ください。
エラーコード
モデルの呼び出しに失敗し、エラーメッセージが返された場合は、「エラーメッセージ」で解決策をご確認ください。
音声リスト
Qwen-Omni モデルの音声リストについては、「音声リスト」をご参照ください。