From 2fb50af83bceff7e8672c2178e16dc35d7f00920 Mon Sep 17 00:00:00 2001 From: N3ther Date: Fri, 1 Jul 2022 14:58:01 -0400 Subject: [PATCH] added support for prediacritics --- .../java/net/oijon/algonquin/tts/IPA.java | 64 +++++++++++++------ .../java/net/oijon/algonquin/tts/TRM.java | 14 ++++ 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/oijon/algonquin/tts/IPA.java b/src/main/java/net/oijon/algonquin/tts/IPA.java index dfe6678..ba37f49 100644 --- a/src/main/java/net/oijon/algonquin/tts/IPA.java +++ b/src/main/java/net/oijon/algonquin/tts/IPA.java @@ -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. @@ -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++; } } @@ -127,6 +153,8 @@ public static String createAudio(String[] fileNames) { return exception; } + + public static void recordAudio(Clip clip, File file) { } diff --git a/src/main/java/net/oijon/algonquin/tts/TRM.java b/src/main/java/net/oijon/algonquin/tts/TRM.java index b97f7af..1f13e9a 100644 --- a/src/main/java/net/oijon/algonquin/tts/TRM.java +++ b/src/main/java/net/oijon/algonquin/tts/TRM.java @@ -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; + } + }