Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/java-speech-api.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSkylion007 <dragonsrcool.aaron@gmail.com>2013-09-02 01:49:37 +0400
committerSkylion007 <dragonsrcool.aaron@gmail.com>2013-09-02 01:49:37 +0400
commitccc42b7d93ab42c54f7e0871b3f5457c9df9a8a9 (patch)
tree411f8eef93a9649245c275dcc77b7e91e7303a70
parentf7553d8d1cb5e25dcfc230d3ff06dfc406673c43 (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.java24
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;
}