快速开始

通义千问Audio

说明

支持的领域 / 任务:aigc

通义千问Audio是阿里云研发的大规模音频语言模型。通义千问Audio可以以多种音频 (包括说话人语音、自然音、音乐、歌声)和文本作为输入,并以文本作为输出。通义千问Audio模型的特点包括:

1、全类型音频感知:通义千问Audio是一个性能卓越的通用音频理解模型,支持30秒内的自然音、人声、音乐等类型音频理解,如多语种语音识别,时间抽定位,说话人情绪、性别识别,环境识别,音乐的乐器、风格、情感识别等。

2、基于音频推理:通义千问Audio支持基于音频内容进行相关推理和创作,如语义理解,场景推理,相关推荐,内容创作等。

3、支持多轮音频和文本对话:通义千问Audio支持多音频分析、多轮音频-文本交错对话。

快速开始

前提条件

示例代码

以下示例展示了调用通义千问Audio API对一个用户指令进行响应的代码。

说明

需要使用您的API-KEY替换示例中的 YOUR_DASHSCOPE_API_KEY,代码才能正常运行。

设置API-KEY

export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
from http import HTTPStatus
import dashscope


def simple_multimodal_conversation_call():
    """Simple single round multimodal conversation call.
    """
    messages = [
        {
            "role": "user",
            "content": [
                {"audio": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"},
                {"text": "这段音频在说什么?"}
            ]
        }
    ]
    response = dashscope.MultiModalConversation.call(model='qwen-audio-turbo',
                                                     messages=messages)
    # The response status_code is HTTPStatus.OK indicate success,
    # otherwise indicate request is failed, you can get error code
    # and message from code and message.
    if response.status_code == HTTPStatus.OK:
        print(response)
    else:
        print(response.code)  # The error code.
        print(response.message)  # The error message.


if __name__ == '__main__':
    simple_multimodal_conversation_call()
// Copyright (c) Alibaba, Inc. and its affiliates.

import java.util.Arrays;
import java.util.Collections;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;

public class Main {
    public static void simpleMultiModalConversationCall()
            throws ApiException, NoApiKeyException, UploadFileException {
        MultiModalConversation conv = new MultiModalConversation();
        MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
        .content(Arrays.asList(Collections.singletonMap("audio", "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"), 
        Collections.singletonMap("text", "这段音频在说什么?"))).build();
        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .model("qwen-audio-turbo")
                .message(userMessage)
                .build();
        MultiModalConversationResult result = conv.call(param);
        System.out.println(result);
    }

    public static void main(String[] args) {
        try {
            simpleMultiModalConversationCall();
        } catch (ApiException | NoApiKeyException | UploadFileException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}

python 调用成功后,将会返回如下示例结果。

{
    "status_code": 200,
    "request_id": "cd828016-bcf5-94c7-82ed-5b45bf06886c",
    "code": "",
    "message": "",
    "output": {
        "choices": [
            {
                "finish_reason": null,
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "text": "这段音频在说中文:\"欢迎使用阿里云\"。"
                        }
                    ]
                }
            }
        ]
    },
    "usage": {
        "input_tokens": 1276,
        "audio_tokens": 768,
        "output_tokens": 19
    }
}

了解更多

有关通义千问Audio API的详细调用文档可前往API详情页面进行了解。