Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TwinML Java Say: Cyrillic letters are not read

I have downloaded the IVR for beginners tutorial and modified it a little to provide voice responses in Russian (java file's encoding is UTF-8):

@Override
protected void doPost(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
        throws IOException {
    VoiceResponse response = new VoiceResponse.Builder()
            .gather(new Gather.Builder()
                    .action("/menu/show")
                    .numDigits(1)
                    .build())
            .say(new Say.Builder("Привет")
                  .voice(Say.Voice.ALICE)
                  .language(Say.Language.RU_RU)
                  .build())
            .build();

    servletResponse.setContentType("text/xml");
    try {
        servletResponse.getWriter().write(response.toXml());
    } catch (TwiMLException e) {
        throw new RuntimeException(e);
    }
}

However, when I call my number, I hear silence. The console's call log shows question marks instead of Cyrillic characters.

enter image description here

I would appreciate help in solving this problem.

like image 582
Nikolay Mamaev Avatar asked Mar 26 '26 14:03

Nikolay Mamaev


1 Answers

It appears, you "just" had to:

servletResponse.setCharacterEncoding("UTF-8");

..or:

servletResponse.setContentType("text/xml; charset=UTF-8");

...since the default is assumed as ISO-8859-1. (And I am not deep into TwiML or IVR, but this seems to break/fix things (Cyrillic characters) on a basic level.)

refs:

  • Change encoding of HttpServletResponse
  • https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html
  • https://javaee.github.io/servlet-spec/
  • http://www.grauw.nl/blog/entry/489
  • https://www.fileformat.info/info/unicode/char/search.htm
  • https://www.twilio.com/docs/voice/twiml/say
  • https://www.twilio.com/docs/voice/twiml/gather
  • UTF8 or UTF-8? :)
  • What's the difference between text/xml vs application/xml for webservice response
like image 181
xerx593 Avatar answered Mar 28 '26 04:03

xerx593



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!