java - twilio: Having trouble getting a Transcription -


i'm creating service using twilio user calls in , leaves message. service reads transcription of message irrelevant processing.

the problem i'm having can't retrieve transcription anywhere. i'm it's because don't understand how use settranscribecallback() method, there no clear examples of how use find.

this class starts recording call, , after user finished, passes off other class processing. (my server's ip address removed)

public class twiliovoice extends httpservlet {  private static final long serialversionuid = 1l;  public void service(httpservletrequest request, httpservletresponse response)         throws ioexception {      twimlresponse twiml = new twimlresponse();      record record = new record();       record.setmaxlength(20);     record.settranscribe(true);     record.settranscribecallback("http://ip/handle-recording");     record.setaction("http://ip/handle-recording");       try {         twiml.append(new say("please state address"));         twiml.append(record);     } catch (twimlexception e) {         e.printstacktrace();     }      response.setcontenttype("application/xml");     response.getwriter().print(twiml.toxml()); } 

this class processes transcription. right now, have whatever user said repeat them.

public void service(httpservletrequest request, httpservletresponse response)         throws ioexception {       string text = request.getparameter("transcriptiontext");     twimlresponse twiml = new twimlresponse();       try {         twiml.append(new say(text));         twiml.append(new say("goodbye"));      } catch (twimlexception e) {         e.printstacktrace();     }      response.setcontenttype("application/xml");     response.getwriter().print(twiml.toxml()); } 

i've tried transcription using sid, whenever try approach, error because transcriptionsid i'm using null.

public void service(httpservletrequest request, httpservletresponse response)         throws ioexception {      string transcriptionsid = request.getparameter("transcriptionsid");     twimlresponse twiml = new twimlresponse();     transcription transcript = null;     string text;      try {         transcript = gettranscript(transcriptionsid );     } catch (twiliorestexception e1) {         e1.printstacktrace();     }      if (transcript != null) {         text = transcript.gettranscriptiontext();     } else {         text = "no go!";     }      try {         twiml.append(new say(text));         twiml.append(new say("goodbye"));      } catch (twimlexception e) {         e.printstacktrace();     }      response.setcontenttype("application/xml");     response.getwriter().print(twiml.toxml()); }  private transcription gettranscript(string sid) throws twiliorestexception {     twiliorestclient client = new twiliorestclient(account_sid, auth_token);      return client.getaccount().gettranscription(sid);  } 

i know web.xml file set right, because can play recording. if 1 can provide help, i'd appreciate it. thanks!

i don't understand how use settranscribecallback() method.

from twiml <record> docs (emphasis mine):

the 'transcribecallback' attribute…allows specify url twilio make asynchronous post request when transcription complete. this…request contain…'transcriptionsid'.

this different action parameter finishes when recording complete because transcription handled different process within twilio's infrastructure.

from record.settranscribecallback("http://ip/handle-recording"); line, looks have of bits wired correctly. if post requests /handle-recording routed class processes transcription (your second snippet), don't know why transcript null.


[t]here no clear examples of how use find.

the official java tutorial automated surveys uses <record> verb's settranscribecallback() method (source).


Comments