Skip to content

Instantly share code, notes, and snippets.

@barkinet
Forked from jexp/MgEspeak.java
Created April 1, 2017 00:55
Show Gist options
  • Select an option

  • Save barkinet/831e8854474d2fcf916b1629ec84cdb3 to your computer and use it in GitHub Desktop.

Select an option

Save barkinet/831e8854474d2fcf916b1629ec84cdb3 to your computer and use it in GitHub Desktop.
MUD MorgenGrauen Konverter für Umlaute und Reformat auf breitere Spalten für ESpeak -> http://mg.mud.de
import java.util.*;
import java.io.*;
public class MgEspeak {
private static String[] umlaute = {"Ae", "Ä", "AE", "Ä", "ae", "ä", "Oe", "Ö", "OE", "Ö", "oe", "ö", "UE", "Ü", "Ue", "Ü", "ue", "ü" };
public static void main(String[] args) throws Exception {
int spalten = args.length > 0 ? Integer.parseInt(args[0]) : 130;
Set<String> ausnahmen = new HashSet(Arrays.asList("feuer","mauer"));
File f = new File("ausnahmen.txt");
if (f.exists()) try (Scanner s = new Scanner(f)) { while(s.hasNext()) { ausnahmen.add(s.next().toLowerCase());}};
Scanner eingabe = new Scanner(System.in);
int aktuell = 0;
while (eingabe.hasNextLine()) {
String zeile = eingabe.nextLine();
if (zeile == null || zeile.trim().isEmpty()) { System.out.println(); continue; }
String[] woerter = zeile.split("((?<=\\W+)|(?=\\W+))");
int laenge = zeile.length();
for (int w=0;w<woerter.length;w+=2) {
String wort = woerter[w];
if (!ausnahmen.contains(wort.toLowerCase())) {
for (int i=0;i<umlaute.length;i+=2) wort = wort.replaceAll(umlaute[i],umlaute[i+1]);
woerter[w] = wort;
}
}
for(String wort : woerter) {
if (aktuell + wort.length() > spalten) { aktuell=0;System.out.println(); }
System.out.print(wort); aktuell += wort.length();
}
if (woerter.length < 6 || laenge < 60 || woerter[0].charAt(0)=='[' || woerter[woerter.length-1].matches("[.!?]")) { aktuell=0;System.out.println(); }
else { System.out.print(" "); aktuell++;}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment