diff options
author | Skylion007 <dragonsrcool.aaron@gmail.com> | 2013-09-02 01:49:37 +0400 |
---|---|---|
committer | Skylion007 <dragonsrcool.aaron@gmail.com> | 2013-09-02 01:49:37 +0400 |
commit | ccc42b7d93ab42c54f7e0871b3f5457c9df9a8a9 (patch) | |
tree | 411f8eef93a9649245c275dcc77b7e91e7303a70 | |
parent | f7553d8d1cb5e25dcfc230d3ff06dfc406673c43 (diff) |
Added region autodetection
Allows other attributes to be detected such accents & dialects. Eg. "Ye old store" would return English(old).
-rw-r--r-- | src/com/darkprograms/speech/synthesiser/Synthesiser.java | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/com/darkprograms/speech/synthesiser/Synthesiser.java b/src/com/darkprograms/speech/synthesiser/Synthesiser.java index aa58c51..82691a7 100644 --- a/src/com/darkprograms/speech/synthesiser/Synthesiser.java +++ b/src/com/darkprograms/speech/synthesiser/Synthesiser.java @@ -247,20 +247,30 @@ public class Synthesiser { } /** - * Searches RawData for Language + * Searches RawData for Language & region if possible * @param RawData the raw String directly from Google you want to search through * @return The language parsed from the rawData or null if Google cannot determine it. */ private String parseRawData(String rawData){ for(int i = 0; i+5<rawData.length(); i++){ - if(rawData.charAt(i)==',' && rawData.charAt(i+5)==',' //Looks for ,"en", ,"es", etc. - && rawData.charAt(i+1)== '"' && rawData.charAt(i+4)=='"'){ // ,"**", - String possible = rawData.substring(i+2,i+4); - if(containsLettersOnly(possible)){//Required due to Google's inconsistent formatting. - return possible; + boolean dashDetected = rawData.charAt(i+4)=='-';//Sometimes Google will detect the region too. + if(rawData.charAt(i)==',' && rawData.charAt(i+1)== '"' + && ((rawData.charAt(i+4)=='"' && rawData.charAt(i+5)==',') + || dashDetected)){ + if(dashDetected){//If region is detected parses the whole string! + int lastQuote = rawData.substring(i+2).indexOf('"');//Where the region ends + if(lastQuote>0) + return rawData.substring(i+2,i+2+lastQuote); + } + else{ + String possible = rawData.substring(i+2,i+4); + if(containsLettersOnly(possible)){//Required due to Google's inconsistent formatting. + //System.out.println(possible); + return possible; + } } } - } + }//End of Loop return null; } |