音声用 API の概要

Nexmo 音声用 API は質の高い音声アプリケーションをクラウドで構築するきわめて簡単な方法であり、次の用途で利用できます。

  • 現在利用中の Web 技術と共に拡張するアプリを構築する
  • Nexmo Call Control Objects (NCCO) を使って、JSON 形式で着信と発信コールフローを制御する
  • 着信と発信コールを録音・保存する
  • カンファレンスコールを作成する
  • テキスト読み上げメッセージを性別やアクセントを変えて40言語で送信する

内容

このドキュメントでは次のトピックを取り上げます。

基本概念

  • JWT で認証 - 音声用 API との交信は JWT (JSON Web Tokens) を使って認証されます。Nexmo ライブラリは Nexmo 音声アプリケーションの固有 ID と秘密鍵を使って JWT 生成を処理します。詳細については、アプリケーションの認証を参照してください。

  • Nexmo 音声アプリケーション - Nexmo 音声アプリケーションはユーザーが構築しているアプリケーションと 1 対 1 でマッピングします。仮想番号や Web フックコールバック URL などの設定を含みます。Nexmo 音声アプリケーションは、Nexmo DashboardNexmo CLI を使用するかアプリケーション用 API を介して作成可能です。

  • NCCO - Nexmo Call Control Objects とは、Nexmo アプリケーションへのコールの操作方法を Nexmo に指示する一連のアクションです。たとえば、コールを connect したり、talk を使用した合成発話を送信したり、オーディオを stream したり、コールを record したりできます。これらのアクションは JSON 形式のオブジェクト配列として表示されます。詳細については、NCCO の関連情報を参照してください。

  • 番号 - Nexmo 音声用 API の電話番号を使用する主な基本概念。

  • Web フック - HTTP リクエストをアプリケーションの Web サーバーに出してそれに基づいて行動できるようにします。たとえば着信は Web フックを送信します。

最初のステップ

音声プレイグラウンド

Nexmo Dashboard では、音声用 API を音声プレイグラウンドでインタラクティブに試すことができます。Nexmo アカウントにサインアップしたら、Nexmo Dashboard の 音声プレイグラウンドに進みます ([音声] ‣ [音声プレイグラウンド])。

こちらのブログ投稿で詳細をお読みいただけます: 音声プレイグラウンド、Nexmo 音声用 API のテストサンドボックスの紹介 (英語)

API の使用

Nexmo 音声プラットフォームとの交信にはパブリック API が主に使用されます。コールを外部に発信するには、POST リクエストを https://api.nexmo.com/v1/calls に出します。

このプロセスを簡素化するため、Nexmo では認証や適切なリクエスト本文の作成をユーザーのために処理するサーバー SDK を多様な言語で提供しています。

開始するには、以下から言語を選択し、コードサンプルの次の変数を置き換えます。

キー 説明
NEXMO_NUMBER コールを発信可能な Nexmo の番号。例: 447700900000
TO_NUMBER E.164 format でコールする番号。例: 447700900001

Prerequisites

A Vonage application contains the required configuration for your project. You can create an application using the Vonage CLI (see below) or via the dashboard. To learn more about applications see our Vonage concepts guide.

Install the CLI

npm install -g nexmo-cli

Create an application

Once you have the CLI installed you can use it to create a Vonage application. Run the following command and make a note of the application ID that it returns. This is the value to use in NEXMO_APPLICATION_ID in the example below. It will also create private.key in the current directory which you will need in the Initialize your dependencies step

Vonage needs to connect to your local machine to access your answer_url. We recommend using ngrok to do this. Make sure to change demo.ngrok.io in the examples below to your own ngrok URL.

nexmo app:create "Outbound Call code snippet" https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json http://demo.ngrok.io/webhooks/events --keyfile private.key

Execute the following command at your terminal prompt to create the JWT for authentication:

export JWT=$(nexmo jwt:generate $PATH_TO_PRIVATE_KEY application_id=$NEXMO_APPLICATION_ID)

Write the code

Add the following to make-an-outbound-call.sh:

