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 <skylion.aaron@gmail.com>2013-09-05 20:17:19 +0400
committerSkylion007 <skylion.aaron@gmail.com>2013-09-05 20:17:19 +0400
commitcc7ce72b8bfcd72b07488382d56552df6dd96c4c (patch)
tree6e186bbd04832c492c55d486ab9fcd78ac56381d
parent5c8ac54aba98f48bc4780286303c66fe16464980 (diff)
Updated volume methods for ease of use and added getNumOfBytes method to
microphone. Also added auto-detect "language" to recognizer.
-rw-r--r--src/com/darkprograms/speech/microphone/Microphone.java41
-rw-r--r--src/com/darkprograms/speech/recognizer/Recognizer.java11
2 files changed, 39 insertions, 13 deletions
diff --git a/src/com/darkprograms/speech/microphone/Microphone.java b/src/com/darkprograms/speech/microphone/Microphone.java
index b9d9a33..e31534e 100644
--- a/src/com/darkprograms/speech/microphone/Microphone.java
+++ b/src/com/darkprograms/speech/microphone/Microphone.java
@@ -137,20 +137,28 @@ public class Microphone {
/**
* Gets the volume of the microphone input
- * Note: Do not update more than every 250ms
- * unless you specify a smaller numOfBytes
- * @return The volume of the microphone input will return -1 if data-line is not available
+ * Interval is 100ms so allow 100ms for this method to run in your code or specify smaller interval.
+ * @return The volume of the microphone input or -1 if data-line is not available
*/
public int getAudioVolume(){
- return getAudioVolume(2000);
+ return getAudioVolume(100);
+ }
+
+ /**
+ * Gets the volume of the microphone input
+ * @param interval: The length of time you would like to calculate the volume over in milliseconds.
+ * @return The volume of the microphone input or -1 if data-line is not available.
+ */
+ public int getAudioVolume(int interval){
+ return calculateAudioVolume(this.getNumOfBytes(interval/1000d));
}
/**
* Gets the volume of microphone input
* @param numOfBytes The number of bytes you want for volume interpretation
- * @return The volume over the specified number of bytes or -1 if mic is unavailable.
+ * @return The volume over the specified number of bytes or -1 if data-line is unavailable.
*/
- public int getAudioVolume(int numOfBytes){
+ private int calculateAudioVolume(int numOfBytes){
if(getTargetDataLine()!=null){
byte[] data = new byte[numOfBytes];
this.getTargetDataLine().read(data, 0, numOfBytes);
@@ -162,7 +170,7 @@ public class Microphone {
}
/**
- * Calculates the volume of AudioData which may be buffered data from a dataline
+ * Calculates the volume of AudioData which may be buffered data from a data-line
* @param audioData The byte[] you want to determine the volume of
* @return the calculated volume of audioData
*/
@@ -181,7 +189,24 @@ public class Microphone {
return (int)(Math.pow(averageMeanSquare,0.5d) + 0.5);
}
-
+ /**
+ * Returns the number of bytes over interval for useful when figuring out how long to record.
+ * @param seconds The length in seconds
+ * @return the number of bytes the microphone will save.
+ */
+ public int getNumOfBytes(int seconds){
+ return getNumOfBytes((double)seconds);
+ }
+
+ /**
+ * Returns the number of bytes over interval for useful when figuring out how long to record.
+ * @param seconds The length in seconds
+ * @return the number of bytes the microphone will output over the specified time.
+ */
+ public int getNumOfBytes(double seconds){
+ return (int)(seconds*getAudioFormat().getSampleRate()*getAudioFormat().getFrameSize()+.5);
+ }
+
/**
* The audio format to save in
*
diff --git a/src/com/darkprograms/speech/recognizer/Recognizer.java b/src/com/darkprograms/speech/recognizer/Recognizer.java
index 70cca69..36a78d5 100644
--- a/src/com/darkprograms/speech/recognizer/Recognizer.java
+++ b/src/com/darkprograms/speech/recognizer/Recognizer.java
@@ -12,8 +12,7 @@ import java.net.URLConnection;
public class Recognizer {
public enum Languages{
- BASQUE("eu"),
- CATALAN("ca"),
+ AUTO_DETECT(null),//tells Google to auto-detect the language
ARABIC__JORDAN("ar-JO"),
ARABIC__LEBANON("ar-LB"),
ARABIC__QATAR("ar-QA"),
@@ -27,6 +26,8 @@ public class Recognizer {
ARABIC__SAUDI_ARABIA("ar-SA"),
ARABIC__TUNISIA("ar-TN"),
ARABIC__YEMEN("ar-YE"),
+ BASQUE("eu"),
+ CATALAN("ca"),
CZECH("cs"),
DUTCH("nl-NL"),
ENGLISH__AUSTRALIA("en-AU"),
@@ -87,18 +88,18 @@ public class Recognizer {
TURKISH("tr"),
ZULU("zu");
- /*
+ /**
*Stores the LanguageCode
*/
private final String languageCode;
- /*
+ /**
*Constructor
*/
private Languages(final String languageCode){
this.languageCode = languageCode;
}
-
+
public String toString(){
return languageCode;
}