Search code examples
twiliotwilio-apitwilio-programmable-voice

Twilio trail account do not have speech-to-text feature


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!


Solution

  • 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());
    }