From 7c6ec7933d6e5122450da804162b2e9ee426e5d9 Mon Sep 17 00:00:00 2001 From: Ingmar Steiner Date: Fri, 19 Dec 2014 13:10:47 +0100 Subject: [PATCH] format java code in marytts-lang-en incantation: $ mvn com.googlecode.maven-java-formatter-plugin:maven-java-formatter-plugin:format -pl marytts-languages/marytts-lang-en --- .../marytts/language/en/EnglishConfig.java | 1 - .../language/en/FreeTTSContourGenerator.java | 64 +- .../marytts/language/en/FreeTTSIntonator.java | 67 +- .../en/FreeTTSPartOfSpeechTagger.java | 150 ++- .../language/en/FreeTTSPauseGenerator.java | 61 +- .../marytts/language/en/FreeTTSPhraser.java | 64 +- .../language/en/FreeTTSTextToTokens.java | 126 +-- .../language/en/FreeTTSTokenToWords.java | 69 +- .../java/marytts/language/en/JTokeniser.java | 117 ++- .../marytts/language/en/NumberExpander.java | 915 ++++++++---------- .../java/marytts/language/en/Prosody.java | 19 +- .../java/marytts/language/en/Segmenter.java | 187 ++-- .../language/en/Utt2XMLDurationsEn.java | 22 +- .../language/en/Utt2XMLIntonationEn.java | 22 +- .../marytts/language/en/Utt2XMLPausesEn.java | 22 +- .../marytts/language/en/Utt2XMLPhrasesEn.java | 22 +- .../marytts/language/en/Utt2XMLPosEn.java | 21 +- .../language/en/Utt2XMLPostprocessedEn.java | 22 +- .../language/en/Utt2XMLSegmentsEn.java | 21 +- .../marytts/language/en/Utt2XMLTokensEn.java | 22 +- .../marytts/language/en/Utt2XMLWordsEn.java | 21 +- .../marytts/language/en/WordRelation.java | 126 ++- .../language/en/XML2UttDurationsEn.java | 39 +- .../language/en/XML2UttIntonationEn.java | 39 +- .../marytts/language/en/XML2UttPausesEn.java | 39 +- .../marytts/language/en/XML2UttPhrasesEn.java | 39 +- .../marytts/language/en/XML2UttPosEn.java | 39 +- .../language/en/XML2UttPostprocessedEn.java | 39 +- .../language/en/XML2UttSegmentsEn.java | 39 +- .../marytts/language/en/XML2UttTokensEn.java | 39 +- .../marytts/language/en/XML2UttWordsEn.java | 39 +- .../language/en/prosody/SentenceType.java | 105 +- .../en_US/datatypes/USEnglishDataTypes.java | 42 +- 33 files changed, 1134 insertions(+), 1525 deletions(-) diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/EnglishConfig.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/EnglishConfig.java index d7845441..04ccfa5f 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/EnglishConfig.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/EnglishConfig.java @@ -22,7 +22,6 @@ package marytts.language.en; import marytts.config.LanguageConfig; import marytts.exceptions.MaryConfigurationException; - public class EnglishConfig extends LanguageConfig { public EnglishConfig() throws MaryConfigurationException { super(EnglishConfig.class.getResourceAsStream("en.config")); diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSContourGenerator.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSContourGenerator.java index 779b9eb0..6f599c53 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSContourGenerator.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSContourGenerator.java @@ -32,54 +32,38 @@ import com.sun.speech.freetts.Utterance; import com.sun.speech.freetts.UtteranceProcessor; import com.sun.speech.freetts.en.ContourGenerator; - - /** * Use an individual FreeTTS module for English synthesis. - * + * * @author Marc Schröder */ -public class FreeTTSContourGenerator extends InternalModule -{ - private UtteranceProcessor processor; +public class FreeTTSContourGenerator extends InternalModule { + private UtteranceProcessor processor; - public FreeTTSContourGenerator() - { - super("ContourGenerator", - USEnglishDataTypes.FREETTS_DURATIONS, - USEnglishDataTypes.FREETTS_CONTOUR, - Locale.ENGLISH - ); - } - - public void startup() throws Exception - { - super.startup(); - - // Initialise FreeTTS - FreeTTSVoices.load(); - processor = new ContourGenerator - (com.sun.speech.freetts.en.us.CMUVoice.class. - getResource("f0_lr_terms.txt"), 170.0f, 34.0f); - } - - public MaryData process(MaryData d) - throws Exception - { - List utterances = d.getUtterances(); - Iterator it = utterances.iterator(); - while (it.hasNext()) { - Utterance utterance = (Utterance) it.next(); - processor.processUtterance(utterance); - } - MaryData output = new MaryData(outputType(), d.getLocale()); - output.setUtterances(utterances); - return output; - } + public FreeTTSContourGenerator() { + super("ContourGenerator", USEnglishDataTypes.FREETTS_DURATIONS, USEnglishDataTypes.FREETTS_CONTOUR, Locale.ENGLISH); + } + public void startup() throws Exception { + super.startup(); + // Initialise FreeTTS + FreeTTSVoices.load(); + processor = new ContourGenerator(com.sun.speech.freetts.en.us.CMUVoice.class.getResource("f0_lr_terms.txt"), 170.0f, + 34.0f); + } + public MaryData process(MaryData d) throws Exception { + List utterances = d.getUtterances(); + Iterator it = utterances.iterator(); + while (it.hasNext()) { + Utterance utterance = (Utterance) it.next(); + processor.processUtterance(utterance); + } + MaryData output = new MaryData(outputType(), d.getLocale()); + output.setUtterances(utterances); + return output; + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSIntonator.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSIntonator.java index dba3ede2..e559a60c 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSIntonator.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSIntonator.java @@ -33,56 +33,39 @@ import com.sun.speech.freetts.UtteranceProcessor; import com.sun.speech.freetts.cart.CARTImpl; import com.sun.speech.freetts.cart.Intonator; - - /** * Use an individual FreeTTS module for English synthesis. - * + * * @author Marc Schröder */ -public class FreeTTSIntonator extends InternalModule -{ - private UtteranceProcessor processor; +public class FreeTTSIntonator extends InternalModule { + private UtteranceProcessor processor; - public FreeTTSIntonator() - { - super("Intonator", - USEnglishDataTypes.FREETTS_PAUSES, - USEnglishDataTypes.FREETTS_INTONATION, - Locale.ENGLISH - ); - } - - public void startup() throws Exception - { - super.startup(); - - // Initialise FreeTTS - FreeTTSVoices.load(); - CARTImpl accentCart = new CARTImpl( - com.sun.speech.freetts.en.us.CMUVoice.class.getResource("int_accent_cart.txt")); - CARTImpl toneCart = new CARTImpl( - com.sun.speech.freetts.en.us.CMUVoice.class.getResource("int_tone_cart.txt")); - processor = new Intonator(accentCart, toneCart); - } - - public MaryData process(MaryData d) - throws Exception - { - List utterances = d.getUtterances(); - Iterator it = utterances.iterator(); - while (it.hasNext()) { - Utterance utterance = (Utterance) it.next(); - processor.processUtterance(utterance); - } - MaryData output = new MaryData(outputType(), d.getLocale()); - output.setUtterances(utterances); - return output; - } + public FreeTTSIntonator() { + super("Intonator", USEnglishDataTypes.FREETTS_PAUSES, USEnglishDataTypes.FREETTS_INTONATION, Locale.ENGLISH); + } + public void startup() throws Exception { + super.startup(); + // Initialise FreeTTS + FreeTTSVoices.load(); + CARTImpl accentCart = new CARTImpl(com.sun.speech.freetts.en.us.CMUVoice.class.getResource("int_accent_cart.txt")); + CARTImpl toneCart = new CARTImpl(com.sun.speech.freetts.en.us.CMUVoice.class.getResource("int_tone_cart.txt")); + processor = new Intonator(accentCart, toneCart); + } + public MaryData process(MaryData d) throws Exception { + List utterances = d.getUtterances(); + Iterator it = utterances.iterator(); + while (it.hasNext()) { + Utterance utterance = (Utterance) it.next(); + processor.processUtterance(utterance); + } + MaryData output = new MaryData(outputType(), d.getLocale()); + output.setUtterances(utterances); + return output; + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPartOfSpeechTagger.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPartOfSpeechTagger.java index 33344156..7f5b60b6 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPartOfSpeechTagger.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPartOfSpeechTagger.java @@ -42,99 +42,81 @@ import com.sun.speech.freetts.Item; import com.sun.speech.freetts.Relation; import com.sun.speech.freetts.Utterance; - - /** * Use an individual FreeTTS module for English synthesis. - * + * * @author Marc Schröder */ -public class FreeTTSPartOfSpeechTagger extends InternalModule -{ - //private UtteranceProcessor processor; - private Logger logger; - - private Map posMap; - - - public FreeTTSPartOfSpeechTagger() - { - super("PartOfSpeechTagger", - USEnglishDataTypes.FREETTS_WORDS, - USEnglishDataTypes.FREETTS_POS, - Locale.ENGLISH - ); - - } +public class FreeTTSPartOfSpeechTagger extends InternalModule { + // private UtteranceProcessor processor; + private Logger logger; - public void startup() throws Exception - { - super.startup(); - this.logger = MaryUtils.getLogger("FreeTTSPOSTagger"); - buildPosMap(); - // Initialise FreeTTS - FreeTTSVoices.load(); - //processor = new PartOfSpeechTagger(); - } + private Map posMap; - public MaryData process(MaryData d) - throws Exception - { - List utterances = d.getUtterances(); - Iterator it = utterances.iterator(); - while (it.hasNext()) { - Utterance utterance = (Utterance) it.next(); - //processor.processUtterance(utterance); - processUtterance(utterance); - } - MaryData output = new MaryData(outputType(), d.getLocale()); - output.setUtterances(utterances); - return output; - } + public FreeTTSPartOfSpeechTagger() { + super("PartOfSpeechTagger", USEnglishDataTypes.FREETTS_WORDS, USEnglishDataTypes.FREETTS_POS, Locale.ENGLISH); - private void buildPosMap(){ - posMap = new HashMap(); - try{ - String posFile = - MaryProperties.getFilename("english.freetts.posfile"); - BufferedReader reader = - new BufferedReader(new FileReader(new File (posFile))); - String line = reader.readLine(); - while (line!=null){ - if(!(line.startsWith("***"))){ - //System.out.println(line); - StringTokenizer st = - new StringTokenizer(line," "); - String word = st.nextToken(); - String pos = st.nextToken(); - posMap.put(word,pos);} - line = reader.readLine(); - } - }catch(Exception e){ - e.printStackTrace(); - throw new Error("Unable to build PoS-Map"); - } - } + } - private void processUtterance(Utterance utt){ - logger.debug("Tagging part of speech..."); - for(Item word = utt.getRelation(Relation.WORD).getHead(); - word != null; word = word.getNext()){ - String pos = null; - if (posMap.containsKey(word.toString())){ - pos = (String) posMap.get(word.toString()); - logger.debug("Assigning pos \""+pos+"\" to word \"" - +word.toString()+"\""); - } - else {pos = "content";} - word.getFeatures().setString("pos",pos); - - } - - } + public void startup() throws Exception { + super.startup(); + this.logger = MaryUtils.getLogger("FreeTTSPOSTagger"); + buildPosMap(); + // Initialise FreeTTS + FreeTTSVoices.load(); + // processor = new PartOfSpeechTagger(); + } - + public MaryData process(MaryData d) throws Exception { + List utterances = d.getUtterances(); + Iterator it = utterances.iterator(); + while (it.hasNext()) { + Utterance utterance = (Utterance) it.next(); + // processor.processUtterance(utterance); + processUtterance(utterance); + } + MaryData output = new MaryData(outputType(), d.getLocale()); + output.setUtterances(utterances); + return output; + } + + private void buildPosMap() { + posMap = new HashMap(); + try { + String posFile = MaryProperties.getFilename("english.freetts.posfile"); + BufferedReader reader = new BufferedReader(new FileReader(new File(posFile))); + String line = reader.readLine(); + while (line != null) { + if (!(line.startsWith("***"))) { + // System.out.println(line); + StringTokenizer st = new StringTokenizer(line, " "); + String word = st.nextToken(); + String pos = st.nextToken(); + posMap.put(word, pos); + } + line = reader.readLine(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Error("Unable to build PoS-Map"); + } + } + + private void processUtterance(Utterance utt) { + logger.debug("Tagging part of speech..."); + for (Item word = utt.getRelation(Relation.WORD).getHead(); word != null; word = word.getNext()) { + String pos = null; + if (posMap.containsKey(word.toString())) { + pos = (String) posMap.get(word.toString()); + logger.debug("Assigning pos \"" + pos + "\" to word \"" + word.toString() + "\""); + } else { + pos = "content"; + } + word.getFeatures().setString("pos", pos); + + } + + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPauseGenerator.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPauseGenerator.java index e483baa1..c94cc596 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPauseGenerator.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPauseGenerator.java @@ -32,52 +32,37 @@ import com.sun.speech.freetts.Utterance; import com.sun.speech.freetts.UtteranceProcessor; import com.sun.speech.freetts.en.PauseGenerator; - - /** * Use an individual FreeTTS module for English synthesis. - * + * * @author Marc Schröder */ -public class FreeTTSPauseGenerator extends InternalModule -{ - private UtteranceProcessor processor; +public class FreeTTSPauseGenerator extends InternalModule { + private UtteranceProcessor processor; - public FreeTTSPauseGenerator() - { - super("PauseGenerator", - USEnglishDataTypes.FREETTS_SEGMENTS, - USEnglishDataTypes.FREETTS_PAUSES, - Locale.ENGLISH - ); - } - - public void startup() throws Exception - { - super.startup(); - - // Initialise FreeTTS - FreeTTSVoices.load(); - processor = new PauseGenerator(); - } - - public MaryData process(MaryData d) - throws Exception - { - List utterances = d.getUtterances(); - Iterator it = utterances.iterator(); - while (it.hasNext()) { - Utterance utterance = (Utterance) it.next(); - processor.processUtterance(utterance); - } - MaryData output = new MaryData(outputType(), d.getLocale()); - output.setUtterances(utterances); - return output; - } + public FreeTTSPauseGenerator() { + super("PauseGenerator", USEnglishDataTypes.FREETTS_SEGMENTS, USEnglishDataTypes.FREETTS_PAUSES, Locale.ENGLISH); + } + public void startup() throws Exception { + super.startup(); + // Initialise FreeTTS + FreeTTSVoices.load(); + processor = new PauseGenerator(); + } + public MaryData process(MaryData d) throws Exception { + List utterances = d.getUtterances(); + Iterator it = utterances.iterator(); + while (it.hasNext()) { + Utterance utterance = (Utterance) it.next(); + processor.processUtterance(utterance); + } + MaryData output = new MaryData(outputType(), d.getLocale()); + output.setUtterances(utterances); + return output; + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPhraser.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPhraser.java index 0e6aa421..99c51028 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPhraser.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSPhraser.java @@ -33,54 +33,38 @@ import com.sun.speech.freetts.UtteranceProcessor; import com.sun.speech.freetts.cart.CARTImpl; import com.sun.speech.freetts.cart.Phraser; - - /** * Use an individual FreeTTS module for English synthesis. - * + * * @author Marc Schröder */ -public class FreeTTSPhraser extends InternalModule -{ - private UtteranceProcessor processor; +public class FreeTTSPhraser extends InternalModule { + private UtteranceProcessor processor; - public FreeTTSPhraser() - { - super("Phraser", - USEnglishDataTypes.FREETTS_POS, - USEnglishDataTypes.FREETTS_PHRASES, - Locale.ENGLISH - ); - } - - public void startup() throws Exception - { - super.startup(); - - // Initialise FreeTTS - FreeTTSVoices.load(); - CARTImpl phrasingCart = new CARTImpl( - com.sun.speech.freetts.en.us.CMUVoice.class.getResource("phrasing_cart.txt")); - processor = new Phraser(phrasingCart); - } - - public MaryData process(MaryData d) - throws Exception - { - List utterances = d.getUtterances(); - Iterator it = utterances.iterator(); - while (it.hasNext()) { - Utterance utterance = (Utterance) it.next(); - processor.processUtterance(utterance); - } - MaryData output = new MaryData(outputType(), d.getLocale()); - output.setUtterances(utterances); - return output; - } + public FreeTTSPhraser() { + super("Phraser", USEnglishDataTypes.FREETTS_POS, USEnglishDataTypes.FREETTS_PHRASES, Locale.ENGLISH); + } + public void startup() throws Exception { + super.startup(); + // Initialise FreeTTS + FreeTTSVoices.load(); + CARTImpl phrasingCart = new CARTImpl(com.sun.speech.freetts.en.us.CMUVoice.class.getResource("phrasing_cart.txt")); + processor = new Phraser(phrasingCart); + } + public MaryData process(MaryData d) throws Exception { + List utterances = d.getUtterances(); + Iterator it = utterances.iterator(); + while (it.hasNext()) { + Utterance utterance = (Utterance) it.next(); + processor.processUtterance(utterance); + } + MaryData output = new MaryData(outputType(), d.getLocale()); + output.setUtterances(utterances); + return output; + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSTextToTokens.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSTextToTokens.java index 84c2e292..cfb9a652 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSTextToTokens.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSTextToTokens.java @@ -44,87 +44,67 @@ import com.sun.speech.freetts.Tokenizer; import com.sun.speech.freetts.Utterance; import com.sun.speech.freetts.en.us.USEnglish; - - /** * Use an individual FreeTTS module for English synthesis. - * + * * @author Marc Schröder */ -public class FreeTTSTextToTokens extends InternalModule -{ - public FreeTTSTextToTokens() - { - super("TextToTokens", - MaryDataType.TEXT, - USEnglishDataTypes.FREETTS_TOKENS, - Locale.ENGLISH - ); - } +public class FreeTTSTextToTokens extends InternalModule { + public FreeTTSTextToTokens() { + super("TextToTokens", MaryDataType.TEXT, USEnglishDataTypes.FREETTS_TOKENS, Locale.ENGLISH); + } - public void startup() throws Exception - { - super.startup(); - - // Initialise FreeTTS - FreeTTSVoices.load(); - } - - public MaryData process(MaryData d) - throws Exception - { - String text = d.getPlainText(); - // create a basic utterance from text - Tokenizer tokenizer = new com.sun.speech.freetts.en.TokenizerImpl(); - tokenizer.setWhitespaceSymbols(USEnglish.WHITESPACE_SYMBOLS); - tokenizer.setSingleCharSymbols(USEnglish.SINGLE_CHAR_SYMBOLS); - tokenizer.setPrepunctuationSymbols(USEnglish.PREPUNCTUATION_SYMBOLS); - tokenizer.setPostpunctuationSymbols(USEnglish.PUNCTUATION_SYMBOLS); - tokenizer.setInputText(text); - ArrayList utteranceList = new ArrayList(); - Token savedToken = null; - boolean first = true; - while (tokenizer.hasMoreTokens()) { - // Fill a new Utterance: - ArrayList tokenList = new ArrayList(); - Utterance utterance = null; - if (savedToken != null) { - tokenList.add(savedToken); - savedToken = null; - } - while (tokenizer.hasMoreTokens()) { - Token token = tokenizer.getNextToken(); - if ((token.getWord().length() == 0) || - (tokenList.size() > 500) || - tokenizer.isBreak()) { - savedToken = token; - break; - } - tokenList.add(token); - } - marytts.modules.synthesis.Voice maryVoice = - d.getDefaultVoice(); - if (maryVoice == null || - !maryVoice.getLocale().equals(Locale.US)) { - maryVoice = marytts.modules.synthesis.Voice. - getDefaultVoice(Locale.US); - } - - utterance = new Utterance - (FreeTTSVoices.getFreeTTSVoice(maryVoice), tokenList); - //utterance.setSpeakable(speakable); - utterance.setFirst(first); - first = false; - utterance.setLast(!tokenizer.hasMoreTokens()); - utteranceList.add(utterance); - } - MaryData output = new MaryData(outputType(), d.getLocale()); - output.setUtterances(utteranceList); - return output; - } + public void startup() throws Exception { + super.startup(); + // Initialise FreeTTS + FreeTTSVoices.load(); + } + public MaryData process(MaryData d) throws Exception { + String text = d.getPlainText(); + // create a basic utterance from text + Tokenizer tokenizer = new com.sun.speech.freetts.en.TokenizerImpl(); + tokenizer.setWhitespaceSymbols(USEnglish.WHITESPACE_SYMBOLS); + tokenizer.setSingleCharSymbols(USEnglish.SINGLE_CHAR_SYMBOLS); + tokenizer.setPrepunctuationSymbols(USEnglish.PREPUNCTUATION_SYMBOLS); + tokenizer.setPostpunctuationSymbols(USEnglish.PUNCTUATION_SYMBOLS); + tokenizer.setInputText(text); + ArrayList utteranceList = new ArrayList(); + Token savedToken = null; + boolean first = true; + while (tokenizer.hasMoreTokens()) { + // Fill a new Utterance: + ArrayList tokenList = new ArrayList(); + Utterance utterance = null; + if (savedToken != null) { + tokenList.add(savedToken); + savedToken = null; + } + while (tokenizer.hasMoreTokens()) { + Token token = tokenizer.getNextToken(); + if ((token.getWord().length() == 0) || (tokenList.size() > 500) || tokenizer.isBreak()) { + savedToken = token; + break; + } + tokenList.add(token); + } + marytts.modules.synthesis.Voice maryVoice = d.getDefaultVoice(); + if (maryVoice == null || !maryVoice.getLocale().equals(Locale.US)) { + maryVoice = marytts.modules.synthesis.Voice.getDefaultVoice(Locale.US); + } + utterance = new Utterance(FreeTTSVoices.getFreeTTSVoice(maryVoice), tokenList); + // utterance.setSpeakable(speakable); + utterance.setFirst(first); + first = false; + utterance.setLast(!tokenizer.hasMoreTokens()); + utteranceList.add(utterance); + } + MaryData output = new MaryData(outputType(), d.getLocale()); + output.setUtterances(utteranceList); + return output; + } } diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSTokenToWords.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSTokenToWords.java index 87d1a126..4f97e0d1 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSTokenToWords.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/FreeTTSTokenToWords.java @@ -46,57 +46,40 @@ import com.sun.speech.freetts.en.us.PrefixFSM; import com.sun.speech.freetts.en.us.PronounceableFSM; import com.sun.speech.freetts.en.us.SuffixFSM; - - /** * Use an individual FreeTTS module for English synthesis. - * + * * @author Marc Schröder */ -public class FreeTTSTokenToWords extends InternalModule -{ - private UtteranceProcessor processor; +public class FreeTTSTokenToWords extends InternalModule { + private UtteranceProcessor processor; - public FreeTTSTokenToWords() - { - super("TokenToWords", - USEnglishDataTypes.FREETTS_TOKENS, - USEnglishDataTypes.FREETTS_WORDS, - Locale.ENGLISH - ); - } - - public void startup() throws Exception - { - super.startup(); - - // Initialise FreeTTS - FreeTTSVoices.load(); - CARTImpl numbersCart = new CARTImpl - (com.sun.speech.freetts.en.us.CMUVoice.class.getResource("nums_cart.txt")); - PronounceableFSM prefixFSM = new PrefixFSM - (com.sun.speech.freetts.en.us.CMUVoice.class.getResource("prefix_fsm.txt")); - PronounceableFSM suffixFSM = new SuffixFSM - (com.sun.speech.freetts.en.us.CMUVoice.class.getResource("suffix_fsm.txt")); - processor = new TokenToWords(numbersCart, prefixFSM, suffixFSM); - } - - public MaryData process(MaryData d) - throws Exception - { - List utterances = d.getUtterances(); - Iterator it = utterances.iterator(); - while (it.hasNext()) { - Utterance utterance = (Utterance) it.next(); - processor.processUtterance(utterance); - } - MaryData output = new MaryData(outputType(), d.getLocale()); - output.setUtterances(utterances); - return output; - } + public FreeTTSTokenToWords() { + super("TokenToWords", USEnglishDataTypes.FREETTS_TOKENS, USEnglishDataTypes.FREETTS_WORDS, Locale.ENGLISH); + } + public void startup() throws Exception { + super.startup(); + // Initialise FreeTTS + FreeTTSVoices.load(); + CARTImpl numbersCart = new CARTImpl(com.sun.speech.freetts.en.us.CMUVoice.class.getResource("nums_cart.txt")); + PronounceableFSM prefixFSM = new PrefixFSM(com.sun.speech.freetts.en.us.CMUVoice.class.getResource("prefix_fsm.txt")); + PronounceableFSM suffixFSM = new SuffixFSM(com.sun.speech.freetts.en.us.CMUVoice.class.getResource("suffix_fsm.txt")); + processor = new TokenToWords(numbersCart, prefixFSM, suffixFSM); + } + public MaryData process(MaryData d) throws Exception { + List utterances = d.getUtterances(); + Iterator it = utterances.iterator(); + while (it.hasNext()) { + Utterance utterance = (Utterance) it.next(); + processor.processUtterance(utterance); + } + MaryData output = new MaryData(outputType(), d.getLocale()); + output.setUtterances(utterances); + return output; + } } diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/JTokeniser.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/JTokeniser.java index 025bf612..788bbdd3 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/JTokeniser.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/JTokeniser.java @@ -34,75 +34,68 @@ import org.w3c.dom.traversal.DocumentTraversal; import org.w3c.dom.traversal.NodeFilter; import org.w3c.dom.traversal.NodeIterator; - /** - * + * * @author Marc Schröder */ public class JTokeniser extends marytts.modules.JTokeniser { - /** + /** * */ - public JTokeniser() { - super(MaryDataType.RAWMARYXML, - MaryDataType.TOKENS, - Locale.ENGLISH); - } + public JTokeniser() { + super(MaryDataType.RAWMARYXML, MaryDataType.TOKENS, Locale.ENGLISH); + } - public MaryData process(MaryData d) throws Exception - { - MaryData result = super.process(d); - normaliseToAscii(result); - propagateForceAccent(result); - return result; - } - - protected void normaliseToAscii(MaryData d) - { - Document doc = d.getDocument(); - NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(doc, - NodeFilter.SHOW_ELEMENT, new NameNodeFilter(MaryXML.TOKEN), false); - Element t = null; - while ((t = (Element) ni.nextNode()) != null) { - String s = MaryDomUtils.tokenText(t); - String normalised = MaryUtils.normaliseUnicodeLetters(s, Locale.ENGLISH); - if (!s.equals(normalised)) { - MaryDomUtils.setTokenText(t, normalised); - } - } - } + public MaryData process(MaryData d) throws Exception { + MaryData result = super.process(d); + normaliseToAscii(result); + propagateForceAccent(result); + return result; + } - /** - * In current FreeTTS code, prosody elements get lost. So remember - * at least the force-accent element on individual tokens: - * @param d - */ - protected void propagateForceAccent(MaryData d) - { - Document doc = d.getDocument(); - NodeIterator prosodyNI = ((DocumentTraversal)doc).createNodeIterator(doc, - NodeFilter.SHOW_ELEMENT, new NameNodeFilter(MaryXML.PROSODY), false); - Element prosody = null; - while ((prosody = (Element) prosodyNI.nextNode()) != null) { - if (prosody.hasAttribute("force-accent")) { - String forceAccent = prosody.getAttribute("force-accent"); - String accent = null; - if (forceAccent.equals("none")) { - accent = "none"; - } else { - accent = "unknown"; - } - NodeIterator tNI = ((DocumentTraversal)doc).createNodeIterator(prosody, - NodeFilter.SHOW_ELEMENT, new NameNodeFilter(MaryXML.TOKEN), false); - Element t = null; - while ((t = (Element) tNI.nextNode()) != null) { - if (!t.hasAttribute("accent")) { - t.setAttribute("accent", accent); - } - } // while t - } - } // while prosody - } + protected void normaliseToAscii(MaryData d) { + Document doc = d.getDocument(); + NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter( + MaryXML.TOKEN), false); + Element t = null; + while ((t = (Element) ni.nextNode()) != null) { + String s = MaryDomUtils.tokenText(t); + String normalised = MaryUtils.normaliseUnicodeLetters(s, Locale.ENGLISH); + if (!s.equals(normalised)) { + MaryDomUtils.setTokenText(t, normalised); + } + } + } + + /** + * In current FreeTTS code, prosody elements get lost. So remember at least the force-accent element on individual tokens: + * + * @param d + */ + protected void propagateForceAccent(MaryData d) { + Document doc = d.getDocument(); + NodeIterator prosodyNI = ((DocumentTraversal) doc).createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter( + MaryXML.PROSODY), false); + Element prosody = null; + while ((prosody = (Element) prosodyNI.nextNode()) != null) { + if (prosody.hasAttribute("force-accent")) { + String forceAccent = prosody.getAttribute("force-accent"); + String accent = null; + if (forceAccent.equals("none")) { + accent = "none"; + } else { + accent = "unknown"; + } + NodeIterator tNI = ((DocumentTraversal) doc).createNodeIterator(prosody, NodeFilter.SHOW_ELEMENT, + new NameNodeFilter(MaryXML.TOKEN), false); + Element t = null; + while ((t = (Element) tNI.nextNode()) != null) { + if (!t.hasAttribute("accent")) { + t.setAttribute("accent", accent); + } + } // while t + } + } // while prosody + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/NumberExpander.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/NumberExpander.java index 56ceedbb..6df95858 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/NumberExpander.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/NumberExpander.java @@ -15,514 +15,445 @@ import com.sun.speech.freetts.Item; import com.sun.speech.freetts.util.Utilities; /** - * Expands Strings containing digits characters into - * a list of words representing those digits. - * - * It translates the following code from flite: - * lang/usEnglish/us_expand.c + * Expands Strings containing digits characters into a list of words representing those digits. + * + * It translates the following code from flite: lang/usEnglish/us_expand.c */ public class NumberExpander { - - private static final String[] digit2num = { - "zero", - "one", - "two", - "three", - "four", - "five", - "six", - "seven", - "eight", - "nine" }; - - private static final String[] digit2teen = { - "ten", /* shouldn't get called */ - "eleven", - "twelve", - "thirteen", - "fourteen", - "fifteen", - "sixteen", - "seventeen", - "eighteen", - "nineteen" }; - - private static final String[] digit2enty = { - "zero", /* shouldn't get called */ - "ten", - "twenty", - "thirty", - "forty", - "fifty", - "sixty", - "seventy", - "eighty", - "ninety" }; - - private static final String[] ord2num = { - "zeroth", - "first", - "second", - "third", - "fourth", - "fifth", - "sixth", - "seventh", - "eighth", - "ninth" }; - - private static final String[] ord2teen = { - "tenth", /* shouldn't get called */ - "eleventh", - "twelfth", - "thirteenth", - "fourteenth", - "fifteenth", - "sixteenth", - "seventeenth", - "eighteenth", - "nineteenth" }; - - private static final String[] ord2enty = { - "zeroth", /* shouldn't get called */ - "tenth", - "twentieth", - "thirtieth", - "fortieth", - "fiftieth", - "sixtieth", - "seventieth", - "eightieth", - "ninetieth" }; + private static final String[] digit2num = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; - /** - * Unconstructable - */ - private NumberExpander() { - } + private static final String[] digit2teen = { "ten", /* shouldn't get called */ + "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; + private static final String[] digit2enty = { "zero", /* shouldn't get called */ + "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; - /** - * Expands a digit string into a list of English words of those digits. - * For example, "1234" expands to "one two three four" - * - * @param numberString the digit string to expand. - * @param wordRelation words are added to this Relation - */ - public static void expandNumber(String numberString, - WordRelation wordRelation, Item tokenItem) { - int numDigits = numberString.length(); - - if (numDigits == 0) { - // wordRelation = null; - } else if (numDigits == 1) { - expandDigits(numberString, wordRelation, tokenItem); - } else if (numDigits == 2) { - expand2DigitNumber(numberString, wordRelation, tokenItem); - } else if (numDigits == 3) { - expand3DigitNumber(numberString, wordRelation, tokenItem); - } else if (numDigits < 7) { - expandBelow7DigitNumber(numberString, wordRelation, tokenItem); - } else if (numDigits < 10) { - expandBelow10DigitNumber(numberString, wordRelation, tokenItem); - } else if (numDigits < 13) { - expandBelow13DigitNumber(numberString, wordRelation, tokenItem); - } else { - expandDigits(numberString, wordRelation, tokenItem); + private static final String[] ord2num = { "zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", + "eighth", "ninth" }; + + private static final String[] ord2teen = { "tenth", /* shouldn't get called */ + "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth" }; + + private static final String[] ord2enty = { "zeroth", /* shouldn't get called */ + "tenth", "twentieth", "thirtieth", "fortieth", "fiftieth", "sixtieth", "seventieth", "eightieth", "ninetieth" }; + + /** + * Unconstructable + */ + private NumberExpander() { } - } + /** + * Expands a digit string into a list of English words of those digits. For example, "1234" expands to "one two three four" + * + * @param numberString + * the digit string to expand. + * @param wordRelation + * words are added to this Relation + */ + public static void expandNumber(String numberString, WordRelation wordRelation, Item tokenItem) { + int numDigits = numberString.length(); - /** - * Expands a two-digit string into a list of English words. - * - * @param numberString the string which is the number to expand - * @param wordRelation words are added to this Relation - */ - private static void expand2DigitNumber(String numberString, - WordRelation wordRelation, Item tokenItem) { - if (numberString.charAt(0) == '0') { - // numberString is "0X" - if (numberString.charAt(1) == '0') { - // numberString is "00", do nothing - } else { - // numberString is "01", "02" ... - String number = digit2num[numberString.charAt(1)-'0']; - wordRelation.addWord(tokenItem,number); - } - } else if (numberString.charAt(1) == '0') { - // numberString is "10", "20", ... - String number = digit2enty[numberString.charAt(0)-'0']; - wordRelation.addWord(tokenItem,number); - } else if (numberString.charAt(0) == '1') { - // numberString is "11", "12", ..., "19" - String number = digit2teen[numberString.charAt(1)-'0']; - wordRelation.addWord(tokenItem,number); - } else { - // numberString is "2X", "3X", ... - String enty = digit2enty[numberString.charAt(0)-'0']; - wordRelation.addWord(tokenItem,enty); - expandDigits(numberString.substring(1,numberString.length()), - wordRelation, tokenItem); - } - } - - - /** - * Expands a three-digit string into a list of English words. - * - * @param numberString the string which is the number to expand - * @param wordRelation words are added to this Relation - */ - private static void expand3DigitNumber(String numberString, - WordRelation wordRelation,Item tokenItem) { - if (numberString.charAt(0) == '0') { - expandNumberAt(numberString, 1, wordRelation, tokenItem); - } else { - String hundredDigit = digit2num[numberString.charAt(0)-'0']; - wordRelation.addWord(tokenItem,hundredDigit); - wordRelation.addWord(tokenItem,"hundred"); - expandNumberAt(numberString, 1, wordRelation, tokenItem); - } - } - - - /** - * Expands a string that is a 4 to 6 digits number into a list - * of English words. For example, "333000" into "three hundred - * and thirty-three thousand". - * - * @param numberString the string which is the number to expand - * @param wordRelation words are added to this Relation - */ - private static void expandBelow7DigitNumber(String numberString, - WordRelation wordRelation,Item tokenItem) { - expandLargeNumber(numberString, "thousand", 3, wordRelation, tokenItem); - } - - - /** - * Expands a string that is a 7 to 9 digits number into a list - * of English words. For example, "19000000" into nineteen million. - * - * @param numberString the string which is the number to expand - * @param wordRelation words are added to this Relation - */ - private static void expandBelow10DigitNumber(String numberString, - WordRelation wordRelation,Item tokenItem) { - expandLargeNumber(numberString, "million", 6, wordRelation, tokenItem); - } - - - /** - * Expands a string that is a 10 to 12 digits number into a list - * of English words. For example, "27000000000" into twenty-seven - * billion. - * - * @param numberString the string which is the number to expand - * @param wordRelation words are added to this Relation - */ - private static void expandBelow13DigitNumber(String numberString, - WordRelation wordRelation,Item tokenItem) { - expandLargeNumber(numberString, "billion", 9, wordRelation, tokenItem); - } - - - /** - * Expands a string that is a number longer than 3 digits into a list - * of English words. For example, "1000" into one thousand. - * - * @param numberString the string which is the number to expand - * @param order either "thousand", "million", or "billion" - * @param numberZeroes the number of zeroes, depending on the order, so - * its either 3, 6, or 9 - * @param wordRelation words are added to this Relation - */ - private static void expandLargeNumber(String numberString, - String order, - int numberZeroes, - WordRelation wordRelation,Item tokenItem) { - int numberDigits = numberString.length(); - - // parse out the prefix, e.g., "113" in "113,000" - int i = numberDigits - numberZeroes; - String part = numberString.substring(0, i); - - // get how many thousands/millions/billions - Item oldTail = wordRelation.getTail(); - - expandNumber(part, wordRelation, tokenItem); - - if (wordRelation.getTail() == oldTail) { - expandNumberAt(numberString, i, wordRelation,tokenItem); - } else { - wordRelation.addWord(tokenItem,order); - expandNumberAt(numberString, i, wordRelation,tokenItem); - } - } - - - /** - * Returns the number string list of the given string starting at - * the given index. E.g., expandNumberAt("1100", 1) gives "one hundred" - * - * @param numberString the string which is the number to expand - * @param startIndex the starting position - * @param wordRelation words are added to this Relation - */ - private static void expandNumberAt(String numberString, - int startIndex, - WordRelation wordRelation,Item tokenItem) { - expandNumber(numberString.substring(startIndex,numberString.length()), - wordRelation,tokenItem); - } - - - /** - * Expands given token to list of words pronouncing it as digits - * - * @param numberString the string which is the number to expand - * @param wordRelation words are added to this Relation - */ - public static void expandDigits(String numberString, - WordRelation wordRelation,Item tokenItem) { - int numberDigits = numberString.length(); - for (int i = 0; i < numberDigits; i++) { - char digit = numberString.charAt(i); - if (isDigit(digit)) { - wordRelation.addWord(tokenItem,digit2num[numberString.charAt(i)-'0']); - } else { - wordRelation.addWord(tokenItem,"umpty"); - } - } - } - - - /** - * Expands the digit string of an ordinal number. - * - * @param rawNumberString the string which is the number to expand - * @param wordRelation words are added to this Relation - */ - public static void expandOrdinal(String rawNumberString, - WordRelation wordRelation,Item tokenItem) { - // remove all ','s from the raw number string - String numberString = Utilities.deleteChar(rawNumberString, ','); - - expandNumber(numberString, wordRelation,tokenItem); - - // get the last in the list of number strings - Item lastItem = wordRelation.getTail(); - - if (lastItem != null) { - - FeatureSet featureSet = lastItem.getFeatures(); - String lastNumber = featureSet.getString("name"); - String ordinal = findMatchInArray(lastNumber, digit2num, ord2num); - - if (ordinal == null) { - ordinal = findMatchInArray(lastNumber, digit2teen, ord2teen); - } - if (ordinal == null) { - ordinal = findMatchInArray(lastNumber, digit2enty, ord2enty); - } - - if (lastNumber.equals("hundred")) { - ordinal = "hundredth"; - } else if (lastNumber.equals("thousand")) { - ordinal = "thousandth"; - } else if (lastNumber.equals("billion")) { - ordinal = "billionth"; - } - - // if there was an ordinal, set the last element of the list - // to that ordinal; otherwise, don't do anything - if (ordinal != null) { - wordRelation.setLastWord(ordinal); - } - } - } - - - /** - * Finds a match of the given string in the given array, - * and returns the element at the same index in the returnInArray - * - * @param strToMatch the string to match - * @param matchInArray the source array - * @param returnInArray the return array - * - * @return an element in returnInArray, or null - * if a match is not found - */ - private static String findMatchInArray(String strToMatch, - String[] matchInArray, - String[] returnInArray) { - for (int i = 0; i < matchInArray.length; i++) { - if (strToMatch.equals(matchInArray[i])) { - if (i < returnInArray.length) { - return returnInArray[i]; + if (numDigits == 0) { + // wordRelation = null; + } else if (numDigits == 1) { + expandDigits(numberString, wordRelation, tokenItem); + } else if (numDigits == 2) { + expand2DigitNumber(numberString, wordRelation, tokenItem); + } else if (numDigits == 3) { + expand3DigitNumber(numberString, wordRelation, tokenItem); + } else if (numDigits < 7) { + expandBelow7DigitNumber(numberString, wordRelation, tokenItem); + } else if (numDigits < 10) { + expandBelow10DigitNumber(numberString, wordRelation, tokenItem); + } else if (numDigits < 13) { + expandBelow13DigitNumber(numberString, wordRelation, tokenItem); } else { - return null; + expandDigits(numberString, wordRelation, tokenItem); } - } } - return null; - } - - /** - * Expands the given number string as pairs as in years or IDs - * - * @param numberString the string which is the number to expand - * @param wordRelation words are added to this Relation - */ - public static void expandID(String numberString, WordRelation wordRelation, Item tokenItem) { - - int numberDigits = numberString.length(); - - if ((numberDigits == 4) && - (numberString.charAt(2) == '0') && - (numberString.charAt(3) == '0')) { - if (numberString.charAt(1) == '0') { // e.g. 2000, 3000 - expandNumber(numberString, wordRelation,tokenItem); - } else { - expandNumber(numberString.substring(0,2), wordRelation,tokenItem); - wordRelation.addWord(tokenItem,"hundred"); - } - } else if ((numberDigits == 2) && (numberString.charAt(0) == '0')) { - wordRelation.addWord(tokenItem,"oh"); - expandDigits(numberString.substring(1,2), wordRelation,tokenItem); - } else if ((numberDigits == 4 && - numberString.charAt(1) == '0') || - numberDigits < 3) { - expandNumber(numberString, wordRelation,tokenItem); - } else if (numberDigits % 2 == 1) { - String firstDigit = digit2num[numberString.charAt(0)-'0']; - wordRelation.addWord(tokenItem,firstDigit); - expandID(numberString.substring(1,numberDigits), wordRelation,tokenItem); - } else { - expandNumber(numberString.substring(0,2), wordRelation,tokenItem); - expandID(numberString.substring(2,numberDigits), wordRelation,tokenItem); - } - } - - - /** - * Expands the given number string as a real number. - * - * @param numberString the string which is the real number to expand - * @param wordRelation words are added to this Relation - */ - public static void expandReal(String numberString, WordRelation wordRelation,Item tokenItem) { - - int stringLength = numberString.length(); - int position; - - if (numberString.charAt(0) == '-') { - // negative real numbers - wordRelation.addWord(tokenItem,"minus"); - expandReal(numberString.substring(1, stringLength), wordRelation,tokenItem); - } else if (numberString.charAt(0) == '+') { - // prefixed with a '+' - wordRelation.addWord(tokenItem,"plus"); - expandReal(numberString.substring(1, stringLength), wordRelation,tokenItem); - } else if ((position = numberString.indexOf('e')) != -1 || - (position = numberString.indexOf('E')) != -1) { - // numbers with 'E' or 'e' - expandReal(numberString.substring(0, position), wordRelation,tokenItem); - wordRelation.addWord(tokenItem,"e"); - expandReal(numberString.substring(position + 1), wordRelation,tokenItem); - } else if ((position = numberString.indexOf('.')) != -1) { - // numbers with '.' - String beforeDot = numberString.substring(0, position); - if (beforeDot.length() > 0) { - expandReal(beforeDot, wordRelation,tokenItem); - } - wordRelation.addWord(tokenItem,"point"); - String afterDot = numberString.substring(position + 1); - if (afterDot.length() > 0) { - expandDigits(afterDot, wordRelation,tokenItem); - } - } else { - // everything else - expandNumber(numberString, wordRelation,tokenItem); - } - } - - - /** - * Expands the given string of letters as a list of single char symbols. - * - * @param letters the string of letters to expand - * @param wordRelation words are added to this Relation - */ - public static void expandLetters(String letters, - WordRelation wordRelation,Item tokenItem) { - letters = letters.toLowerCase(); - char c; - - for (int i = 0; i < letters.length(); i++) { - // if this is a number - c = letters.charAt(i); - - if (isDigit(c)) { - wordRelation.addWord(tokenItem,digit2num[c-'0']); - } else if (letters.equals("a")) { - wordRelation.addWord(tokenItem,"_a"); - } else { - wordRelation.addWord(tokenItem,String.valueOf(c)); - } - } - } - - - /** - * Returns the integer value of the given string of Roman numerals. - * - * @param roman the string of Roman numbers - * - * @return the integer value - */ - public static int expandRoman(String roman) { - int value = 0; - - for (int p = 0; p < roman.length(); p++) { - char c = roman.charAt(p); - if (c == 'X') { - value += 10; - } else if (c == 'V') { - value += 5; - } else if (c == 'I') { - if (p+1 < roman.length()) { - char p1 = roman.charAt(p+1); - if (p1 == 'V') { - value += 4; - p++; - } else if (p1 == 'X') { - value += 9; - p++; - } else { - value += 1; - } + /** + * Expands a two-digit string into a list of English words. + * + * @param numberString + * the string which is the number to expand + * @param wordRelation + * words are added to this Relation + */ + private static void expand2DigitNumber(String numberString, WordRelation wordRelation, Item tokenItem) { + if (numberString.charAt(0) == '0') { + // numberString is "0X" + if (numberString.charAt(1) == '0') { + // numberString is "00", do nothing + } else { + // numberString is "01", "02" ... + String number = digit2num[numberString.charAt(1) - '0']; + wordRelation.addWord(tokenItem, number); + } + } else if (numberString.charAt(1) == '0') { + // numberString is "10", "20", ... + String number = digit2enty[numberString.charAt(0) - '0']; + wordRelation.addWord(tokenItem, number); + } else if (numberString.charAt(0) == '1') { + // numberString is "11", "12", ..., "19" + String number = digit2teen[numberString.charAt(1) - '0']; + wordRelation.addWord(tokenItem, number); } else { - value += 1; + // numberString is "2X", "3X", ... + String enty = digit2enty[numberString.charAt(0) - '0']; + wordRelation.addWord(tokenItem, enty); + expandDigits(numberString.substring(1, numberString.length()), wordRelation, tokenItem); } - } } - return value; - } + /** + * Expands a three-digit string into a list of English words. + * + * @param numberString + * the string which is the number to expand + * @param wordRelation + * words are added to this Relation + */ + private static void expand3DigitNumber(String numberString, WordRelation wordRelation, Item tokenItem) { + if (numberString.charAt(0) == '0') { + expandNumberAt(numberString, 1, wordRelation, tokenItem); + } else { + String hundredDigit = digit2num[numberString.charAt(0) - '0']; + wordRelation.addWord(tokenItem, hundredDigit); + wordRelation.addWord(tokenItem, "hundred"); + expandNumberAt(numberString, 1, wordRelation, tokenItem); + } + } - /** - * Returns true if the given character is a digit (0-9 only). - * - * @param ch the character to test - * - * @return true or false - */ - public static boolean isDigit(char ch) { - return ('0' <= ch && ch <= '9'); - } + /** + * Expands a string that is a 4 to 6 digits number into a list of English words. For example, "333000" into "three hundred and + * thirty-three thousand". + * + * @param numberString + * the string which is the number to expand + * @param wordRelation + * words are added to this Relation + */ + private static void expandBelow7DigitNumber(String numberString, WordRelation wordRelation, Item tokenItem) { + expandLargeNumber(numberString, "thousand", 3, wordRelation, tokenItem); + } + + /** + * Expands a string that is a 7 to 9 digits number into a list of English words. For example, "19000000" into nineteen + * million. + * + * @param numberString + * the string which is the number to expand + * @param wordRelation + * words are added to this Relation + */ + private static void expandBelow10DigitNumber(String numberString, WordRelation wordRelation, Item tokenItem) { + expandLargeNumber(numberString, "million", 6, wordRelation, tokenItem); + } + + /** + * Expands a string that is a 10 to 12 digits number into a list of English words. For example, "27000000000" into + * twenty-seven billion. + * + * @param numberString + * the string which is the number to expand + * @param wordRelation + * words are added to this Relation + */ + private static void expandBelow13DigitNumber(String numberString, WordRelation wordRelation, Item tokenItem) { + expandLargeNumber(numberString, "billion", 9, wordRelation, tokenItem); + } + + /** + * Expands a string that is a number longer than 3 digits into a list of English words. For example, "1000" into one thousand. + * + * @param numberString + * the string which is the number to expand + * @param order + * either "thousand", "million", or "billion" + * @param numberZeroes + * the number of zeroes, depending on the order, so its either 3, 6, or 9 + * @param wordRelation + * words are added to this Relation + */ + private static void expandLargeNumber(String numberString, String order, int numberZeroes, WordRelation wordRelation, + Item tokenItem) { + int numberDigits = numberString.length(); + + // parse out the prefix, e.g., "113" in "113,000" + int i = numberDigits - numberZeroes; + String part = numberString.substring(0, i); + + // get how many thousands/millions/billions + Item oldTail = wordRelation.getTail(); + + expandNumber(part, wordRelation, tokenItem); + + if (wordRelation.getTail() == oldTail) { + expandNumberAt(numberString, i, wordRelation, tokenItem); + } else { + wordRelation.addWord(tokenItem, order); + expandNumberAt(numberString, i, wordRelation, tokenItem); + } + } + + /** + * Returns the number string list of the given string starting at the given index. E.g., expandNumberAt("1100", 1) gives + * "one hundred" + * + * @param numberString + * the string which is the number to expand + * @param startIndex + * the starting position + * @param wordRelation + * words are added to this Relation + */ + private static void expandNumberAt(String numberString, int startIndex, WordRelation wordRelation, Item tokenItem) { + expandNumber(numberString.substring(startIndex, numberString.length()), wordRelation, tokenItem); + } + + /** + * Expands given token to list of words pronouncing it as digits + * + * @param numberString + * the string which is the number to expand + * @param wordRelation + * words are added to this Relation + */ + public static void expandDigits(String numberString, WordRelation wordRelation, Item tokenItem) { + int numberDigits = numberString.length(); + for (int i = 0; i < numberDigits; i++) { + char digit = numberString.charAt(i); + if (isDigit(digit)) { + wordRelation.addWord(tokenItem, digit2num[numberString.charAt(i) - '0']); + } else { + wordRelation.addWord(tokenItem, "umpty"); + } + } + } + + /** + * Expands the digit string of an ordinal number. + * + * @param rawNumberString + * the string which is the number to expand + * @param wordRelation + * words are added to this Relation + */ + public static void expandOrdinal(String rawNumberString, WordRelation wordRelation, Item tokenItem) { + // remove all ','s from the raw number string + String numberString = Utilities.deleteChar(rawNumberString, ','); + + expandNumber(numberString, wordRelation, tokenItem); + + // get the last in the list of number strings + Item lastItem = wordRelation.getTail(); + + if (lastItem != null) { + + FeatureSet featureSet = lastItem.getFeatures(); + String lastNumber = featureSet.getString("name"); + String ordinal = findMatchInArray(lastNumber, digit2num, ord2num); + + if (ordinal == null) { + ordinal = findMatchInArray(lastNumber, digit2teen, ord2teen); + } + if (ordinal == null) { + ordinal = findMatchInArray(lastNumber, digit2enty, ord2enty); + } + + if (lastNumber.equals("hundred")) { + ordinal = "hundredth"; + } else if (lastNumber.equals("thousand")) { + ordinal = "thousandth"; + } else if (lastNumber.equals("billion")) { + ordinal = "billionth"; + } + + // if there was an ordinal, set the last element of the list + // to that ordinal; otherwise, don't do anything + if (ordinal != null) { + wordRelation.setLastWord(ordinal); + } + } + } + + /** + * Finds a match of the given string in the given array, and returns the element at the same index in the returnInArray + * + * @param strToMatch + * the string to match + * @param matchInArray + * the source array + * @param returnInArray + * the return array + * + * @return an element in returnInArray, or null if a match is not found + */ + private static String findMatchInArray(String strToMatch, String[] matchInArray, String[] returnInArray) { + for (int i = 0; i < matchInArray.length; i++) { + if (strToMatch.equals(matchInArray[i])) { + if (i < returnInArray.length) { + return returnInArray[i]; + } else { + return null; + } + } + } + return null; + } + + /** + * Expands the given number string as pairs as in years or IDs + * + * @param numberString + * the string which is the number to expand + * @param wordRelation + * words are added to this Relation + */ + public static void expandID(String numberString, WordRelation wordRelation, Item tokenItem) { + + int numberDigits = numberString.length(); + + if ((numberDigits == 4) && (numberString.charAt(2) == '0') && (numberString.charAt(3) == '0')) { + if (numberString.charAt(1) == '0') { // e.g. 2000, 3000 + expandNumber(numberString, wordRelation, tokenItem); + } else { + expandNumber(numberString.substring(0, 2), wordRelation, tokenItem); + wordRelation.addWord(tokenItem, "hundred"); + } + } else if ((numberDigits == 2) && (numberString.charAt(0) == '0')) { + wordRelation.addWord(tokenItem, "oh"); + expandDigits(numberString.substring(1, 2), wordRelation, tokenItem); + } else if ((numberDigits == 4 && numberString.charAt(1) == '0') || numberDigits < 3) { + expandNumber(numberString, wordRelation, tokenItem); + } else if (numberDigits % 2 == 1) { + String firstDigit = digit2num[numberString.charAt(0) - '0']; + wordRelation.addWord(tokenItem, firstDigit); + expandID(numberString.substring(1, numberDigits), wordRelation, tokenItem); + } else { + expandNumber(numberString.substring(0, 2), wordRelation, tokenItem); + expandID(numberString.substring(2, numberDigits), wordRelation, tokenItem); + } + } + + /** + * Expands the given number string as a real number. + * + * @param numberString + * the string which is the real number to expand + * @param wordRelation + * words are added to this Relation + */ + public static void expandReal(String numberString, WordRelation wordRelation, Item tokenItem) { + + int stringLength = numberString.length(); + int position; + + if (numberString.charAt(0) == '-') { + // negative real numbers + wordRelation.addWord(tokenItem, "minus"); + expandReal(numberString.substring(1, stringLength), wordRelation, tokenItem); + } else if (numberString.charAt(0) == '+') { + // prefixed with a '+' + wordRelation.addWord(tokenItem, "plus"); + expandReal(numberString.substring(1, stringLength), wordRelation, tokenItem); + } else if ((position = numberString.indexOf('e')) != -1 || (position = numberString.indexOf('E')) != -1) { + // numbers with 'E' or 'e' + expandReal(numberString.substring(0, position), wordRelation, tokenItem); + wordRelation.addWord(tokenItem, "e"); + expandReal(numberString.substring(position + 1), wordRelation, tokenItem); + } else if ((position = numberString.indexOf('.')) != -1) { + // numbers with '.' + String beforeDot = numberString.substring(0, position); + if (beforeDot.length() > 0) { + expandReal(beforeDot, wordRelation, tokenItem); + } + wordRelation.addWord(tokenItem, "point"); + String afterDot = numberString.substring(position + 1); + if (afterDot.length() > 0) { + expandDigits(afterDot, wordRelation, tokenItem); + } + } else { + // everything else + expandNumber(numberString, wordRelation, tokenItem); + } + } + + /** + * Expands the given string of letters as a list of single char symbols. + * + * @param letters + * the string of letters to expand + * @param wordRelation + * words are added to this Relation + */ + public static void expandLetters(String letters, WordRelation wordRelation, Item tokenItem) { + letters = letters.toLowerCase(); + char c; + + for (int i = 0; i < letters.length(); i++) { + // if this is a number + c = letters.charAt(i); + + if (isDigit(c)) { + wordRelation.addWord(tokenItem, digit2num[c - '0']); + } else if (letters.equals("a")) { + wordRelation.addWord(tokenItem, "_a"); + } else { + wordRelation.addWord(tokenItem, String.valueOf(c)); + } + } + } + + /** + * Returns the integer value of the given string of Roman numerals. + * + * @param roman + * the string of Roman numbers + * + * @return the integer value + */ + public static int expandRoman(String roman) { + int value = 0; + + for (int p = 0; p < roman.length(); p++) { + char c = roman.charAt(p); + if (c == 'X') { + value += 10; + } else if (c == 'V') { + value += 5; + } else if (c == 'I') { + if (p + 1 < roman.length()) { + char p1 = roman.charAt(p + 1); + if (p1 == 'V') { + value += 4; + p++; + } else if (p1 == 'X') { + value += 9; + p++; + } else { + value += 1; + } + } else { + value += 1; + } + } + } + return value; + } + + /** + * Returns true if the given character is a digit (0-9 only). + * + * @param ch + * the character to test + * + * @return true or false + */ + public static boolean isDigit(char ch) { + return ('0' <= ch && ch <= '9'); + } } diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Prosody.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Prosody.java index 3b176901..41b55022 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Prosody.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Prosody.java @@ -25,16 +25,11 @@ import marytts.datatypes.MaryDataType; import marytts.modules.ProsodyGeneric; import marytts.server.MaryProperties; -public class Prosody extends ProsodyGeneric -{ - public Prosody() - { - super(MaryDataType.PHONEMES, - MaryDataType.INTONATION, - Locale.ENGLISH, - MaryProperties.localePrefix(Locale.ENGLISH)+".prosody.tobipredparams", - MaryProperties.localePrefix(Locale.ENGLISH)+".prosody.accentPriorities", - MaryProperties.localePrefix(Locale.ENGLISH)+".prosody.syllableaccents", - MaryProperties.localePrefix(Locale.ENGLISH)+".prosody.paragraphdeclination"); - } +public class Prosody extends ProsodyGeneric { + public Prosody() { + super(MaryDataType.PHONEMES, MaryDataType.INTONATION, Locale.ENGLISH, MaryProperties.localePrefix(Locale.ENGLISH) + + ".prosody.tobipredparams", MaryProperties.localePrefix(Locale.ENGLISH) + ".prosody.accentPriorities", + MaryProperties.localePrefix(Locale.ENGLISH) + ".prosody.syllableaccents", MaryProperties + .localePrefix(Locale.ENGLISH) + ".prosody.paragraphdeclination"); + } } diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Segmenter.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Segmenter.java index e49e7ce6..fe071557 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Segmenter.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Segmenter.java @@ -31,40 +31,35 @@ import com.sun.speech.freetts.Utterance; import com.sun.speech.freetts.UtteranceProcessor; import com.sun.speech.freetts.lexicon.Lexicon; - /** - * Annotates an utterance with Relation.SYLLABLE, - * Relation.SYLLABLE_STRUCTURE, and - * Relation.SEGMENT. - * To determine stress, the isStressed method relies upon - * a phone ending in the number "1". Subclasses should override - * isStressed and deStress if stresses are - * determined in other ways. - * + * Annotates an utterance with Relation.SYLLABLE, Relation.SYLLABLE_STRUCTURE, and + * Relation.SEGMENT. To determine stress, the isStressed method relies upon a phone ending in the number + * "1". Subclasses should override isStressed and deStress if stresses are determined in other ways. + * * @see Relation#SEGMENT * @see Relation#SYLLABLE * @see Relation#SYLLABLE_STRUCTURE */ public class Segmenter implements UtteranceProcessor { - private final static String STRESS = "1"; - private final static String NO_STRESS = "0"; - private Map addenda; + private final static String STRESS = "1"; + private final static String NO_STRESS = "0"; + private Map addenda; - /** - * Annotates an utterance with Relation.SYLLABLE, - * Relation.SYLLABLE_STRUCTURE, and - * Relation.SEGMENT. - * - * @param utterance the utterance to process/tokenize - * - * @see Relation#SEGMENT - * @see Relation#SYLLABLE - * @see Relation#SYLLABLE_STRUCTURE - * - * @throws ProcessException if an IOException is thrown during the - * processing of the utterance - */ - public void processUtterance(Utterance utterance) throws ProcessException { + /** + * Annotates an utterance with Relation.SYLLABLE, Relation.SYLLABLE_STRUCTURE, and + * Relation.SEGMENT. + * + * @param utterance + * the utterance to process/tokenize + * + * @see Relation#SEGMENT + * @see Relation#SYLLABLE + * @see Relation#SYLLABLE_STRUCTURE + * + * @throws ProcessException + * if an IOException is thrown during the processing of the utterance + */ + public void processUtterance(Utterance utterance) throws ProcessException { // preconditions if (utterance.getRelation(Relation.WORD) == null) { @@ -183,80 +178,70 @@ public class Segmenter implements UtteranceProcessor { assert utterance.getRelation(Relation.SEGMENT) != null; } - /** - * Determines if the given phonene is stressed. - * To determine stress, this method relies upon - * a phone ending in the number "1". Subclasses should override this - * method if stresses are determined in other ways. - * - * @param phone the phone to check - * - * @return true if the phone is stressed, otherwise false - */ - protected boolean isStressed(String phone) { - return phone.endsWith("1"); - } - - /** - * Converts stressed phone to regular phone. This method - * merely removes the last character of the phone. Subclasses - * should override this if another method is to be used. - * - * @param phone the phone to convert - * - * @return de-stressed phone - */ - protected String deStress(String phone) { - String retPhone = phone; - if (isStressed(phone)) { - retPhone = phone.substring(0, phone.length() - 1); + /** + * Determines if the given phonene is stressed. To determine stress, this method relies upon a phone ending in the number "1". + * Subclasses should override this method if stresses are determined in other ways. + * + * @param phone + * the phone to check + * + * @return true if the phone is stressed, otherwise false + */ + protected boolean isStressed(String phone) { + return phone.endsWith("1"); } - return retPhone; - } - - - - - - public void saveAddenda() throws IOException{ - String path = MaryProperties.maryBase()+"/log/addenda.log"; - if (addenda != null && path != null){ - try{ - String line; - StringBuilder addendaBuf = new StringBuilder(); - addendaBuf.append("# Logfile contains words that are not in the lexicon" - +"\n# and their transcriptions predicted by the LTS-rules" - +"\n# (for English)\n"); - //add new entries - Set words = addenda.keySet(); - for (Iterator it = words.iterator();it.hasNext();){ - String nextWord = (String) it.next(); - addendaBuf.append(nextWord+" " - +addenda.get(nextWord)+"\n"); - } - - //open addenda file - PrintWriter addendaOut = new PrintWriter( - new FileOutputStream(new File(path))); - //print addendaBuf and close - addendaOut.print(addendaBuf.toString()); - addendaOut.flush(); - addendaOut.close(); - } catch (Exception e){ - throw new IOException("Could not save addenda because : " - +e.getMessage()); - } - - } - } - /** - * Returns the simple name of this class. - * - * @return the simple name of this class - */ - public String toString() { - return "Segmenter"; - } + /** + * Converts stressed phone to regular phone. This method merely removes the last character of the phone. Subclasses should + * override this if another method is to be used. + * + * @param phone + * the phone to convert + * + * @return de-stressed phone + */ + protected String deStress(String phone) { + String retPhone = phone; + if (isStressed(phone)) { + retPhone = phone.substring(0, phone.length() - 1); + } + return retPhone; + } + + public void saveAddenda() throws IOException { + String path = MaryProperties.maryBase() + "/log/addenda.log"; + if (addenda != null && path != null) { + try { + String line; + StringBuilder addendaBuf = new StringBuilder(); + addendaBuf.append("# Logfile contains words that are not in the lexicon" + + "\n# and their transcriptions predicted by the LTS-rules" + "\n# (for English)\n"); + // add new entries + Set words = addenda.keySet(); + for (Iterator it = words.iterator(); it.hasNext();) { + String nextWord = (String) it.next(); + addendaBuf.append(nextWord + " " + addenda.get(nextWord) + "\n"); + } + + // open addenda file + PrintWriter addendaOut = new PrintWriter(new FileOutputStream(new File(path))); + // print addendaBuf and close + addendaOut.print(addendaBuf.toString()); + addendaOut.flush(); + addendaOut.close(); + } catch (Exception e) { + throw new IOException("Could not save addenda because : " + e.getMessage()); + } + + } + } + + /** + * Returns the simple name of this class. + * + * @return the simple name of this class + */ + public String toString() { + return "Segmenter"; + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLDurationsEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLDurationsEn.java index 32d52d6b..1e7c4ea4 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLDurationsEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLDurationsEn.java @@ -25,25 +25,15 @@ import marytts.datatypes.MaryDataType; import marytts.language.en_US.datatypes.USEnglishDataTypes; import marytts.modules.Utt2XMLBase; - - /** - * Convert FreeTTS utterances into MaryXML format - * (Durations, English). - * + * Convert FreeTTS utterances into MaryXML format (Durations, English). + * * @author Marc Schröder */ -public class Utt2XMLDurationsEn extends Utt2XMLBase -{ - public Utt2XMLDurationsEn() - { - super("Utt2XML DurationsEn", - USEnglishDataTypes.FREETTS_MBROLISED_DURATIONS, - MaryDataType.DURATIONS, - Locale.ENGLISH); - } - +public class Utt2XMLDurationsEn extends Utt2XMLBase { + public Utt2XMLDurationsEn() { + super("Utt2XML DurationsEn", USEnglishDataTypes.FREETTS_MBROLISED_DURATIONS, MaryDataType.DURATIONS, Locale.ENGLISH); + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLIntonationEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLIntonationEn.java index 91aff5b7..67ac314a 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLIntonationEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLIntonationEn.java @@ -25,25 +25,15 @@ import marytts.datatypes.MaryDataType; import marytts.language.en_US.datatypes.USEnglishDataTypes; import marytts.modules.Utt2XMLBase; - - /** - * Convert FreeTTS utterances into MaryXML format - * (Intonation, English). - * + * Convert FreeTTS utterances into MaryXML format (Intonation, English). + * * @author Marc Schröder */ -public class Utt2XMLIntonationEn extends Utt2XMLBase -{ - public Utt2XMLIntonationEn() - { - super("Utt2XML IntonationEn", - USEnglishDataTypes.FREETTS_INTONATION, - MaryDataType.INTONATION, - Locale.ENGLISH); - } - +public class Utt2XMLIntonationEn extends Utt2XMLBase { + public Utt2XMLIntonationEn() { + super("Utt2XML IntonationEn", USEnglishDataTypes.FREETTS_INTONATION, MaryDataType.INTONATION, Locale.ENGLISH); + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPausesEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPausesEn.java index fe8e8651..0f426dbd 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPausesEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPausesEn.java @@ -24,25 +24,15 @@ import java.util.Locale; import marytts.language.en_US.datatypes.USEnglishDataTypes; import marytts.modules.Utt2XMLBase; - - /** - * Convert FreeTTS utterances into MaryXML format - * (Pauses, English). - * + * Convert FreeTTS utterances into MaryXML format (Pauses, English). + * * @author Marc Schröder */ -public class Utt2XMLPausesEn extends Utt2XMLBase -{ - public Utt2XMLPausesEn() - { - super("Utt2XML PausesEn", - USEnglishDataTypes.FREETTS_PAUSES, - USEnglishDataTypes.PAUSES_US, - Locale.ENGLISH); - } - +public class Utt2XMLPausesEn extends Utt2XMLBase { + public Utt2XMLPausesEn() { + super("Utt2XML PausesEn", USEnglishDataTypes.FREETTS_PAUSES, USEnglishDataTypes.PAUSES_US, Locale.ENGLISH); + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPhrasesEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPhrasesEn.java index 999a6ed0..ba89f869 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPhrasesEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPhrasesEn.java @@ -24,25 +24,15 @@ import java.util.Locale; import marytts.language.en_US.datatypes.USEnglishDataTypes; import marytts.modules.Utt2XMLBase; - - /** - * Convert FreeTTS utterances into MaryXML format - * (Phrases, English). - * + * Convert FreeTTS utterances into MaryXML format (Phrases, English). + * * @author Marc Schröder */ -public class Utt2XMLPhrasesEn extends Utt2XMLBase -{ - public Utt2XMLPhrasesEn() - { - super("Utt2XML PhrasesEn", - USEnglishDataTypes.FREETTS_PHRASES, - USEnglishDataTypes.PHRASES_US, - Locale.ENGLISH); - } - +public class Utt2XMLPhrasesEn extends Utt2XMLBase { + public Utt2XMLPhrasesEn() { + super("Utt2XML PhrasesEn", USEnglishDataTypes.FREETTS_PHRASES, USEnglishDataTypes.PHRASES_US, Locale.ENGLISH); + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPosEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPosEn.java index 2be60862..a2070bd9 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPosEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPosEn.java @@ -25,24 +25,15 @@ import marytts.datatypes.MaryDataType; import marytts.language.en_US.datatypes.USEnglishDataTypes; import marytts.modules.Utt2XMLBase; - - /** - * Convert FreeTTS utterances into MaryXML format - * (parts of speech, English). - * + * Convert FreeTTS utterances into MaryXML format (parts of speech, English). + * * @author Marc Schröder */ -public class Utt2XMLPosEn extends Utt2XMLBase -{ - public Utt2XMLPosEn() - { - super("Utt2XML PosEn", - USEnglishDataTypes.FREETTS_POS, - MaryDataType.PARTSOFSPEECH, - Locale.ENGLISH); - } +public class Utt2XMLPosEn extends Utt2XMLBase { + public Utt2XMLPosEn() { + super("Utt2XML PosEn", USEnglishDataTypes.FREETTS_POS, MaryDataType.PARTSOFSPEECH, Locale.ENGLISH); + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPostprocessedEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPostprocessedEn.java index 39e9ffc7..07a27396 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPostprocessedEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLPostprocessedEn.java @@ -25,25 +25,15 @@ import marytts.datatypes.MaryDataType; import marytts.language.en_US.datatypes.USEnglishDataTypes; import marytts.modules.Utt2XMLBase; - - /** - * Convert FreeTTS utterances into MaryXML format - * (Postprocessed, English). - * + * Convert FreeTTS utterances into MaryXML format (Postprocessed, English). + * * @author Marc Schröder */ -public class Utt2XMLPostprocessedEn extends Utt2XMLBase -{ - public Utt2XMLPostprocessedEn() - { - super("Utt2XML PostprocessedEn", - USEnglishDataTypes.FREETTS_POSTPROCESSED, - MaryDataType.ALLOPHONES, - Locale.ENGLISH); - } - +public class Utt2XMLPostprocessedEn extends Utt2XMLBase { + public Utt2XMLPostprocessedEn() { + super("Utt2XML PostprocessedEn", USEnglishDataTypes.FREETTS_POSTPROCESSED, MaryDataType.ALLOPHONES, Locale.ENGLISH); + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLSegmentsEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLSegmentsEn.java index 3411954e..5c5b2277 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLSegmentsEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLSegmentsEn.java @@ -25,24 +25,15 @@ import marytts.datatypes.MaryDataType; import marytts.language.en_US.datatypes.USEnglishDataTypes; import marytts.modules.Utt2XMLBase; - - /** - * Convert FreeTTS utterances into MaryXML format - * (Segments, English). - * + * Convert FreeTTS utterances into MaryXML format (Segments, English). + * * @author Marc Schröder */ -public class Utt2XMLSegmentsEn extends Utt2XMLBase -{ - public Utt2XMLSegmentsEn() - { - super("Utt2XML SegmentsEn", - USEnglishDataTypes.FREETTS_SEGMENTS, - MaryDataType.PHONEMES, - Locale.ENGLISH); - } +public class Utt2XMLSegmentsEn extends Utt2XMLBase { + public Utt2XMLSegmentsEn() { + super("Utt2XML SegmentsEn", USEnglishDataTypes.FREETTS_SEGMENTS, MaryDataType.PHONEMES, Locale.ENGLISH); + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLTokensEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLTokensEn.java index 20800696..2fdcd917 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLTokensEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLTokensEn.java @@ -25,25 +25,15 @@ import marytts.datatypes.MaryDataType; import marytts.language.en_US.datatypes.USEnglishDataTypes; import marytts.modules.Utt2XMLBase; - - /** - * Convert FreeTTS utterances into MaryXML format - * (Tokens, English). - * + * Convert FreeTTS utterances into MaryXML format (Tokens, English). + * * @author Marc Schröder */ -public class Utt2XMLTokensEn extends Utt2XMLBase -{ - public Utt2XMLTokensEn() - { - super("Utt2XML TokensEn", - USEnglishDataTypes.FREETTS_TOKENS, - MaryDataType.TOKENS, - Locale.ENGLISH); - } - +public class Utt2XMLTokensEn extends Utt2XMLBase { + public Utt2XMLTokensEn() { + super("Utt2XML TokensEn", USEnglishDataTypes.FREETTS_TOKENS, MaryDataType.TOKENS, Locale.ENGLISH); + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLWordsEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLWordsEn.java index 90f27957..7030b249 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLWordsEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/Utt2XMLWordsEn.java @@ -25,24 +25,15 @@ import marytts.datatypes.MaryDataType; import marytts.language.en_US.datatypes.USEnglishDataTypes; import marytts.modules.Utt2XMLBase; - - /** - * Convert FreeTTS utterances into MaryXML format - * (Words, English). - * + * Convert FreeTTS utterances into MaryXML format (Words, English). + * * @author Marc Schröder */ -public class Utt2XMLWordsEn extends Utt2XMLBase -{ - public Utt2XMLWordsEn() - { - super("Utt2XML WordsEn", - USEnglishDataTypes.FREETTS_WORDS, - MaryDataType.WORDS, - Locale.ENGLISH); - } +public class Utt2XMLWordsEn extends Utt2XMLBase { + public Utt2XMLWordsEn() { + super("Utt2XML WordsEn", USEnglishDataTypes.FREETTS_WORDS, MaryDataType.WORDS, Locale.ENGLISH); + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/WordRelation.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/WordRelation.java index 187a76f5..ef25a081 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/WordRelation.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/WordRelation.java @@ -20,76 +20,72 @@ import com.sun.speech.freetts.Utterance; */ public class WordRelation { - private Relation relation; - private TokenToWords tokenToWords; + private Relation relation; + private TokenToWords tokenToWords; - - private WordRelation(Relation parentRelation, TokenToWords tokenToWords) { - this.relation = parentRelation; - this.tokenToWords = tokenToWords; - } - - - /** - * Creates a WordRelation object with the given utterance and - * TokenToWords. - * - * @param utterance the Utterance from which to create a Relation - * @param tokenToWords the TokenToWords object to use - * - * @return a WordRelation object - */ - public static WordRelation createWordRelation(Utterance utterance, - TokenToWords tokenToWords) { - Relation relation = utterance.createRelation(Relation.WORD); - return new WordRelation(relation, tokenToWords); - } - - - /** - * Adds a break as a feature to the last item in the list. - */ - public void addBreak() { - Item wordItem = relation.getTail(); - if (wordItem != null) { - FeatureSet featureSet = wordItem.getFeatures(); - featureSet.setString("break", "1"); + private WordRelation(Relation parentRelation, TokenToWords tokenToWords) { + this.relation = parentRelation; + this.tokenToWords = tokenToWords; } - } + /** + * Creates a WordRelation object with the given utterance and TokenToWords. + * + * @param utterance + * the Utterance from which to create a Relation + * @param tokenToWords + * the TokenToWords object to use + * + * @return a WordRelation object + */ + public static WordRelation createWordRelation(Utterance utterance, TokenToWords tokenToWords) { + Relation relation = utterance.createRelation(Relation.WORD); + return new WordRelation(relation, tokenToWords); + } - /** - * Adds a word as an Item to this WordRelation object. - * - * @param word the word to add - */ - public void addWord(Item tokenItem, String word) { - assert (tokenItem != null); - Item wordItem = tokenItem.createDaughter(); - FeatureSet featureSet = wordItem.getFeatures(); - featureSet.setString("name", word); - relation.appendItem(wordItem); - } + /** + * Adds a break as a feature to the last item in the list. + */ + public void addBreak() { + Item wordItem = relation.getTail(); + if (wordItem != null) { + FeatureSet featureSet = wordItem.getFeatures(); + featureSet.setString("break", "1"); + } + } + /** + * Adds a word as an Item to this WordRelation object. + * + * @param word + * the word to add + */ + public void addWord(Item tokenItem, String word) { + assert(tokenItem != null); + Item wordItem = tokenItem.createDaughter(); + FeatureSet featureSet = wordItem.getFeatures(); + featureSet.setString("name", word); + relation.appendItem(wordItem); + } - /** - * Sets the last Item in this WordRelation to the given word. - * - * @param word the word to set - */ - public void setLastWord(String word) { - Item lastItem = relation.getTail(); - FeatureSet featureSet = lastItem.getFeatures(); - featureSet.setString("name", word); - } + /** + * Sets the last Item in this WordRelation to the given word. + * + * @param word + * the word to set + */ + public void setLastWord(String word) { + Item lastItem = relation.getTail(); + FeatureSet featureSet = lastItem.getFeatures(); + featureSet.setString("name", word); + } - - /** - * Returns the last item in this WordRelation. - * - * @return the last item - */ - public Item getTail() { - return relation.getTail(); - } + /** + * Returns the last item in this WordRelation. + * + * @return the last item + */ + public Item getTail() { + return relation.getTail(); + } } diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttDurationsEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttDurationsEn.java index 5e026201..4ab06fd2 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttDurationsEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttDurationsEn.java @@ -29,35 +29,24 @@ import org.w3c.dom.Element; import com.sun.speech.freetts.Utterance; - - /** - * Convert a MaryXML DOM tree into FreeTTS utterances - * (durations, English). - * + * Convert a MaryXML DOM tree into FreeTTS utterances (durations, English). + * * @author Marc Schröder */ -public class XML2UttDurationsEn extends XML2UttBase -{ - public XML2UttDurationsEn() { - super("XML2Utt DurationsEn", - MaryDataType.DURATIONS, - USEnglishDataTypes.FREETTS_DURATIONS, - Locale.ENGLISH); - } +public class XML2UttDurationsEn extends XML2UttBase { + public XML2UttDurationsEn() { + super("XML2Utt DurationsEn", MaryDataType.DURATIONS, USEnglishDataTypes.FREETTS_DURATIONS, Locale.ENGLISH); + } - /** - * Depending on the data type, find the right information in the sentence - * and insert it into the utterance. - */ - protected void fillUtterance(Utterance utterance, Element sentence) - { - fillUtterance(utterance, sentence, - true, // create word relation - true, // create sylstruct relation - false); // don't create target relation - } + /** + * Depending on the data type, find the right information in the sentence and insert it into the utterance. + */ + protected void fillUtterance(Utterance utterance, Element sentence) { + fillUtterance(utterance, sentence, true, // create word relation + true, // create sylstruct relation + false); // don't create target relation + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttIntonationEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttIntonationEn.java index 81fbc122..ae26e950 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttIntonationEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttIntonationEn.java @@ -29,35 +29,24 @@ import org.w3c.dom.Element; import com.sun.speech.freetts.Utterance; - - /** - * Convert a MaryXML DOM tree into FreeTTS utterances - * (intonation, English). - * + * Convert a MaryXML DOM tree into FreeTTS utterances (intonation, English). + * * @author Marc Schröder */ -public class XML2UttIntonationEn extends XML2UttBase -{ - public XML2UttIntonationEn() { - super("XML2Utt IntonationEn", - MaryDataType.INTONATION, - USEnglishDataTypes.FREETTS_INTONATION, - Locale.ENGLISH); - } +public class XML2UttIntonationEn extends XML2UttBase { + public XML2UttIntonationEn() { + super("XML2Utt IntonationEn", MaryDataType.INTONATION, USEnglishDataTypes.FREETTS_INTONATION, Locale.ENGLISH); + } - /** - * Depending on the data type, find the right information in the sentence - * and insert it into the utterance. - */ - protected void fillUtterance(Utterance utterance, Element sentence) - { - fillUtterance(utterance, sentence, - true, // create word relation - true, // create sylstruct relation - false); // don't create target relation - } + /** + * Depending on the data type, find the right information in the sentence and insert it into the utterance. + */ + protected void fillUtterance(Utterance utterance, Element sentence) { + fillUtterance(utterance, sentence, true, // create word relation + true, // create sylstruct relation + false); // don't create target relation + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPausesEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPausesEn.java index 2682c950..d1e00b03 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPausesEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPausesEn.java @@ -28,35 +28,24 @@ import org.w3c.dom.Element; import com.sun.speech.freetts.Utterance; - - /** - * Convert a MaryXML DOM tree into FreeTTS utterances - * (pauses, English). - * + * Convert a MaryXML DOM tree into FreeTTS utterances (pauses, English). + * * @author Marc Schröder */ -public class XML2UttPausesEn extends XML2UttBase -{ - public XML2UttPausesEn() { - super("XML2Utt PausesEn", - USEnglishDataTypes.PAUSES_US, - USEnglishDataTypes.FREETTS_PAUSES, - Locale.ENGLISH); - } +public class XML2UttPausesEn extends XML2UttBase { + public XML2UttPausesEn() { + super("XML2Utt PausesEn", USEnglishDataTypes.PAUSES_US, USEnglishDataTypes.FREETTS_PAUSES, Locale.ENGLISH); + } - /** - * Depending on the data type, find the right information in the sentence - * and insert it into the utterance. - */ - protected void fillUtterance(Utterance utterance, Element sentence) - { - fillUtterance(utterance, sentence, - true, // create word relation - true, // create sylstruct relation - false); // don't create target relation - } + /** + * Depending on the data type, find the right information in the sentence and insert it into the utterance. + */ + protected void fillUtterance(Utterance utterance, Element sentence) { + fillUtterance(utterance, sentence, true, // create word relation + true, // create sylstruct relation + false); // don't create target relation + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPhrasesEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPhrasesEn.java index 444daf91..dd184519 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPhrasesEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPhrasesEn.java @@ -28,36 +28,25 @@ import org.w3c.dom.Element; import com.sun.speech.freetts.Utterance; - - /** - * Convert a MaryXML DOM tree into FreeTTS utterances - * (phrases, English). - * + * Convert a MaryXML DOM tree into FreeTTS utterances (phrases, English). + * * @author Marc Schröder */ -public class XML2UttPhrasesEn extends XML2UttBase -{ - public XML2UttPhrasesEn() { - super("XML2Utt PhrasesEn", - USEnglishDataTypes.PHRASES_US, - USEnglishDataTypes.FREETTS_PHRASES, - Locale.ENGLISH); - } +public class XML2UttPhrasesEn extends XML2UttBase { + public XML2UttPhrasesEn() { + super("XML2Utt PhrasesEn", USEnglishDataTypes.PHRASES_US, USEnglishDataTypes.FREETTS_PHRASES, Locale.ENGLISH); + } - /** - * Depending on the data type, find the right information in the sentence - * and insert it into the utterance. - */ - protected void fillUtterance(Utterance utterance, Element sentence) - { - fillUtterance(utterance, sentence, - true, // create word relation - false, // do not create sylstruct relation - false); // don't create target relation + /** + * Depending on the data type, find the right information in the sentence and insert it into the utterance. + */ + protected void fillUtterance(Utterance utterance, Element sentence) { + fillUtterance(utterance, sentence, true, // create word relation + false, // do not create sylstruct relation + false); // don't create target relation - } + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPosEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPosEn.java index 46241d40..5c1ee4a8 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPosEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPosEn.java @@ -29,36 +29,25 @@ import org.w3c.dom.Element; import com.sun.speech.freetts.Utterance; - - /** - * Convert a MaryXML DOM tree into FreeTTS utterances - * (parts of speech, English). - * + * Convert a MaryXML DOM tree into FreeTTS utterances (parts of speech, English). + * * @author Marc Schröder */ -public class XML2UttPosEn extends XML2UttBase -{ - public XML2UttPosEn() { - super("XML2Utt PosEn", - MaryDataType.PARTSOFSPEECH, - USEnglishDataTypes.FREETTS_POS, - Locale.ENGLISH); - } +public class XML2UttPosEn extends XML2UttBase { + public XML2UttPosEn() { + super("XML2Utt PosEn", MaryDataType.PARTSOFSPEECH, USEnglishDataTypes.FREETTS_POS, Locale.ENGLISH); + } - /** - * Depending on the data type, find the right information in the sentence - * and insert it into the utterance. - */ - protected void fillUtterance(Utterance utterance, Element sentence) - { - fillUtterance(utterance, sentence, - true, // create word relation - false, // do not create sylstruct relation - false); // don't create target relation + /** + * Depending on the data type, find the right information in the sentence and insert it into the utterance. + */ + protected void fillUtterance(Utterance utterance, Element sentence) { + fillUtterance(utterance, sentence, true, // create word relation + false, // do not create sylstruct relation + false); // don't create target relation - } + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPostprocessedEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPostprocessedEn.java index ddaaacbc..0eacf61b 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPostprocessedEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttPostprocessedEn.java @@ -29,35 +29,24 @@ import org.w3c.dom.Element; import com.sun.speech.freetts.Utterance; - - /** - * Convert a MaryXML DOM tree into FreeTTS utterances - * (postprocessed, English). - * + * Convert a MaryXML DOM tree into FreeTTS utterances (postprocessed, English). + * * @author Marc Schröder */ -public class XML2UttPostprocessedEn extends XML2UttBase -{ - public XML2UttPostprocessedEn() { - super("XML2Utt PostprocessedEn", - MaryDataType.ALLOPHONES, - USEnglishDataTypes.FREETTS_POSTPROCESSED, - Locale.ENGLISH); - } +public class XML2UttPostprocessedEn extends XML2UttBase { + public XML2UttPostprocessedEn() { + super("XML2Utt PostprocessedEn", MaryDataType.ALLOPHONES, USEnglishDataTypes.FREETTS_POSTPROCESSED, Locale.ENGLISH); + } - /** - * Depending on the data type, find the right information in the sentence - * and insert it into the utterance. - */ - protected void fillUtterance(Utterance utterance, Element sentence) - { - fillUtterance(utterance, sentence, - true, // create word relation - true, // create sylstruct relation - false); // don't create target relation - } + /** + * Depending on the data type, find the right information in the sentence and insert it into the utterance. + */ + protected void fillUtterance(Utterance utterance, Element sentence) { + fillUtterance(utterance, sentence, true, // create word relation + true, // create sylstruct relation + false); // don't create target relation + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttSegmentsEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttSegmentsEn.java index 3e280424..902d85e9 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttSegmentsEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttSegmentsEn.java @@ -29,35 +29,24 @@ import org.w3c.dom.Element; import com.sun.speech.freetts.Utterance; - - /** - * Convert a MaryXML DOM tree into FreeTTS utterances - * (segments, English). - * + * Convert a MaryXML DOM tree into FreeTTS utterances (segments, English). + * * @author Marc Schröder */ -public class XML2UttSegmentsEn extends XML2UttBase -{ - public XML2UttSegmentsEn() { - super("XML2Utt SegmentsEn", - MaryDataType.PHONEMES, - USEnglishDataTypes.FREETTS_SEGMENTS, - Locale.ENGLISH); - } +public class XML2UttSegmentsEn extends XML2UttBase { + public XML2UttSegmentsEn() { + super("XML2Utt SegmentsEn", MaryDataType.PHONEMES, USEnglishDataTypes.FREETTS_SEGMENTS, Locale.ENGLISH); + } - /** - * Depending on the data type, find the right information in the sentence - * and insert it into the utterance. - */ - protected void fillUtterance(Utterance utterance, Element sentence) - { - fillUtterance(utterance, sentence, - true, // create word relation - true, // create sylstruct relation - false); // don't create target relation - } + /** + * Depending on the data type, find the right information in the sentence and insert it into the utterance. + */ + protected void fillUtterance(Utterance utterance, Element sentence) { + fillUtterance(utterance, sentence, true, // create word relation + true, // create sylstruct relation + false); // don't create target relation + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttTokensEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttTokensEn.java index 34e5bde3..e5576c16 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttTokensEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttTokensEn.java @@ -29,36 +29,25 @@ import org.w3c.dom.Element; import com.sun.speech.freetts.Utterance; - - /** - * Convert a MaryXML DOM tree into FreeTTS utterances - * (tokens, English). - * + * Convert a MaryXML DOM tree into FreeTTS utterances (tokens, English). + * * @author Marc Schröder */ -public class XML2UttTokensEn extends XML2UttBase -{ - public XML2UttTokensEn() { - super("XML2Utt TokensEn", - MaryDataType.TOKENS, - USEnglishDataTypes.FREETTS_TOKENS, - Locale.ENGLISH); - } +public class XML2UttTokensEn extends XML2UttBase { + public XML2UttTokensEn() { + super("XML2Utt TokensEn", MaryDataType.TOKENS, USEnglishDataTypes.FREETTS_TOKENS, Locale.ENGLISH); + } - /** - * Depending on the data type, find the right information in the sentence - * and insert it into the utterance. - */ - protected void fillUtterance(Utterance utterance, Element sentence) - { - fillUtterance(utterance, sentence, - false, // do not create word relation - false, // do not create sylstruct relation - false); // don't create target relation + /** + * Depending on the data type, find the right information in the sentence and insert it into the utterance. + */ + protected void fillUtterance(Utterance utterance, Element sentence) { + fillUtterance(utterance, sentence, false, // do not create word relation + false, // do not create sylstruct relation + false); // don't create target relation - } + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttWordsEn.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttWordsEn.java index b0adfe5d..78665995 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttWordsEn.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/XML2UttWordsEn.java @@ -29,36 +29,25 @@ import org.w3c.dom.Element; import com.sun.speech.freetts.Utterance; - - /** - * Convert a MaryXML DOM tree into FreeTTS utterances - * (words, English). - * + * Convert a MaryXML DOM tree into FreeTTS utterances (words, English). + * * @author Marc Schröder */ -public class XML2UttWordsEn extends XML2UttBase -{ - public XML2UttWordsEn() { - super("XML2Utt WordsEn", - MaryDataType.WORDS, - USEnglishDataTypes.FREETTS_WORDS, - Locale.ENGLISH); - } +public class XML2UttWordsEn extends XML2UttBase { + public XML2UttWordsEn() { + super("XML2Utt WordsEn", MaryDataType.WORDS, USEnglishDataTypes.FREETTS_WORDS, Locale.ENGLISH); + } - /** - * Depending on the data type, find the right information in the sentence - * and insert it into the utterance. - */ - protected void fillUtterance(Utterance utterance, Element sentence) - { - fillUtterance(utterance, sentence, - true, // create word relation - false, // do not create sylstruct relation - false); // don't create target relation + /** + * Depending on the data type, find the right information in the sentence and insert it into the utterance. + */ + protected void fillUtterance(Utterance utterance, Element sentence) { + fillUtterance(utterance, sentence, true, // create word relation + false, // do not create sylstruct relation + false); // don't create target relation - } + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/prosody/SentenceType.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/prosody/SentenceType.java index 7371a3a4..64db40ec 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/prosody/SentenceType.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en/prosody/SentenceType.java @@ -22,56 +22,67 @@ package marytts.language.en.prosody; /** * Information on how to recognise and how to realise different sentence types. */ -public class SentenceType -{ - public static final SentenceType declarative = - new SentenceType( "declarative", "L-L%", "H-L%", "H-", "!H*", "L+H*"); - public static final SentenceType interrogative = - new SentenceType("interrogative", "H-H%", "H-L%", "H-", "L*", "H*"); - public static final SentenceType exclamation = - new SentenceType("exclamation", "L-L%", "H-L%", "H-", "H*", "H*"); - public static final SentenceType interrogYN = - new SentenceType("interrogYN", "H-H%", "H-L%", "H-", "L*", "H*"); - public static final SentenceType interrogWH = - new SentenceType("interrogWH", "L-L%", "H-L%", "H-", "H*", "H*"); +public class SentenceType { + public static final SentenceType declarative = new SentenceType("declarative", "L-L%", "H-L%", "H-", "!H*", "L+H*"); + public static final SentenceType interrogative = new SentenceType("interrogative", "H-H%", "H-L%", "H-", "L*", "H*"); + public static final SentenceType exclamation = new SentenceType("exclamation", "L-L%", "H-L%", "H-", "H*", "H*"); + public static final SentenceType interrogYN = new SentenceType("interrogYN", "H-H%", "H-L%", "H-", "L*", "H*"); + public static final SentenceType interrogWH = new SentenceType("interrogWH", "L-L%", "H-L%", "H-", "H*", "H*"); - public static SentenceType punctuationType(String punct) - { - if (punct.equals(".")) return declarative; - else if (punct.equals("?")) return interrogative; - else if (punct.equals("!")) return exclamation; - else return null; - } + public static SentenceType punctuationType(String punct) { + if (punct.equals(".")) + return declarative; + else if (punct.equals("?")) + return interrogative; + else if (punct.equals("!")) + return exclamation; + else + return null; + } - private String name; - private String sentenceFinalBoundary; - private String nonFinalMajorBoundary; - private String minorBoundary; - private String nuclearAccent; - private String nonNuclearAccent; + private String name; + private String sentenceFinalBoundary; + private String nonFinalMajorBoundary; + private String minorBoundary; + private String nuclearAccent; + private String nonNuclearAccent; - private SentenceType(String name, - String sentenceFinalBoundary, - String nonFinalMajorBoundary, - String minorBoundary, - String nuclearAccent, - String nonNuclearAccent) - { - this.name = name; - this.sentenceFinalBoundary = sentenceFinalBoundary; - this.nonFinalMajorBoundary = nonFinalMajorBoundary; - this.minorBoundary = minorBoundary; - this.nuclearAccent = nuclearAccent; - this.nonNuclearAccent = nonNuclearAccent; - } + private SentenceType(String name, String sentenceFinalBoundary, String nonFinalMajorBoundary, String minorBoundary, + String nuclearAccent, String nonNuclearAccent) { + this.name = name; + this.sentenceFinalBoundary = sentenceFinalBoundary; + this.nonFinalMajorBoundary = nonFinalMajorBoundary; + this.minorBoundary = minorBoundary; + this.nuclearAccent = nuclearAccent; + this.nonNuclearAccent = nonNuclearAccent; + } - public String name() { return name; } - public String toString() { return name(); } - public String sentenceFinalBoundary() { return sentenceFinalBoundary; } - public String nonFinalMajorBoundary() { return nonFinalMajorBoundary; } - public String minorBoundary() { return minorBoundary; } - public String nuclearAccent() { return nuclearAccent; } - public String nonNuclearAccent() { return nonNuclearAccent; } + public String name() { + return name; + } + + public String toString() { + return name(); + } + + public String sentenceFinalBoundary() { + return sentenceFinalBoundary; + } + + public String nonFinalMajorBoundary() { + return nonFinalMajorBoundary; + } + + public String minorBoundary() { + return minorBoundary; + } + + public String nuclearAccent() { + return nuclearAccent; + } + + public String nonNuclearAccent() { + return nonNuclearAccent; + } } - diff --git a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en_US/datatypes/USEnglishDataTypes.java b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en_US/datatypes/USEnglishDataTypes.java index dc9334ec..0e86a035 100644 --- a/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en_US/datatypes/USEnglishDataTypes.java +++ b/marytts-languages/marytts-lang-en/src/main/java/marytts/language/en_US/datatypes/USEnglishDataTypes.java @@ -23,25 +23,29 @@ import marytts.datatypes.MaryDataType; import marytts.datatypes.MaryXML; /** - * This class will register the data types that are specific for the - * US English synthesis modules. + * This class will register the data types that are specific for the US English synthesis modules. + * * @author marc - * + * */ -public class USEnglishDataTypes -{ - public static final MaryDataType FREETTS_CONTOUR = new MaryDataType("FREETTS_CONTOUR", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType FREETTS_DURATIONS = new MaryDataType("FREETTS_DURATIONS", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType FREETTS_INTONATION = new MaryDataType("FREETTS_INTONATION", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType FREETTS_MBROLISED_DURATIONS = new MaryDataType("FREETTS_MBROLISED_DURATIONS", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType FREETTS_PAUSES = new MaryDataType("FREETTS_PAUSES", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType FREETTS_PHRASES = new MaryDataType("FREETTS_PHRASES", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType FREETTS_POS = new MaryDataType("FREETTS_POS", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType FREETTS_POSTPROCESSED = new MaryDataType("FREETTS_POSTPROCESSED", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType FREETTS_SEGMENTS = new MaryDataType("FREETTS_SEGMENTS", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType FREETTS_TOKENS = new MaryDataType("FREETTS_TOKENS", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType FREETTS_WORDS = new MaryDataType("FREETTS_WORDS", false, false, MaryDataType.UTTERANCES); - public static final MaryDataType PAUSES_US = new MaryDataType("PAUSES_US", true, true, MaryDataType.MARYXML, MaryXML.MARYXML); - public static final MaryDataType PHRASES_US = new MaryDataType("PHRASES_US", true, true, MaryDataType.MARYXML, MaryXML.MARYXML); +public class USEnglishDataTypes { + public static final MaryDataType FREETTS_CONTOUR = new MaryDataType("FREETTS_CONTOUR", false, false, MaryDataType.UTTERANCES); + public static final MaryDataType FREETTS_DURATIONS = new MaryDataType("FREETTS_DURATIONS", false, false, + MaryDataType.UTTERANCES); + public static final MaryDataType FREETTS_INTONATION = new MaryDataType("FREETTS_INTONATION", false, false, + MaryDataType.UTTERANCES); + public static final MaryDataType FREETTS_MBROLISED_DURATIONS = new MaryDataType("FREETTS_MBROLISED_DURATIONS", false, false, + MaryDataType.UTTERANCES); + public static final MaryDataType FREETTS_PAUSES = new MaryDataType("FREETTS_PAUSES", false, false, MaryDataType.UTTERANCES); + public static final MaryDataType FREETTS_PHRASES = new MaryDataType("FREETTS_PHRASES", false, false, MaryDataType.UTTERANCES); + public static final MaryDataType FREETTS_POS = new MaryDataType("FREETTS_POS", false, false, MaryDataType.UTTERANCES); + public static final MaryDataType FREETTS_POSTPROCESSED = new MaryDataType("FREETTS_POSTPROCESSED", false, false, + MaryDataType.UTTERANCES); + public static final MaryDataType FREETTS_SEGMENTS = new MaryDataType("FREETTS_SEGMENTS", false, false, + MaryDataType.UTTERANCES); + public static final MaryDataType FREETTS_TOKENS = new MaryDataType("FREETTS_TOKENS", false, false, MaryDataType.UTTERANCES); + public static final MaryDataType FREETTS_WORDS = new MaryDataType("FREETTS_WORDS", false, false, MaryDataType.UTTERANCES); + public static final MaryDataType PAUSES_US = new MaryDataType("PAUSES_US", true, true, MaryDataType.MARYXML, MaryXML.MARYXML); + public static final MaryDataType PHRASES_US = new MaryDataType("PHRASES_US", true, true, MaryDataType.MARYXML, + MaryXML.MARYXML); } -