curl -X POST https://api.nexmo.com/v1/calls\
  -H "Authorization: Bearer $JWT"\
  -H "Content-Type: application/json"\
  -d '{"to":[{"type": "phone","number": "'$VOICE_TO_NUMBER'"}],
      "from": {"type": "phone","number": "'$VONAGE_VIRTUAL_NUMBER'"},
      "answer_url":["'"$VOICE_ANSWER_URL"'"]}'

View full source

Run your code

Save this file to your machine and run it:

bash make-an-outbound-call.sh

ガイド

  • Cloud Runtime For Voice: Using Voice with Vonge Cloud Runtime.
  • Call Control Objects: To tell Vonage how to handle a phone call, you must provide a Nexmo Call Control Object (NCCO) when a call is placed or answered. There are various actions available, such as `talk`, `input` and `record`.
  • Conference Calling: When a phone call is made or received by Vonage it is added to a conversation. A single conversation contains one or more phone calls (sometimes referred to as legs).
  • Call Flow: The various stages of a call and how they interact.
  • Voice Notifications: In this guide, you will learn how to contact a list of people by phone, convey a message, and see who confirmed that they had received the message. These voice-based critical alerts are more persistent than a text message, making your message more likely to be noticed. Additionally, with the recipient confirmation, you can be sure that your message made it through.
  • Numbers: Numbers are a key part of using the Vonage Voice API. This guide covers number formatting, outgoing caller IDs and incoming call numbers.
  • Interactive Voice Response (IVR): Build an automated phone system for users to input information with the keypad and hear a spoken response
  • Endpoints: When connecting a call, you can connect to another phone number, a `sip` endpoint or a `websocket`. These are known as endpoints.
  • Advanced IVR: This guide shows you how to use Automatic Speech Recognition to create a voice bot/interactive voice assistant application.
  • Regions: Recording audio input from a caller or recording the conversation between two callers.
  • Voice Bot with Google Dialogflow: This guide will help you to start with an example Dialogflow bot and interact with it from phone calls using provided sample reference codes using Vonage Voice API.
  • Text to Speech: Using our Text-To-Speech engine, you can play machine-generated speech to your callers
  • Advanced Machine Detection: Using our Text-To-Speech engine, you can play machine-generated speech to your callers
  • Voice Bot with Amazon Lex: This guide will help you to start with an example Amazon Lex bot and interact with it from Voice Calls using provided sample reference codes using Vonage Voice API.
  • Customizing Spoken Text: Use Speech Synthesis Markup Language (SSML) to control how text-to-speech is read out
  • Click to Call: Learn how to enable your customers to call you directly from your website.
  • Speech to Text: Capture user input by converting user speech to text form during a call.
  • Call Tracking: Keep track of which campaigns are working well by using different numbers for each one and tracking the incoming calls. This guide shows you how to handle incoming calls, connect them to another number, and track the phone numbers that called each of your Vonage numbers.
  • DTMF: Capture user input by detecting DTMF tones (button presses) during a call.
  • Call Recording and Transcription: Recording audio input from a caller or recording the conversation between two callers.
  • Voicemail: Learn how to record audio from inbound calls using .NET and the Vonage Voice API.
  • WebSockets: You can connect the audio of a call to a WebSocket to work with it in real time.
  • Contact Center Intelligence: Learn how to enhance your contact center solution with Voice API.
  • Voice Journey: This guide shows you how to add programmable assistance to your contact center
  • Fraud Prevention: Protect your Voice API applications from fraud
  • Local Numbers: Replace your toll-free numbers (e.g. 800, 0800) with local geographical numbers that allow you to provide a better customer service. Users can make cheaper calls and you can offer location-sensitive information when they contact you.
  • Call Whisper: Phone numbers are everywhere in advertising: on billboards, in TV ads, on websites, in newspapers. Often these numbers all redirect to the same call center, where an agent needs to inquire why the person is calling, and where they saw the advert. Call Whispers make this so much simpler.
  • App to App Calling: Learn how to add calling to your Android, iOS, and Web apps.
  • Programmable SIP: Learn how to integrate your existing SIP Infrastructure with the Vonage Communications Platform.
  • Masked Calling: ユーザーが実際の番号を非公開にしたまま、お互いに電話をかけられるようにします。

コードスニペット

ユースケース

    関連情報