TwiML™ Voice: <Gather>

You can use TwiML's <Gather> verb to collect digits or transcribe speech during a call.

The following example shows the most basic use of <Gather> TwiML:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather/>
</Response>

You can always send Twilio plain TwiML, or leverage the helper libraries to add TwiML to your web applications:

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
response.gather();

console.log(response.toString());
using Twilio.TwiML;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Gather();

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$response->gather();

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.gather

puts response
from twilio.twiml.voice_response import Gather, VoiceResponse

response = VoiceResponse()
response.gather()

print(response)
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Gather gather = new Gather.Builder().build();
        VoiceResponse response = new VoiceResponse.Builder().gather(gather)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/simple_gather.xml -->
<Response>
    <Gather/>
</Response>
Toggle to your preferred programming language, or view the raw TwiML to see how the libraries and TwiML syntax differ
Simple <Gather>

Toggle to your preferred programming language, or view the raw TwiML to see how the libraries and TwiML syntax differ

When Twilio executes this TwiML, it will pause for up to five seconds to wait for the caller to enter digits on their keypad. A few things might happen next:

  • The caller enters digits followed by a # symbol or 5 seconds of silence. Twilio will submit those digits in a POST request back to the URL hosting your TwiML.
  • The caller doesn't enter any digits and 5 seconds pass. Twilio will move on to the next TwiML verb in the document – since there are no more verbs here, Twilio will end the call.

By nesting <Say> or <Play> in your <Gather>, you can read some text or play music for your caller while waiting for their input.  See "Nest other verbs" below for examples and more information.

<Gather> Attributes

<Gather> supports the following attributes that change its behavior:

Attribute name Allowed values 初期値
action URL (relative or absolute) 現在の文書の URL
finishOnKey 0-9, #, *, and '' (the empty string) #
hints 「単語、多くの単語を含むフレーズ」 none
input dtmf, speech, dtmf speech dtmf
language BCP-47 language tags en-US
method GET, POST POST
numDigits 正の整数値(秒) 無制限
partialResultCallback URL (relative or absolute) none
partialResultCallbackMethod GET, POST POST
profanityFilter true, false true
speechTimeout positive integer or auto timeout attribute value
Timeout 正の整数値(秒) 5

DIAL動詞 と SMS動詞は、複数の属性を使えます。

下の例ではcallerIdパラメータが省略されていますが、Twilio for KDDI Web Communications をご利用のお客様においては、callerId パラメータで必ずご自身で購入したTwilio電話番号を指定する必要があり、かつ、省略できません。

DIAL動詞で電話をかける場合にはTwilio電話番号(050/0120/0800/その他番号)を、SMS動詞でSMSを送信する場合にはアメリカ番号もしくはSMSが有効なTwilio番号を指定する必要があります。

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather input="speech dtmf" timeout="3" numDigits="1">
        <Say>Please press 1 or say sales for sales.</Say>
    </Gather>
</Response>

action

The action attribute takes an absolute or relative URL as a value. When the caller finishes entering digits (or the timeout is reached), Twilio will make an HTTP request to this URL. That request will include the user's data and Twilio's standard request parameters.

If you do not provide an action parameter, Twilio will POST to the URL that houses the active TwiML document.

Twilio may send some extra parameters with its request after the <Gather> ends:

If you gather digits from the caller, Twilio will include the Digits parameter containing the numbers your caller entered.

If you specify speech as an input with input="speech", Twilio will include SpeechResult and Confidence:

  • SpeechResult contains the transcribed result of your caller's speech.
  • Confidence contains a confidence score between 0.0 and 1.0. A higher confidence score means a better likelihood that the transcription is accurate.

After <Gather> ends and Twilio sends its request to your action URL, the current call will continue using the TwiML you send back from that URL. Because of this, any TwiML verbs that occur after your <Gather> are unreachable.

However, if the caller did not enter any digits or speech, call flow would continue in the original TwiML document.

Without an action URL, Twilio will re-request the URL that hosts the TwiML you just executed. This can lead to unwanted looping behavior if you're not careful. See our example below for more information.

