设置日期格式以便与 Java 中的文本转语音一起使用
我有一个Date
,我想将其格式化为可由文本转语音引擎使用的文本。我目前正在使用各种 SimpleDateFormat
手动完成此操作。
格式化结果的示例:
- 1 月 25 日,2001
- 于 1 月 25 日下午 6 点,2000 于
- 1 月 25 日下午 7 点 5 点,2001 于 7 点 52 点
有什么想法吗?谢谢。
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 SimpleDateFormat
s.
Examples of what should 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您愿意失去精度,有一些代码示例将时间报告为“四分之一到一”或“十分之五”,但我能找到的所有示例都执行您已经在做的操作并使用 if/then/else检查所有特殊情况。
查看 http://sourceforge.net/projects/fuzzytime/ 的 Python 脚本这个,或者搜索“模糊时间”来获取其他几个例子。
否则,我认为只要你抓住了所有的边缘情况,你就已经走在正确的轨道上了。
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.
你需要的是将数字转化为文字。您已经完成了一半,只需转到此处,看看此过程是否有帮助。一旦您将数字转化为文字,那么与 TTS 集成就会很容易。 JAVA:数字到单词
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
鉴于时间和/或预算有限,我可能会使用
SimpleDateFormat
创建由分隔符分隔的元素,然后编写自己的函数将其转换为可读文本。所以我首先转换为:
一月|25|2001|6|00|下午
一月|25|2000|7|05|下午
January|25|2011|7|52|PM
然后将结果解析为自定义格式(基于我想要听到的日期/时间的发音),然后进行文本转语音。对我来说,边缘情况的数量似乎很少。
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.