text to speach :
Code:
package cycbrr;
public class TTSJutsu {
public String speak(String strIn) {
// in case else (phrase not found)
String[] words = strIn.split("\\s+");
for (String string : words) {
// case word exists : *to fun
switch (string) {
case "hi":
// code block
System.out.println(string);
break;
default:
// case it is actually a number
if (isNumeric(string)) {
// replace with counter super fun here
System.out.println(string);
}
// case it is actually a Time
else if (isTime(string)) {
System.out.println(string);
String[] time = string.split(":");
int hour = Integer.parseInt(time[0].trim());
int min = Integer.parseInt(time[1].trim());
String hourStr = hour + "";
String minStr = min + "";
if (hour < 10) {
hourStr = "0" + hour;
}
if (min < 10) {
minStr = "0" + min;
}
String result = hourStr + ":" + minStr;
System.out.println(result);
}
}
}
return "";
}
public static boolean isNumeric(String str) {
return str.matches("-?\\d+(\\.\\d+)?"); // match a number with optional '-' and decimal.
}
public static boolean isTime(String str) {
return str.matches("(?:[01]\\d|2[0123]):(?:[012345]\\d)"); // match a number with optional '-' and decimal.
}
}
:coolpepe: :cop2: :cop3: