skip to Main Content

Hi i’m new to the Twilio api.

Can any one provide some ideas or good example for converting text to speech(voice).

I’m using java & Rest api & Twilio api.

2

Answers


  1. Chosen as BEST ANSWER

    enter code hereWhen application initiates a call to the Twilio API, for example via the CallFactory.create method, Twilio will send your request to a URL that is expected to return a TwiML response.

    The Say verb converts text to speech that is read back to the caller. is useful for development or saying dynamic text that is difficult to pre-record.

    Another option for responding with TwiML is via the TwiMLResponse class, which is available in the com.twilio.sdk.verbs package.

    reference linK : http://azure.microsoft.com/en-in/documentation/articles/partner-twilio-java-how-to-use-voice-sms/#howto_provide_twiml_responses

    // Use your account SID and authentication token instead
    // of the placeholders shown here.
    String accountSID = "your_twilio_account";
    String authToken = "your_twilio_authentication_token";
    
    // Create an instance of the Twilio client.
    TwilioRestClient client;
    client = new TwilioRestClient(accountSID, authToken);
    
    // Retrieve the account, used later to create an instance of the CallFactory.
    Account account = client.getAccount();
    
    // Use the Twilio-provided site for the TwiML response.
    String Url="http://twimlets.com/message";
    Url = Url + "?Message%5B0%5D=Hello%20World";
    
    // Place the call From, To and URL values into a hash map. 
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("From", "NNNNNNNNNN"); // Use your own value for the second parameter.
    params.put("To", "NNNNNNNNNN");   // Use your own value for the second parameter.
    params.put("Url", Url);
    
    // Create an instance of the CallFactory class.
    CallFactory callFactory = account.getCallFactory();
    
    // Make the call.
    Call call = callFactory.create(params);
    
    • sample code to generating the TWIML using TwiMLResponse class using inputMsgString :

      TwiMLResponse twiml = new TwiMLResponse(); Say say = new Say( inputMsgString); twiml.append(say); msgAsXML = twiml.toXML();


  2. Twilio evangelist here.

    The <Say> TwiML verb does this for you:

    <Response> 
        <Say>Hello World!</Say>
    </Response>
    

    I’d suggest working through the Voice Quickstart. It walks you through using Java to build a servlet that generates and returns TwiML:

    https://www.twilio.com/docs/quickstart/java/twiml/say-response

    Hope that helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search