0

I have a twilio trail account number. I want to know whether speech recognition feature is disabled for trail accounts.

I tried to capture speech using Gather verb. but it does not work.

Thank you!

Dhanushka Sampath
  • 217
  • 1
  • 5
  • 17
  • When you say it doesn't work, what do you mean exactly? What have you tried and what were the results? Thanks – philnash Apr 30 '18 at 00:20
  • I got a twilio number. I want to capture the voice of a user who calls to that number and speak. I am trying to get that speak as string.(twilio can handle the speech-to-text part). According to twilio official documentation it says by using verb I can do it. – Dhanushka Sampath Apr 30 '18 at 03:46
  • Yes, but what have you tried and what do you mean that it does not work? – philnash Apr 30 '18 at 03:47
  • https://drive.google.com/open?id=1tvDmNKNqBYrj20nQ8IcAq3GupvGEhs9I – Dhanushka Sampath Apr 30 '18 at 03:53
  • Ok, that's your code for your controller. How does it not work? – philnash Apr 30 '18 at 03:55
  • after running my web application(above controller), and get a call to that number I hear the phrase I written inside . but it does not goes to the action url of the verb . I gave another method inside the same class as action url since I am doing the testing. If it works properly the request body that comes to the test(){} method should contain the speech that the user has done. But in this code even the action url do not execute and do not comes to the test() method. – Dhanushka Sampath Apr 30 '18 at 04:07
  • That is the issue with me. Could you please help me in this case. Thank you! – Dhanushka Sampath Apr 30 '18 at 04:09
  • I think I know what's going on, drafting an answer now :) – philnash Apr 30 '18 at 04:10

1 Answers1

0

Twilio developer evangelist here.

I think the issue here is that the <Gather> is not setup to hear the caller if they start speaking during the <Say> portion of the call.

Your TwiML from the code you shared looks a bit like this:

<Response>
  <Say>Welcome to Twilio, please tell us why you're calling</Say>
  <Gather input="speech" timeout="5" action="https://f2b4fbc1.ngrok.io/asr/test"></Gather>
</Response>

So, the <Gather> only starts listening once the <Say> is complete.

Instead, you should nest the <Say> within the <Gather> to make TwiML like this:

<Response>
  <Gather input="speech" timeout="5" action="https://f2b4fbc1.ngrok.io/asr/test">
    <Say>Welcome to Twilio, please tell us why you're calling</Say>
  </Gather>
</Response>

The code for this should look like:

Say say = new Say.Builder("Welcome to Twilio, please tell us why you're calling").build();  
Gather gather = new Gather.Builder().input(Gather.Input.SPEECH).timeout(5).action("https://f2b4fbc1.ngrok.io/asr/test").say(say).build();       
VoiceResponse response = new VoiceResponse.Builder().gather(gather).build();

Let me know if that helps at all.

[edit]

I also believe that you need to be setting the content type when you return the XML. I'm not a Spring/Java developer, but here's what I think you need to change

@RequestMapping(method = RequestMethod.POST, value = "/recordTheSpeech", produces = MediaType.APPLICATION_XML_VALUE)
public ResponseEntity<String> recordTheSpeech() throws IOException {
    Say say = new Say.Builder("Welcome to Twilio, please tell us why you're calling").build();
    Gather gather = new Gather.Builder().input(Gather.Input.SPEECH).timeout(5).action("https://f2b4fbc1.ngrok.io/asr/test").say(say).build();
    VoiceResponse response = new VoiceResponse.Builder().gather(gather).build();

    return new ResponseEntity.ok().body(response.toXml());
}
philnash
  • 70,667
  • 10
  • 60
  • 88
  • I tried that also. then also I heard the phrase inside and call ended automatically. without executing the method corresponding to action url. (test()). I am not sure with three things. 1. Is the url given as action is in correct format? 2. Is it ok to return a string by recordTheSpeech(); since twilio needs data from our web app in TwiML format. 3. since I have a trail twilio phone number;is it affect this issue? – Dhanushka Sampath Apr 30 '18 at 11:53
  • I have another idea! You still want the `` to be nested in the `` but I think Twilio might just be getting the response as text. Can you set the `Content-Type` of the response as `text/xml` and try it again? – philnash May 01 '18 at 00:45
  • could you please tell me from where do i need to make change? – Dhanushka Sampath May 01 '18 at 01:59
  • Yes you were correct, the issue was with the content type. @RequestMapping(produces = MediaType.APPLICATION_XML_VALUE ,method = RequestMethod.POST,value = "/recordTheSpeech") – Dhanushka Sampath May 01 '18 at 03:16
  • after changing the content type the issue solved. Thank you so much. – Dhanushka Sampath May 01 '18 at 03:18
  • I just added an update to my answer. Glad to see you have sorted it though. Could you mark the answer as correct so that others can see it helped too, please? Thanks! – philnash May 01 '18 at 03:19
  • Hi philnash. faced an issue again. I wanted to use the redirect verb inside a if statement. here is that code snippet. Redirect redirect = new Redirect.Builder("https://bd3dbfce.ngrok.io/asr/sayItAgain").method(HttpMethod.POST).build(); VoiceResponse response = new VoiceResponse.Builder().redirect(redirect) .build(); return response.toXml(); – Dhanushka Sampath May 03 '18 at 08:31
  • but when i run the code I here someone is reading the url without redirecting to that url. could you please give me a hint what might be the issue. Thank you! – Dhanushka Sampath May 03 '18 at 08:34
  • I'm not sure what you're asking here, and this sounds like a new question. Could you start a new question with as much detail as you can include, and then let me know? – philnash May 04 '18 at 00:02
  • Ohh It was the same mistake from my side. I have not included " @RequestMapping(produces = MediaType.APPLICATION_XML_VALUE)" to the corresponding method. Problem solved. Thank you for your time!!! – Dhanushka Sampath May 04 '18 at 03:54