语音IVR

本文为您展示了如何调用IvrCall接口实现交互式语音应答。

功能介绍

语音IVR是指通过调用语音呼叫的API,从运营商网络向指定号码发起一通呼叫,呼叫被接起后,播放一段指定音频,用户根据音频引导,通过手机按键信息返回意图,语音平台通过消息回执返回按键信息给企业业务系统。

准备工作

在实现调用API实现语音IVR功能前,您需要完成以下操作:

代码示例

本示例展示了如何调用IvrCall进行语音交互。接口详情,请参见IvrCall

如果您需要进行调试,请参见使用OpenAPI Explorer

// This file is auto-generated, don't edit it. Thanks.

import com.aliyun.tea.*;
import com.aliyun.dyvmsapi20170525.*;
import com.aliyun.dyvmsapi20170525.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;

public class Sample {

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dyvmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dyvmsapi.aliyuncs.com";
        return new com.aliyun.dyvmsapi20170525.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dyvmsapi20170525.Client client = Sample.createClient("accessKeyId", "accessKeySecret");
        IvrCallRequest ivrCallRequest = new IvrCallRequest()
                .setCalledShowNumber("05710000****")
                .setCalledNumber("1580000****")
                .setStartCode("TTS_71390****");
        // 复制代码运行请自行打印 API 的返回值
        client.ivrCall(ivrCallRequest);
    }
}
# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys

from typing import List

