Qwen2-Audio是Qwen大音频语言模型系列的最新版本,能够接收多种音频信号输入,并根据语音指令执行音频分析或直接生成文本响应。
下载量 24
发布时间 : 4/24/2025
模型介绍
内容详情
替代品
模型简介
Qwen2-Audio支持语音聊天和音频分析两种交互模式,能够处理音频输入并生成文本响应,适用于多种音频理解任务。
模型特点
多模式交互
支持语音聊天和音频分析两种交互模式,用户可以通过语音或文本指令与模型交互。
音频理解
能够处理多种音频信号输入,包括语音、环境音等,并进行理解和分析。
文本生成
根据音频输入生成自然语言文本响应,适用于对话和问答场景。
模型能力
音频理解
文本生成
语音交互
音频分析
使用案例
语音交互
语音聊天
用户无需输入文本,即可与模型进行自由语音交互。
生成自然语言文本响应
音频分析
音频内容理解
用户提供音频和文本指令,模型进行分析并生成响应。
识别音频内容并生成描述
license: apache-2.0 language:
- en pipeline_tag: audio-text-to-text tags:
- multimodal library_name: transformers base_model:
- Qwen/Qwen2-Audio-7B-Instruct
在vllm中运行请执行
vllm serve mlinmg/Qwen-2-Audio-Instruct-dynamic-fp8
Qwen/Qwen2-Audio-7B-Instruct-FP8
简介
Qwen2-Audio是Qwen大音频语言模型系列的最新版本。Qwen2-Audio能够接收多种音频信号输入,并根据语音指令执行音频分析或直接生成文本响应。我们引入了两种独特的音频交互模式:
-
语音聊天:用户无需输入文本,即可与Qwen2-Audio自由进行语音交互;
-
音频分析:用户在交互过程中可提供音频和文本指令进行分析;
我们发布了Qwen2-Audio-7B和Qwen2-Audio-7B-Instruct,分别是预训练模型和对话模型。
环境要求
Qwen2-Audio的代码已集成至最新版Hugging Face transformers库,建议通过命令pip install git+https://github.com/huggingface/transformers
从源码安装,否则可能会遇到以下错误:
KeyError: 'qwen2-audio'
快速开始
以下我们将展示如何使用Qwen2-Audio-7B-Instruct
进行推理,支持语音聊天和音频分析两种模式。请注意我们采用ChatML格式进行对话,本示例将展示如何利用apply_chat_template
实现这一功能。
语音聊天推理
在语音聊天模式下,用户无需输入文本即可与Qwen2-Audio自由交互:
from io import BytesIO
from urllib.request import urlopen
import librosa
from transformers import Qwen2AudioForConditionalGeneration, AutoProcessor
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct")
model = Qwen2AudioForConditionalGeneration.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct", device_map="auto")
conversation = [
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/guess_age_gender.wav"},
]},
{"role": "assistant", "content": "Yes, the speaker is female and in her twenties."},
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/translate_to_chinese.wav"},
]},
]
text = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
audios = []
for message in conversation:
if isinstance(message["content"], list):
for ele in message["content"]:
if ele["type"] == "audio":
audios.append(librosa.load(
BytesIO(urlopen(ele['audio_url']).read(),
sr=processor.feature_extractor.sampling_rate)[0]
)
inputs = processor(text=text, audios=audios, return_tensors="pt", padding=True)
inputs.input_ids = inputs.input_ids.to("cuda")
generate_ids = model.generate(**inputs, max_length=256)
generate_ids = generate_ids[:, inputs.input_ids.size(1):]
response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
音频分析推理
在音频分析模式下,用户可同时提供音频和文本指令进行分析:
from io import BytesIO
from urllib.request import urlopen
import librosa
from transformers import Qwen2AudioForConditionalGeneration, AutoProcessor
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct")
model = Qwen2AudioForConditionalGeneration.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct", device_map="auto")
conversation = [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/glass-breaking-151256.mp3"},
{"type": "text", "text": "What's that sound?"},
]},
{"role": "assistant", "content": "It is the sound of glass shattering."},
{"role": "user", "content": [
{"type": "text", "text": "What can you do when you hear that?"},
]},
{"role": "assistant", "content": "Stay alert and cautious, and check if anyone is hurt or if there is any damage to property."},
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/1272-128104-0000.flac"},
{"type": "text", "text": "What does the person say?"},
]},
]
text = processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
audios = []
for message in conversation:
if isinstance(message["content"], list):
for ele in message["content"]:
if ele["type"] == "audio":
audios.append(
librosa.load(
BytesIO(urlopen(ele['audio_url']).read()),
sr=processor.feature_extractor.sampling_rate)[0]
)
inputs = processor(text=text, audios=audios, return_tensors="pt", padding=True)
inputs.input_ids = inputs.input_ids.to("cuda")
generate_ids = model.generate(**inputs, max_length=256)
generate_ids = generate_ids[:, inputs.input_ids.size(1):]
response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
批量推理
我们还支持批量推理:
from io import BytesIO
from urllib.request import urlopen
import librosa
from transformers import Qwen2AudioForConditionalGeneration, AutoProcessor
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct")
model = Qwen2AudioForConditionalGeneration.from_pretrained("Qwen/Qwen2-Audio-7B-Instruct", device_map="auto")
conversation1 = [
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/glass-breaking-151256.mp3"},
{"type": "text", "text": "What's that sound?"},
]},
{"role": "assistant", "content": "It is the sound of glass shattering."},
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/f2641_0_throatclearing.wav"},
{"type": "text", "text": "What can you hear?"},
]}
]
conversation2 = [
{"role": "user", "content": [
{"type": "audio", "audio_url": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-Audio/audio/1272-128104-0000.flac"},
{"type": "text", "text": "What does the person say?"},
]},
]
conversations = [conversation1, conversation2]
text = [processor.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False) for conversation in conversations]
audios = []
for conversation in conversations:
for message in conversation:
if isinstance(message["content"], list):
for ele in message["content"]:
if ele["type"] == "audio":
audios.append(
librosa.load(
BytesIO(urlopen(ele['audio_url']).read()),
sr=processor.feature_extractor.sampling_rate)[0]
)
inputs = processor(text=text, audios=audios, return_tensors="pt", padding=True)
inputs['input_ids'] = inputs['input_ids'].to("cuda")
inputs.input_ids = inputs.input_ids.to("cuda")
generate_ids = model.generate(**inputs, max_length=256)
generate_ids = generate_ids[:, inputs.input_ids.size(1):]
response = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)
引用
如果您觉得我们的工作有帮助,欢迎引用。
@article{Qwen2-Audio,
title={Qwen2-Audio技术报告},
author={褚云飞、徐进、杨倩、韦浩杰、魏希品、郭志芳、冷毅冲、吕元君、何金正、林俊旸、周畅、周靖人},
journal={arXiv预印本 arXiv:2407.10759},
year={2024}
}
@article{Qwen-Audio,
title={Qwen-Audio:通过统一的大规模音频语言模型推进通用音频理解},
author={褚云飞、徐进、周晓环、杨倩、张士亮、闫志杰、周畅、周靖人},
journal={arXiv预印本 arXiv:2311.07919},
year={2023}
}
Phi 4 Multimodal Instruct
MIT
Phi-4-multimodal-instruct是一款轻量级开源多模态基础模型,融合了Phi-3.5和4.0模型的语言、视觉及语音研究数据。
文本生成音频
Transformers

