开发者

Format a date for use with text-to-speech in Java

I have a Date which I'd like to format into text that is usable by a text-to-speech engine. I am currently doing it by hand using various SimpleDateFormats.

Examples of what s开发者_如何转开发hould result from formatting:

  • January 25, two thousand one at 6 pm
  • January 25, two thousand at 7 oh 5pm
  • January 25, two thousand eleven at 7 52 pm

Any thoughts? Thanks.


If you are willing to lose precision, there are examples of code that reports the time as "quarter to one" or "five past ten", but the examples I can find all do what you are already doing and use if/then/else to check for all the special cases.

Take a look at http://sourceforge.net/projects/fuzzytime/ for a Python script that does this, or search for "fuzzy time" to get several other examples.

Otherwise, I think you are already on the right track as long as you catch all the edge cases.


What you need is to turn numbers into words. You're halfway there just go here and see if this procedure can help. Once you got yourself turning numbers into words then it will be easy to integrate with the TTS. JAVA: Number to Word


Given limited time and/or budget, I'd probably use SimpleDateFormat to create elements separated by delimiters, then write my own function to convert that to readable text.

So I'd first convert to:
January|25|2001|6|00|PM
January|25|2000|7|05|PM
January|25|2011|7|52|PM

then parse the result into a custom format (based on how I want to hear the date/time sounded), then do the text-to-speech. The number of edge cases seems low to me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