音声用 API の概要
Nexmo 音声用 API は質の高い音声アプリケーションをクラウドで構築するきわめて簡単な方法であり、次の用途で利用できます。
- 現在利用中の Web 技術と共に拡張するアプリを構築する
- Nexmo Call Control Objects (NCCO) を使って、JSON 形式で着信と発信コールフローを制御する
- 着信と発信コールを録音・保存する
- カンファレンスコールを作成する
- テキスト読み上げメッセージを性別やアクセントを変えて40言語で送信する
内容
このドキュメントでは次のトピックを取り上げます。
- Nexmo 音声用 API の基本概念 で基本用語を学ぶ
- 音声用 API を使い始める方法 (使用言語での例を交えて)
- ガイド 音声用 API の操作方法
- コードスニペット 特定のタスクに役立つコードスニペット
- ユースケース コードサンプルを使った詳細なユースケース
- 関連情報 API に関するドキュメントとその他の補足コンテンツ
基本概念
JWT で認証 - 音声用 API との交信は JWT (JSON Web Tokens) を使って認証されます。Nexmo ライブラリは Nexmo 音声アプリケーションの固有 ID と秘密鍵を使って JWT 生成を処理します。詳細については、アプリケーションの認証を参照してください。
Nexmo 音声アプリケーション - Nexmo 音声アプリケーションはユーザーが構築しているアプリケーションと 1 対 1 でマッピングします。仮想番号や Web フックコールバック URL などの設定を含みます。Nexmo 音声アプリケーションは、Nexmo Dashboard、Nexmo 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
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.
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"'"]}'Run your code
Save this file to your machine and run it:
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
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.
npm install @vonage/server-sdkCreate a file named make-an-outbound-call.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Write the code
Add the following to make-an-outbound-call.js:
vonage.voice.createOutboundCall({
to: [
{
type: 'phone',
number: VOICE_TO_NUMBER,
},
],
from: {
type: 'phone',
number: VONAGE_VIRTUAL_NUMBER,
},
answer_url: [VOICE_ANSWER_URL],
})
.then((resp) => console.log(resp))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
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
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.
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Create a class named OutboundTextToSpeechCall and add the following code to the main method:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}Write the code
Add the following to the main method of the OutboundTextToSpeechCall class:
val callEvent = client.voice.createCall {
toPstn(VOICE_TO_NUMBER)
from(VONAGE_VIRTUAL_NUMBER)
answerUrl(VOICE_ANSWER_URL)
}Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.voice with the package containing OutboundTextToSpeechCall:
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
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.
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Create a class named OutboundTextToSpeech and add the following code to the main method:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();Write the code
Add the following to the main method of the OutboundTextToSpeech class:
client.getVoiceClient().createCall(new Call(VOICE_TO_NUMBER, VONAGE_VIRTUAL_NUMBER, VOICE_ANSWER_URL));Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.voice with the package containing OutboundTextToSpeech:
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
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.
Install-Package VonageWrite the code
Add the following to MakeOutboundCall.cs:
var creds = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(creds);
var answerUrl = "https://nexmo-community.github.io/ncco-examples/text-to-speech.json";
var toEndpoint = new PhoneEndpoint() { Number = VOICE_TO_NUMBER };
var fromEndpoint = new PhoneEndpoint() { Number = VONAGE_VIRTUAL_NUMBER };
var command = new CallCommand() { To = new Endpoint[] { toEndpoint }, From = fromEndpoint, AnswerUrl = new[] { answerUrl } };
var response = await client.VoiceClient.CreateCallAsync(command);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
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.
composer require vonage/clientRun your code
Save this file to your machine and run it:
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
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.
pip install vonage python-dotenvWrite the code
Add the following to make-an-outbound-call.py:
from vonage import Auth, Vonage
from vonage_voice import CreateCallRequest, Phone, ToPhone
client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_PRIVATE_KEY,
)
)
response = client.voice.create_call(
CreateCallRequest(
answer_url=[VOICE_ANSWER_URL],
to=[ToPhone(number=VOICE_TO_NUMBER)],
from_=Phone(number=VONAGE_VIRTUAL_NUMBER),
)
)
pprint(response)Run your code
Save this file to your machine and run it:
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
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.
gem install vonageRun your code
Save this file to your machine and run it:
ガイド
- 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: ユーザーが実際の番号を非公開にしたまま、お互いに電話をかけられるようにします。
コードスニペット
- Before You Begin
- Controlling-conference-calls / Connect callers into a conference
- Controlling-conversations / Track NCCO progress
- Controlling-conversations / Transfer a call
- Controlling-conversations / Transfer a call with inline NCCO
- Controlling-media / Earmuff a call
- Controlling-media / Mute a call
- Controlling-media / Play an audio stream into a call
- Controlling-media / Play DTMF into a call
- Controlling-media / Play text-to-speech into a call
- Controlling-media / Stop an audio stream in a call
- Controlling-media / Stop text-to-speech in a call
- Controlling-media / Subscribe to real-time DTMF events
- Controlling-media / Unsubscribe to real-time DTMF events
- Handle-user-input / Handle user input with ASR
- Handle-user-input / Handle user input with DTMF
- Making-calls / Connect an inbound call
- Making-calls / Make an outbound call
- Making-calls / Make an outbound call with an NCCO
- Programmable-sip / Create a Domain
- Programmable-sip / Create a Domain User
- Programmable-sip / Delete a Domain
- Programmable-sip / Delete a Domain User
- Programmable-sip / Query a Domain
- Programmable-sip / Query a Domain User
- Programmable-sip / Query Domain Users
- Programmable-sip / Query Domains
- Programmable-sip / Update a Domain
- Programmable-sip / Update a Domain User
- Receiving-calls / Receive an inbound call
- Recording-calls / Download a recording
- Recording-calls / Record a call
- Recording-calls / Record a call with split audio
- Recording-calls / Record a message
- Recording-calls / Record a named conversation
- Retrieving-calls / Retrieve information for a call
- Retrieving-calls / Retrieve information for all calls