Skip to content

Commit

Permalink
added support for prediacritics
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdcramer committed Jul 1, 2022
1 parent 8346a87 commit 2fb50af
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
64 changes: 46 additions & 18 deletions src/main/java/net/oijon/algonquin/tts/IPA.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ public static String[] getFileNames(String input) {

//g and ɡ are the same sound, however two different points in unicode. as such, they need to both be in there to prevent disappearing chars
char[] ipaList = {'p', 'b', 't', 'd', 'ʈ', 'ɖ', 'c', 'ɟ', 'k', 'g', 'ɡ', 'q', 'ɢ', 'ʔ', 'm', 'ɱ', 'n', 'ɳ', 'ɲ', 'ŋ', 'ɴ', 'ʙ', 'r', 'ʀ', 'ⱱ', 'ɾ', 'ɽ', 'ɸ', 'β', 'f', 'v', 'θ', 'ð', 's', 'z', 'ʃ', 'ʒ', 'ʂ', 'ʐ', 'ç', 'ʝ', 'x', 'ɣ', 'χ', 'ʁ', 'ħ', 'ʕ', 'h', 'ɦ', 'ɬ', 'ɮ', 'ʋ', 'ɹ', 'ɻ', 'j', 'ɰ', 'l', 'ɭ', 'ʎ', 'ʟ', 'ʍ', 'w', 'ɥ', 'ʜ', 'ʢ', 'ʡ', 'ɕ', 'ʑ', 'ɺ', 'ɧ', 'i', 'y', 'ɨ', 'ʉ', 'ɯ', 'u', 'ɪ', 'ʏ', 'ʊ', 'e', 'ø', 'ɘ', 'ɵ', 'ɤ', 'o', 'ə', 'ɛ', 'œ', 'ɜ', 'ɞ', 'ʌ', 'ɔ', 'æ', 'ɐ', 'a', 'ɶ', 'ɑ', 'ɒ'};
//char[] preDiacriticList = {'ᵐ', 'ⁿ', 'ᶯ', 'ᶮ', 'ᵑ'};
char[] preDiacriticList = {'ᵐ', 'ⁿ', 'ᶯ', 'ᶮ', 'ᵑ'};
char[] postDiacriticList = {'̥', '̊', '̬', 'ʰ', '̹', '̜', '̟', '̠', '̈', '̽', '̩', '̯', '˞', '̤', '̰', '̼', 'ʷ', 'ʲ', 'ˠ', 'ˤ', '̴', '̝', '̞', '̘', '̙', '̪', '̺', '̻','̃', 'ˡ', '̚', '-'};
String[] fileNames = new String[input.length()];


int inputLength = input.length();
int currentFileName = 0;

for (int i = 0; i < inputLength; i++) {
char c = input.charAt(i);
//boolean isPreDiacritic = false;
boolean isPreDiacritic = false;
boolean isPostDiacritic = false;

//handles spaces.
Expand All @@ -38,41 +39,66 @@ public static String[] getFileNames(String input) {
fileNames[currentFileName] = "space";
currentFileName++;
}
/*
for (int l = 0; l < preDiacriticList.length; l++) {
if (c == preDiacriticList[l]) {
isPreDiacritic = true;
if (currentFileName != fileNames.length) {
currentFileName++;
fileNames[currentFileName] += "" + c;



for (int j = 0; j < postDiacriticList.length; j++) {
if (c == postDiacriticList[j]) {
isPostDiacritic = true;
//shouldnt actually be a problem, but just in case...]
if (currentFileName != 0) {
//if diacritic, add to file name of previous char.
currentFileName--;
fileNames[currentFileName] += Character.toString(c);
currentFileName++;
} else {
System.err.println("Postdiacritic \'" + c + "\' attempted to be added to non-existant character! Skipping...");
}
} else {
System.err.println("Prediacritic attempted to be added to non-existant character! Skipping...");
}

}
}
*/
for (int j = 0; j < postDiacriticList.length; j++) {

for (int j = 0; j < preDiacriticList.length; j++) {
if (c == postDiacriticList[j]) {
isPostDiacritic = true;
//shouldnt actually be a problem, but just in case...]
if (currentFileName != 0) {
//if diacritic, add to file name of previous char.
currentFileName--;
fileNames[currentFileName] += "" + c;
fileNames[currentFileName] += Character.toString(c);
currentFileName++;
} else {
System.err.println("Postdiacritic attempted to be added to non-existant character! Skipping...");
System.err.println("Postdiacritic \'" + c + "\' attempted to be added to non-existant character! Skipping...");
}

}
}

for (int l = 0; l < preDiacriticList.length; l++) {
if (c == preDiacriticList[l]) {
System.out.println(preDiacriticList[l]);
isPreDiacritic = true;
if (currentFileName != fileNames.length) {
//if prediacritic, add to file name of next char.
fileNames[currentFileName] = Character.toString(c);
} else {
System.err.println("Prediacritic \'" + c + "\' attempted to be added to non-existant character! Skipping...");
}
}
}

//skips if the character was a diacritic, should speed things up...
if (isPostDiacritic != true) {
if (isPostDiacritic == false && isPreDiacritic == false) {
for (int k = 0; k < ipaList.length; k++) {
if (c == ipaList[k]) {
//sets file name to character and goes to the next file name
fileNames[currentFileName] = Character.toString(c);
//checks if null because if not, prediacritics would be overwritten.
if (fileNames[currentFileName] == null) {
fileNames[currentFileName] = Character.toString(c);
} else {
fileNames[currentFileName] += Character.toString(c);
}

currentFileName++;
}
}
Expand Down Expand Up @@ -127,6 +153,8 @@ public static String createAudio(String[] fileNames) {
return exception;
}



public static void recordAudio(Clip clip, File file) {

}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/oijon/algonquin/tts/TRM.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,18 @@ public static String createAudio(String input) {
return exception;
}

public static String createSchwaTubeTest() {
String exception = "";

int sampleRate = 2018; // L = c/F, where L is the length (17cm), c is the speed of sound (cm/s), and F is the sampling frequency
float delayLine[][] = new float[sampleRate][2];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < sampleRate; j++) {
delayLine[j][i] = (delayLine[j-1][i]);
}
}

return exception;
}

}

0 comments on commit 2fb50af

Please sign in to comment.