支持多种语言
P
microsoft
584.02k
1,329
Ultravox V0 5 Llama 3 2 1b
MIT
Ultravox是一个基于Llama3.2-1B和Whisper-large-v3构建的多模态语音大语言模型,能够同时处理语音和文本输入。
文本生成音频
Transformers

支持多种语言
U
fixie-ai
167.25k
21
Seamless M4t V2 Large
SeamlessM4T v2 是 Facebook 发布的大规模多语言多模态机器翻译模型,支持近100种语言的语音和文本翻译。
文本生成音频
Transformers

支持多种语言
S
facebook
64.59k
821
Ultravox V0 3
MIT
Ultravox 是一个基于 Llama3.1-8B-Instruct 和 Whisper-small 构建的多模态语音大语言模型,能够同时处理语音和文本输入。
文本生成音频
Transformers

英语
U
fixie-ai
48.30k
17
Ultravox V0 5 Llama 3 1 8b
MIT
Ultravox是一款基于Llama3.1-8B-Instruct和whisper-large-v3-turbo构建的多模态语音大语言模型,能够同时处理语音和文本输入。
文本生成音频
Transformers

支持多种语言
U
fixie-ai
17.86k
12
Hf Seamless M4t Medium
SeamlessM4T 是一个多语言翻译模型,支持语音和文本的输入输出,实现跨语言交流。
文本生成音频
Transformers

H
facebook
14.74k
30
Granite Speech 3.3 8b
Apache-2.0
专为自动语音识别(ASR)和自动语音翻译(AST)设计的紧凑高效语音语言模型,采用双阶段设计处理音频和文本
文本生成音频
Transformers

英语
G
ibm-granite
5,532
35
Voila Tokenizer
MIT
Voila是一个大型语音-语言基础模型系列,旨在提升人机交互体验,支持多种音频任务和语言。
文本生成音频
Transformers

支持多种语言
V
maitrix-org
4,912
3
Hf Seamless M4t Large
SeamlessM4T 是一个支持多语言语音和文本翻译的统一模型,能够实现语音到语音、语音到文本、文本到语音和文本到文本的翻译任务。
文本生成音频
Transformers

H
facebook
4,648
57
Minicpm O 2 6 Int4
MiniCPM-o 2.6的int4量化版本,显著降低GPU显存占用,支持多模态处理能力。
文本生成音频
Transformers

其他
M
openbmb
4,249
42
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers

支持多种语言
L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers

英语
C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统
中文
R
uer
2,694
98
AIbase是一个专注于MCP服务的平台,为AI开发者提供高质量的模型上下文协议服务,助力AI应用开发。
简体中文