我希望Google文字转语音引擎能够说出这样的句子:
今天是7月25日。
但是使用当前版本3.3.13.1635260.arm和更新的语言包,输出如下:
今天是7月25日。
Time time = new Time(Time.getCurrentTimezone());
time.setToNow();
today = time.monthDay;
String output = "Today is the "+ today + ". of July.";
speech.speak(output, TextToSpeech.QUEUE_FLUSH, null);
我用今天的int和String值尝试了它,结果相同。
答案 0 :(得分:1)
static String[] suffixes =
// 0 1 2 3 4 5 6 7 8 9
{ "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th",
// 10 11 12 13 14 15 16 17 18 19
"th", "th", "th", "th", "th", "th", "th", "th", "th", "th",
// 20 21 22 23 24 25 26 27 28 29
"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th",
// 30 31
"th", "st" };
Date date = new Date();
SimpleDateFormat formatDayOfMonth = new SimpleDateFormat("d");
int day = Integer.parseInt(formatDateOfMonth.format(date));
String dayStr = day + suffixes[day];
然后:
String output = "Today is the "+ dayStr + ". of July.";
speech.speak(output, TextToSpeech.QUEUE_FLUSH, null);
答案 1 :(得分:0)
这可能是因为它完全按照你传递的字符串来解释字符串。例如,"今天是7月25日。"
这样的事情可以帮助https://stackoverflow.com/a/4011232/3724365。
// http://code.google.com/p/guava-libraries
import static com.google.common.base.Preconditions.*;
String getDayOfMonthSuffix(final int n) {
checkArgument(n >= 1 && n <= 31, "illegal day of month: " + n);
if (n >= 11 && n <= 13) {
return "th";
}
switch (n % 10) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
default: return "th";
}
}
所以你得到
String daySuffix = getDayOfMonthSuffix(today);
String ordinalToday = today + daySuffix;
String output = "Today is the "+ ordinalToday + ". of July.";
speech.speak(output, TextToSpeech.QUEUE_FLUSH, null);