我已经下载了IVR for beginners tutorial并对其进行了一些修改,以提供俄语语音响应(java文件的编码为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);
}
}
但是,当我拨打电话时,我会听到沉默.控制台的呼叫日志显示问号而不是西里尔字符.
希望能为您解决这个问题提供帮助.
最佳答案
看来,您“只是”必须:
servletResponse.setCharacterEncoding("UTF-8");
..要么:
servletResponse.setContentType("text/xml; charset=UTF-8");
…因为默认值假定为ISO-8859-1. (而且我对TwiML或IVR并不深入,但这似乎可以从根本上打破/固定东西(西里尔字母).)
参考:
> 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?