from alibabacloud_dyvmsapi20170525.client import Client as Dyvmsapi20170525Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_dyvmsapi20170525 import models as dyvmsapi_20170525_models


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> Dyvmsapi20170525Client:
        """
        使用AK&SK初始化账号Client
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            # 您的AccessKey ID,
            access_key_id=access_key_id,
            # 您的AccessKey Secret,
            access_key_secret=access_key_secret
        )
        # 访问的域名
        config.endpoint = 'dyvmsapi.aliyuncs.com'
        return Dyvmsapi20170525Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client('accessKeyId', 'accessKeySecret')
        ivr_call_request = dyvmsapi_20170525_models.IvrCallRequest(
            called_show_number='05710000****',
            called_number='1580000****',
            start_code='TTS_71390****'
        )
        # 复制代码运行请自行打印 API 的返回值
        client.ivr_call(ivr_call_request)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client('accessKeyId', 'accessKeySecret')
        ivr_call_request = dyvmsapi_20170525_models.IvrCallRequest(
            called_show_number='05710000****',
            called_number='1580000****',
            start_code='TTS_71390****'
        )
        # 复制代码运行请自行打印 API 的返回值
        await client.ivr_call_async(ivr_call_request)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])
// This file is auto-generated, don't edit it. Thanks.
package main

import (
  "os"
  dyvmsapi20170525  "github.com/alibabacloud-go/dyvmsapi-20170525/v2/client"
  openapi  "github.com/alibabacloud-go/darabonba-openapi/client"
  "github.com/alibabacloud-go/tea/tea"
)


/**
 * 使用AK&SK初始化账号Client
 * @param accessKeyId
 * @param accessKeySecret
 * @return Client
 * @throws Exception
 */
func CreateClient (accessKeyId *string, accessKeySecret *string) (_result *dyvmsapi20170525.Client, _err error) {
  config := &openapi.Config{
    // 您的AccessKey ID
    AccessKeyId: accessKeyId,
    // 您的AccessKey Secret
    AccessKeySecret: accessKeySecret,
  }
  // 访问的域名
  config.Endpoint = tea.String("dyvmsapi.aliyuncs.com")
  _result = &dyvmsapi20170525.Client{}
  _result, _err = dyvmsapi20170525.NewClient(config)
  return _result, _err
}

func _main (args []*string) (_err error) {
  client, _err := CreateClient(tea.String("accessKeyId"), tea.String("accessKeySecret"))
  if _err != nil {
    return _err
  }

  ivrCallRequest := &dyvmsapi20170525.IvrCallRequest{
    CalledShowNumber: tea.String("05710000****"),
    CalledNumber: tea.String("1580000****"),
    StartCode: tea.String("TTS_71390****"),
  }
  // 复制代码运行请自行打印 API 的返回值
  _, _err = client.IvrCall(ivrCallRequest)
  if _err != nil {
    return _err
  }
  return _err
}


func main() {
  err := _main(tea.StringSlice(os.Args[1:]))
  if err != nil {
    panic(err)
  }
}
<?php

// This file is auto-generated, don't edit it. Thanks.
namespace AlibabaCloud\SDK\Sample;

use AlibabaCloud\SDK\Dyvmsapi\V20170525\Dyvmsapi;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dyvmsapi\V20170525\Models\IvrCallRequest;

class Sample {

    /**
     * 使用AK&SK初始化账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Dyvmsapi Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // 您的AccessKey ID
            "accessKeyId" => $accessKeyId,
            // 您的AccessKey Secret
            "accessKeySecret" => $accessKeySecret
        ]);
        // 访问的域名
        $config->endpoint = "dyvmsapi.aliyuncs.com";
        return new Dyvmsapi($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient("accessKeyId", "accessKeySecret");
        $ivrCallRequest = new IvrCallRequest([
            "calledShowNumber" => "05710000****",
            "calledNumber" => "1580000****",
            "startCode" => "TTS_71390****"
        ]);
        // 复制代码运行请自行打印 API 的返回值
        $client->ivrCall($ivrCallRequest);
    }
}
$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($path)) {
    require_once $path;
}
Sample::main(array_slice($argv, 1));
// This file is auto-generated, don't edit it. Thanks.

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

using Tea;
using Tea.Utils;


namespace AlibabaCloud.SDK.Sample
{
    public class Sample 
    {

        /**
         * 使用AK&SK初始化账号Client
         * @param accessKeyId
         * @param accessKeySecret
         * @return Client
         * @throws Exception
         */
        public static AlibabaCloud.SDK.Dyvmsapi20170525.Client CreateClient(string accessKeyId, string accessKeySecret)
        {
            AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
            {
                // 您的AccessKey ID
                AccessKeyId = accessKeyId,
                // 您的AccessKey Secret
                AccessKeySecret = accessKeySecret,
            };
            // 访问的域名
            config.Endpoint = "dyvmsapi.aliyuncs.com";
            return new AlibabaCloud.SDK.Dyvmsapi20170525.Client(config);
        }

        public static void Main(string[] args)
        {
            AlibabaCloud.SDK.Dyvmsapi20170525.Client client = CreateClient("accessKeyId", "accessKeySecret");
            AlibabaCloud.SDK.Dyvmsapi20170525.Models.IvrCallRequest ivrCallRequest = new AlibabaCloud.SDK.Dyvmsapi20170525.Models.IvrCallRequest
            {
                CalledShowNumber = "05710000****",
                CalledNumber = "1580000****",
                StartCode = "TTS_71390****",
            };
            // 复制代码运行请自行打印 API 的返回值
            client.IvrCall(ivrCallRequest);
        }


    }
}
// This file is auto-generated, don't edit it
import Dyvmsapi20170525, * as $Dyvmsapi20170525 from '@alicloud/dyvmsapi20170525';
// 依赖的模块可通过下载工程中的模块依赖文件或右上角的获取 SDK 依赖信息查看
import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import * as $tea from '@alicloud/tea-typescript';


export default class Client {

  /**
   * 使用AK&SK初始化账号Client
   * @param accessKeyId
   * @param accessKeySecret
   * @return Client
   * @throws Exception
   */
  static createClient(accessKeyId: string, accessKeySecret: string): Dyvmsapi20170525 {
    let config = new $OpenApi.Config({
      // 您的AccessKey ID
      accessKeyId: accessKeyId,
      // 您的AccessKey Secret
      accessKeySecret: accessKeySecret,
    });
    // 访问的域名
    config.endpoint = "dyvmsapi.aliyuncs.com";
    return new Dyvmsapi20170525(config);
  }

  static async main(args: string[]): Promise<void> {
    let client = Client.createClient("accessKeyId", "accessKeySecret");
    let ivrCallRequest = new $Dyvmsapi20170525.IvrCallRequest({
      calledShowNumber: "05710000****",
      calledNumber: "1580000****",
      startCode: "TTS_71390****",
    });
    // 复制代码运行请自行打印 API 的返回值
    await client.ivrCall(ivrCallRequest);
  }

}

Client.main(process.argv.slice(2));

执行结果

正常返回结果如下所示:

{
  "Message": "OK",
  "RequestId": "4ABF7FB6-449C-4624-8CC6-9AAE36845****",
  "Code": "OK",
  "CallId": "1187209624900105518****"
}

调用SDK返回错误码,详情请参见错误码列表

阿里云首页 语音服务 相关技术圈