Imagine you have the following TwiML hosted at http://example.com/complex_gather.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather>
        <Say>
            Please enter your account number,
            followed by the pound sign
        </Say>
    </Gather>
    <Say>We didn't receive any input. Goodbye!</Say>
</Response>

Scenario 1: If the caller:

  • does not press the keypad or say anything for five seconds, or
  • enters '#' (the default finishOnKey value) before entering any other digits

then they will hear, "We didn't receive any input. Goodbye!"

Scenario 2: If the caller:

  • enters a digit while the call is speaking "Please enter your account number..."

then the <Say> verb will stop speaking and wait for the user's action.

Scenario 3: If the caller:

  • enters 12345 and then presses #, or
  • allows 5 seconds to pass

then Twilio will submit the digits and request parameters to the URL hosting this TwiML (http://example.com/complex_gather.xml). Twilio will fetch this same TwiML again and execute it, getting the caller stuck in this <Gather> loop.

To avoid this behavior, it's best practice to point your action URL to a new URL that hosts some other TwiML for handling the duration of the call.

The following code sample is almost identical to the TwiML above, but we've added the action and method attributes:

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const gather = response.gather({
    action: '/process_gather.php',
    method: 'GET'
});
gather.say('Please enter your account number,\nfollowed by the pound sign');
response.say('We didn\'t receive any input. Goodbye!');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.Http;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var gather = new Gather(action: new Uri("/process_gather.php"), method: HttpMethod.Get);
        gather
            .Say("Please enter your account number,\nfollowed by the pound sign");
        response.Append(gather);
        response.Say("We didn't receive any input. Goodbye!");

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$gather = $response->gather(['action' => '/process_gather.php',
    'method' => 'GET']);
$gather->say('Please enter your account number,\nfollowed by the pound sign');
$response->say('We didn\'t receive any input. Goodbye!');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.gather(action: '/process_gather.php', method: 'GET') do |gather|
  gather.say(message: 'Please enter your account number,\nfollowed by the pound sign')
end
response.say(message: 'We didn\'t receive any input. Goodbye!')

puts response
from twilio.twiml.voice_response import Gather, VoiceResponse, Say

response = VoiceResponse()
gather = Gather(action='/process_gather.php', method='GET')
gather.say('Please enter your account number,\nfollowed by the pound sign')
response.append(gather)
response.say('We didn\'t receive any input. Goodbye!')

print(response)
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;
import com.twilio.http.HttpMethod;

public class Example {
    public static void main(String[] args) {
        Say say = new Say
            .Builder("Please enter your account number,\nfollowed by the pound sign").build();
        Gather gather = new Gather.Builder().action("/process_gather.php")
            .method(HttpMethod.GET).say(say).build();
        Say say2 = new Say
            .Builder("We didn't receive any input. Goodbye!").build();
        VoiceResponse response = new VoiceResponse.Builder().gather(gather)
            .say(say2).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/complex_gather.xml -->
<Response>
    <Gather action="/process_gather.php" method="GET">
        <Say>
            Please enter your account number,
            followed by the pound sign
        </Say>
    </Gather>
    <Say>We didn't receive any input. Goodbye!</Say>
</Response>
Specify an action URL to properly handle the rest of the call
Complex <Gather> with action/method and nested <Say>

Specify an action URL to properly handle the rest of the call

Now when the caller enters their input, Twilio will submit the digits and request parameters to the process_gather.php URL.

If we wanted to read back this input to the caller, our code hosted at /process_gather.php might look like:

<?php
// page located at http://yourserver/process_gather.php
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<Response><Say>You entered " . $_REQUEST['Digits'] . "</Say></Response>";
?>

Back to attributes list

finishOnKey

finishOnKey lets you set a value that your caller can press to submit their digits or speech.

For example,  if you set finishOnKey to # and your caller enters 1234#, Twilio will immediately stop waiting for more input after they press #.  

Twilio will then submit Digits=1234 to your action URL (note that the # is not included).

Allowed values for this attribute are:

  • # (this is the default value)
  • *
  • Single digits 09 
  • An empty string ('')

If you use an empty string, <Gather> will capture all user input and no key will end the <Gather>. In this case, Twilio submits the user's digits to the action URL only after the timeout is reached.

Back to attributes list

hints

You can improve Twilio's recognition of the words or phrases you expect from your callers by adding hints to your <Gather>.

The hints attribute contains a list of words or phrases that Twilio should expect during recognition.

You may provide up to 500 words or phrases in this list, separating each entry with a comma. Your hints may be up to 100 characters each, and you should separate each word in a phrase with a space, e.g.:

hints="this is a phrase I expect to hear, keyword, product name, name"

Back to attributes list

input

Specify which inputs (DTMF or speech) Twilio should accept with the input attribute.

The default input for <Gather> is dtmf. You can set input to dtmf, speech, or dtmf speech.

If you set input to speech, Twilio will gather speech from the caller for a maximum duration of 60 seconds.

If you're using Twilio's speech recognition with <Gather>, you can use this tool to estimate your costs.

If you set dtmf speech for your input, dtmf will take precedence over speech. If the caller enters the numDigits or presses the finishOnKey , the <Gather> will end without collecting more speech.

The following example shows a <Gather> that specifies speech input from the user. When this TwiML executes, the caller will hear the <Say> prompt. Twilio will then collect speech input for up to 60 seconds.

Once the caller stops speaking for five seconds, Twilio posts their transcribed speech to your action URL.

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const gather = response.gather({
    input: 'speech',
    action: '/completed'
});
gather.say('Welcome to Twilio, please tell us why you\'re calling');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var gather = new Gather(input: "speech", action: new Uri("/completed"));
        gather.Say("Welcome to Twilio, please tell us why you're calling");
        response.Append(gather);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$gather = $response->gather(['input' => 'speech', 'action' => '/completed']);
$gather->say('Welcome to Twilio, please tell us why you\'re calling');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.gather(input: 'speech', action: '/completed') do |gather|
  gather.say(message: 'Welcome to Twilio, please tell us why you\'re calling')
end

puts response
from twilio.twiml.voice_response import Gather, VoiceResponse, Say

response = VoiceResponse()
gather = Gather(input='speech', action='/completed')
gather.say('Welcome to Twilio, please tell us why you\'re calling')
response.append(gather)

print(response)
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Say say = new Say
            .Builder("Welcome to Twilio, please tell us why you're calling").build();
        Gather gather = new Gather.Builder().input("speech")
            .action("/completed").say(say).build();
        VoiceResponse response = new VoiceResponse.Builder().gather(gather)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/simple_gather.xml -->
<Response>
    <Gather input="speech" action="/completed">
           <Say>Welcome to Twilio, please tell us why you're calling</Say>
        </Gather>
</Response>
Gather speech

Back to attributes list

language

The language attribute specifies the language Twilio should recognize from your caller.

This value defaults to en-US, but you can set your language to any of our supported languages: see the full list.

Back to attributes list

method

The method you set on <Gather> tells Twilio whether to request your action URL via HTTP GET or POST.

POST is <Gather>'s default method.

Back to attributes list

numDigits

You can set the number of digits you expect from your caller by including numDigits in <Gather>.

The numDigits attribute only applies to DTMF input.

For example, you might wish to set numDigits="5" when asking your caller to enter their 5-digit zip code. Once the caller enters the final digit of 94117, Twilio will immediately submit the data to your action URL.

Back to attributes list

partialResultCallback

If you provide a partialResultCallback URL, Twilio will make requests to this URL in real-time as it recognizes speech.  These requests will contain a parameter labeled UnstableSpeechResult which contains partial transcriptions. These transcriptions may change as the speech recognition progresses.

The webhooks Twilio makes to your partialResultCallback are asynchronous. They do not accept any TwiML in response. If you want to take more actions based on this partial result, you need to use the REST API to modify the call.

Back to attributes list

profanityFilter

The profanityFilter specifies if Twilio should filter profanities out of your speech transcription. This attribute defaults to true, which replaces all but the initial character in each filtered profane word with asterisks, e.g., 'f***.'

If you set this attribute to false, Twilio will no longer filter any profanities in your transcriptions.

Back to attributes list

speechTimeout

When collecting speech from your caller, speechTimeout sets the limit (in seconds) that Twilio will wait before it stops its speech recognition. After this timeout is reached, Twilio will post the speechResult to your action URL.

If you use both timeout and speechTimeout in your <Gather>, timeout will take precedence for DTMF input and speechTimeout will take precedence for speech.  

If you speechTimeout to auto, Twilio will stop speech recognition when there is a pause in speech and return the results immediately.

Back to attributes list

Timeout

timeout allows you to set the limit (in seconds) that Twilio will wait for the caller to press another digit or say another word before it sends data to your action URL.

For example, if timeout is 3, Twilio wait three seconds for the caller to press another key or say another word before submitting their data.

Twilio will wait until all nested verbs execute before it begins the timeout period.

Back to attributes list

Nest other verbs

You can nest the following verbs within <Gather>:

<Say>

The following example shows a <Gather> with a nested <Say>. This will read some text to the caller, and allows the caller to enter input at any time while that text is read to them:

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const gather = response.gather({
  input: 'speech dtmf',
  timeout: 3,
  numDigits: 1,
});
gather.say('Please press 1 or say sales for sales.');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var gather = new Gather(input: "speech dtmf", timeout: 3, numDigits: 1);
        gather.Say("Please press 1 or say sales for sales.");
        response.Append(gather);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$gather = $response->gather(['input' => 'speech dtmf', 'timeout' => 3,
    'numDigits' => 1]);
$gather->say('Please press 1 or say sales for sales.');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.gather(input: 'speech dtmf', timeout: 3, num_digits: 1) do |gather|
  gather.say(message: 'Please press 1 or say sales for sales.')
end

puts response
from twilio.twiml.voice_response import Gather, VoiceResponse, Say

response = VoiceResponse()
gather = Gather(input='speech dtmf', timeout=3, num_digits=1)
gather.say('Please press 1 or say sales for sales.')
response.append(gather)

print(response)
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;
import java.util.Arrays;


public class Example {
    public static void main(String[] args) {
        Say say = new Say.Builder("Please press 1 or say sales for sales.")
            .build();
        Gather gather = new Gather.Builder().inputs(
          Arrays.asList(Gather.Input.DTMF, Gather.Input.SPEECH))
            .timeout(3).numDigits(1).say(say).build();
        VoiceResponse response = new VoiceResponse.Builder().gather(gather)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather input="speech dtmf" timeout="3" numDigits="1">
        <Say>Please press 1 or say sales for sales.</Say>
    </Gather>
</Response>
Gather speech or DTMF with nested <Say>

When a <Gather> contains nested <Say> or <Play> verbs, the timeout begins either after the audio completes or when the caller presses their first key.

Manage timeouts

When a <Gather> reaches its timeout without any user input, call control will fall through to the next verb in your original TwiML document.

If you wish to have Twilio submit a request to your action URL even if <Gather> times out, include a <Redirect> after the <Gather> like this:

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const gather = response.gather({
    action: '/process_gather.php',
    method: 'GET'
});
gather.say('Enter something, or not');
response.redirect({
    method: 'GET'
}, '/process_gather.php?Digits=TIMEOUT');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.Http;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var gather = new Gather(action: new Uri("/process_gather.php"), method: HttpMethod.Get);
        gather.Say("Enter something, or not");
        response.Append(gather);
        response.Redirect(new Uri("/process_gather.php?Digits=TIMEOUT"), method: HttpMethod.Get);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$gather = $response->gather(['action' => '/process_gather.php',
    'method' => 'GET']);
$gather->say('Enter something, or not');
$response->redirect('/process_gather.php?Digits=TIMEOUT', ['method' => 'GET']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.gather(action: '/process_gather.php', method: 'GET') do |gather|
  gather.say(message: 'Enter something, or not')
end
response.redirect('/process_gather.php?Digits=TIMEOUT', method: 'GET')

puts response
from twilio.twiml.voice_response import Gather, Redirect, VoiceResponse, Say

response = VoiceResponse()
gather = Gather(action='/process_gather.php', method='GET')
gather.say('Enter something, or not')
response.append(gather)
response.redirect('/process_gather.php?Digits=TIMEOUT', method='GET')

print(response)
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.voice.Redirect;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;
import com.twilio.http.HttpMethod;

public class Example {
    public static void main(String[] args) {
        Say say = new Say.Builder("Enter something, or not").build();
        Gather gather = new Gather.Builder().action("/process_gather.php")
            .method(HttpMethod.GET).say(say).build();
        Redirect redirect = new Redirect.Builder("/process_gather.php?Digits=TIMEOUT")
            .method(HttpMethod.GET)
            .build();
        VoiceResponse response = new VoiceResponse.Builder().gather(gather)
            .redirect(redirect).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/gather_hints.xml -->
<Response>
    <Gather action="/process_gather.php" method="GET">
        <Say>Enter something, or not</Say>
    </Gather>
    <Redirect method="GET">
        /process_gather.php?Digits=TIMEOUT
    </Redirect>
</Response>
Send information to your action URL even if <Gather> times out
<Redirect> after <Gather>

Send information to your action URL even if <Gather> times out

With this code, Twilio will move to the next verb in the document (<Redirect>) when <Gather> times out. In our example, we instruct Twilio to make a new GET request to /process_gather.php?Digits=TIMEOUT

トラブルシューティング

A few common problems users face when working with <Gather>:

Problem: <Gather> doesn't receive caller input when the caller is using a VoIP phone.

Solution: Some VoIP phones have trouble sending DTMF digits. This is usually because these phones use compressed bandwidth-conserving audio protocols that interfere with the transmission of the digit's signal. Consult your phone's documentation on DTMF problems.

Problem: Twilio does not send the Digits parameter to your <Gather> URL.

Solution: Check to ensure your application is not responding to the action URL with an HTTP 3xx redirect. Twilio will follow this redirect, but won't resend the Digits parameter.

If you encounter other issues with <Gather>, please reach out to our support team for assistance.

Language appendix

使用可能な言語の記載されたCSVファイルはこちらです。

Language 言語タグ
アフリカーンス語(南アフリカ) af-ZA
アムハラ語(エチオピア) am-ET
アラビア語(アルジェリア) ar-DZ
アラビア語(バーレーン) ar-BH
アラビア語(エジプト) ar-EG
アラビア語(イラク) ar-IQ
アラビア語(イスラエル) ar-IL
アラビア語(ヨルダン) ar-JO
アラビア語(クウェート) ar-KW
アラビア語(レバノン) ar-LB
アラビア語(モロッコ) ar-MA
アラビア語(オマーン) ar-OM
アラビア語(カタール) ar-QA
アラビア語(サウディアラビア) ar-SA
アラビア語(パレスチナ自治区) ar-PS
アラビア語(チュニジア) ar-TN
アラビア語(アラブ首長国連邦) ar-AE
アルメニア語(アルメニア) hy-AM
アゼルバイジャン語(アゼルバイジャン) az-AZ
バスク語(スペイン) eu-ES
ベンガル語(バングラデシュ) bn-BD
ベンガル語(インド) bn-IN
ブルガリア語(ブルガリア) bg-BG
カタルーニャ語(スペイン) ca-ES
中国語、広東語(繁体字、香港) yue-Hant-HK
中国語(簡体字、中国) cmn-Hans-CN
中国語、標準中国語(簡体字、香港) cmn-Hans-HK
中国語(繁体字、台湾) cmn-Hant-TW
クロアチア語(クロアチア) hr-HR
チェコ語(チェコ共和国) cs-CZ
デンマーク語(デンマーク) da-DK
オランダ語(オランダ) nl-NL
英語(オーストラリア) en-AU
英語(カナダ) en-CA
英語(ガーナ) en-GH
英語(インド) en-IN
英語(アイルランド) en-IE
英語(ケニア) en-KE
英語(ニュージーランド) en-NZ
英語(ナイジェリア) en-NG
英語(フィリピン) en-PH
英語(南アフリカ) en-ZA
英語(タンザニア) en-TZ
英語(英国) en-GB
英語(米国) en-US
フィリピン語(フィリピン) il-PH
フィンランド語(フィンランド) fi-FI
フランス語(カナダ) fr-CA
フランス語(フランス) fr-FR
ガリシア語(スペイン) gl-ES
ジョージア語(ジョージア) ka-GE
ドイツ語(ドイツ) de-DE
ギリシャ語(ギリシャ) el-GR
グジャラート語(インド) gu-IN
ヘブライ語(イスラエル) he-IL
ヒンディー語(インド) hi-IN
ハンガリー語(ハンガリー) hu-HU
アイスランド語(アイスランド) is-IS
インドネシア語(インドネシア) id-ID
イタリア語(イタリア) it-IT
日本語(日本) ja-JP
ジャワ語(インドネシア) jv-ID
カナラ語(インド) kn-IN
クメール語(カンボジア) km-KH
韓国語(韓国) ko-KR
ラオ語(ラオス) lo-LA
ラトビア語(ラトビア)  lv-LV
リトアニア語(リトアニア) lt-LT
マレー語(マレーシア) ms-MY
マレーシア(インド) ml-IN
マラーティー語(インド) mr-IN
ネパール語(ネパール)  ne-NP
ノルウェー語ブークモール(ノルウェー) nb-NO
ペルシャ語(イラン) fa-IR
ポーランド語(ポーランド) pl-PL
ポルトガル語(ブラジル) pt-BR
ポルトガル語(ポルトガル) pt-PT
ルーマニア語(ルーマニア) ro-RO
ロシア語(ロシア) ru-RU
セルビア語(セルビア) sr-RS
シンハラ語(スリランカ) si-LK
スロバキア語(チェコスロバキア) sk-SK
スロベニア語(スロベニア) sl-SI
スペイン語(アルゼンチン) es-AR
スペイン語(ボリビア) es-BO
スペイン語(チリ) es-CL
スペイン語(コロンビア) es-CO
スペイン語(コスタリカ) es-CR
スペイン語(ドミニカ共和国) es-DO
スペイン語(エクアドル) es-EC
スペイン語(エルサルバドル) es-SV
スペイン語(グアテマラ) es-GT
スペイン語(ホンデュラス) es-HN
スペイン語(メキシコ) es-MX
スペイン語(ニカラグア) es-NI
スペイン語(パナマ) es-PA
スペイン語(パラグアイ) es-PY
スペイン語(ペルー) es-PE
スペイン語(プエルトリコ) es-PR
スペイン語(スペイン) es-ES
スペイン語(米国) es-US
スペイン語(ウルグアイ) es-UY
スペイン語(ベネズエラ) es-VE
スンダ語(インドネシア) su-ID
スワヒリ語(ケニア)  sw-KE
スワヒリ語(タンザニア) sw-TZ
スウェーデン語(スウェーデン) sv-SE
タミール語(インド) ta-IN
タミール語(マレーシア) ta-MY
タミル語(シンガポール) ta-SG
タミル語(スリランカ) ta-LK
テルグ語(インド) te-IN
タイ語(タイ) th-TH
トルコ語(トルコ) tr-TR
ウクライナ語(ウクライナ) uk-UA
ウルドゥ語(インド) ur-IN
ウルドゥ語(パキスタン) ur-PK
ベトナム語(ベトナム) vi-VN
ズールー語(南アフリカ) zu-ZA

ヘルプが必要ですか?

誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。

コードサンプルを読み込んでいます...
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
response.gather();

console.log(response.toString());
using Twilio.TwiML;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        response.Gather();

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$response->gather();

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.gather

puts response
from twilio.twiml.voice_response import Gather, VoiceResponse

response = VoiceResponse()
response.gather()

print(response)
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Gather gather = new Gather.Builder().build();
        VoiceResponse response = new VoiceResponse.Builder().gather(gather)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/simple_gather.xml -->
<Response>
    <Gather/>
</Response>
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const gather = response.gather({
    action: '/process_gather.php',
    method: 'GET'
});
gather.say('Please enter your account number,\nfollowed by the pound sign');
response.say('We didn\'t receive any input. Goodbye!');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.Http;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var gather = new Gather(action: new Uri("/process_gather.php"), method: HttpMethod.Get);
        gather
            .Say("Please enter your account number,\nfollowed by the pound sign");
        response.Append(gather);
        response.Say("We didn't receive any input. Goodbye!");

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$gather = $response->gather(['action' => '/process_gather.php',
    'method' => 'GET']);
$gather->say('Please enter your account number,\nfollowed by the pound sign');
$response->say('We didn\'t receive any input. Goodbye!');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.gather(action: '/process_gather.php', method: 'GET') do |gather|
  gather.say(message: 'Please enter your account number,\nfollowed by the pound sign')
end
response.say(message: 'We didn\'t receive any input. Goodbye!')

puts response
from twilio.twiml.voice_response import Gather, VoiceResponse, Say

response = VoiceResponse()
gather = Gather(action='/process_gather.php', method='GET')
gather.say('Please enter your account number,\nfollowed by the pound sign')
response.append(gather)
response.say('We didn\'t receive any input. Goodbye!')

print(response)
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;
import com.twilio.http.HttpMethod;

public class Example {
    public static void main(String[] args) {
        Say say = new Say
            .Builder("Please enter your account number,\nfollowed by the pound sign").build();
        Gather gather = new Gather.Builder().action("/process_gather.php")
            .method(HttpMethod.GET).say(say).build();
        Say say2 = new Say
            .Builder("We didn't receive any input. Goodbye!").build();
        VoiceResponse response = new VoiceResponse.Builder().gather(gather)
            .say(say2).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/complex_gather.xml -->
<Response>
    <Gather action="/process_gather.php" method="GET">
        <Say>
            Please enter your account number,
            followed by the pound sign
        </Say>
    </Gather>
    <Say>We didn't receive any input. Goodbye!</Say>
</Response>
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const gather = response.gather({
    input: 'speech',
    action: '/completed'
});
gather.say('Welcome to Twilio, please tell us why you\'re calling');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var gather = new Gather(input: "speech", action: new Uri("/completed"));
        gather.Say("Welcome to Twilio, please tell us why you're calling");
        response.Append(gather);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$gather = $response->gather(['input' => 'speech', 'action' => '/completed']);
$gather->say('Welcome to Twilio, please tell us why you\'re calling');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.gather(input: 'speech', action: '/completed') do |gather|
  gather.say(message: 'Welcome to Twilio, please tell us why you\'re calling')
end

puts response
from twilio.twiml.voice_response import Gather, VoiceResponse, Say

response = VoiceResponse()
gather = Gather(input='speech', action='/completed')
gather.say('Welcome to Twilio, please tell us why you\'re calling')
response.append(gather)

print(response)
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;


public class Example {
    public static void main(String[] args) {
        Say say = new Say
            .Builder("Welcome to Twilio, please tell us why you're calling").build();
        Gather gather = new Gather.Builder().input("speech")
            .action("/completed").say(say).build();
        VoiceResponse response = new VoiceResponse.Builder().gather(gather)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/simple_gather.xml -->
<Response>
    <Gather input="speech" action="/completed">
           <Say>Welcome to Twilio, please tell us why you're calling</Say>
        </Gather>
</Response>
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const gather = response.gather({
  input: 'speech dtmf',
  timeout: 3,
  numDigits: 1,
});
gather.say('Please press 1 or say sales for sales.');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var gather = new Gather(input: "speech dtmf", timeout: 3, numDigits: 1);
        gather.Say("Please press 1 or say sales for sales.");
        response.Append(gather);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$gather = $response->gather(['input' => 'speech dtmf', 'timeout' => 3,
    'numDigits' => 1]);
$gather->say('Please press 1 or say sales for sales.');

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.gather(input: 'speech dtmf', timeout: 3, num_digits: 1) do |gather|
  gather.say(message: 'Please press 1 or say sales for sales.')
end

puts response
from twilio.twiml.voice_response import Gather, VoiceResponse, Say

response = VoiceResponse()
gather = Gather(input='speech dtmf', timeout=3, num_digits=1)
gather.say('Please press 1 or say sales for sales.')
response.append(gather)

print(response)
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;
import java.util.Arrays;


public class Example {
    public static void main(String[] args) {
        Say say = new Say.Builder("Please press 1 or say sales for sales.")
            .build();
        Gather gather = new Gather.Builder().inputs(
          Arrays.asList(Gather.Input.DTMF, Gather.Input.SPEECH))
            .timeout(3).numDigits(1).say(say).build();
        VoiceResponse response = new VoiceResponse.Builder().gather(gather)
            .build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather input="speech dtmf" timeout="3" numDigits="1">
        <Say>Please press 1 or say sales for sales.</Say>
    </Gather>
</Response>
SDKバージョン:
  • 5.x
SDKバージョン:
  • 7.x
SDKバージョン:
  • 3.x
SDKバージョン:
  • 5.x
SDKバージョン:
  • 6.x
SDKバージョン:
  • 5.x
形式:
  • TwiML
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const response = new VoiceResponse();
const gather = response.gather({
    action: '/process_gather.php',
    method: 'GET'
});
gather.say('Enter something, or not');
response.redirect({
    method: 'GET'
}, '/process_gather.php?Digits=TIMEOUT');

console.log(response.toString());
using Twilio.TwiML;
using Twilio.Http;
using Twilio.TwiML.Voice;
using System;


class Example
{
    static void Main()
    {
        var response = new VoiceResponse();
        var gather = new Gather(action: new Uri("/process_gather.php"), method: HttpMethod.Get);
        gather.Say("Enter something, or not");
        response.Append(gather);
        response.Redirect(new Uri("/process_gather.php?Digits=TIMEOUT"), method: HttpMethod.Get);

        Console.WriteLine(response.ToString());;
    }
}
<?php
require_once './vendor/autoload.php';
use Twilio\TwiML;

$response = new TwiML();
$gather = $response->gather(['action' => '/process_gather.php',
    'method' => 'GET']);
$gather->say('Enter something, or not');
$response->redirect('/process_gather.php?Digits=TIMEOUT', ['method' => 'GET']);

echo $response;
require 'twilio-ruby'

response = Twilio::TwiML::VoiceResponse.new
response.gather(action: '/process_gather.php', method: 'GET') do |gather|
  gather.say(message: 'Enter something, or not')
end
response.redirect('/process_gather.php?Digits=TIMEOUT', method: 'GET')

puts response
from twilio.twiml.voice_response import Gather, Redirect, VoiceResponse, Say

response = VoiceResponse()
gather = Gather(action='/process_gather.php', method='GET')
gather.say('Enter something, or not')
response.append(gather)
response.redirect('/process_gather.php?Digits=TIMEOUT', method='GET')

print(response)
import com.twilio.twiml.voice.Gather;
import com.twilio.twiml.voice.Redirect;
import com.twilio.twiml.VoiceResponse;
import com.twilio.twiml.voice.Say;
import com.twilio.twiml.TwiMLException;
import com.twilio.http.HttpMethod;

public class Example {
    public static void main(String[] args) {
        Say say = new Say.Builder("Enter something, or not").build();
        Gather gather = new Gather.Builder().action("/process_gather.php")
            .method(HttpMethod.GET).say(say).build();
        Redirect redirect = new Redirect.Builder("/process_gather.php?Digits=TIMEOUT")
            .method(HttpMethod.GET)
            .build();
        VoiceResponse response = new VoiceResponse.Builder().gather(gather)
            .redirect(redirect).build();

        try {
            System.out.println(response.toXml());
        } catch (TwiMLException e) {
            e.printStackTrace();
        }
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/gather_hints.xml -->
<Response>
    <Gather action="/process_gather.php" method="GET">
        <Say>Enter something, or not</Say>
    </Gather>
    <Redirect method="GET">
        /process_gather.php?Digits=TIMEOUT
    </Redirect>
</Response>