diff options
author | Luke Kuza <luke.kuza@allstarwireless.com> | 2013-09-02 06:05:23 +0400 |
---|---|---|
committer | Luke Kuza <luke.kuza@allstarwireless.com> | 2013-09-02 06:05:23 +0400 |
commit | 3a84a182f5485d2cbd3d177620190d519c635603 (patch) | |
tree | cfa64b9d537630e7e8d3cd7cb0187c28366be536 | |
parent | 3a1c82ffb1d4b0ffc982123be2dc90fd89cb4ab3 (diff) | |
parent | ccc42b7d93ab42c54f7e0871b3f5457c9df9a8a9 (diff) |
Merge pull request #17 from Skylion007/patch-1
Added region autodetection
-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 d648386..31de7e1 100644 --- a/src/com/darkprograms/speech/synthesiser/Synthesiser.java +++ b/src/com/darkprograms/speech/synthesiser/Synthesiser.java @@ -249,20 +249,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; } |