summaryrefslogtreecommitdiffstats
path: root/core/java/android/speech/recognition
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
commit54b6cfa9a9e5b861a9930af873580d6dc20f773c (patch)
tree35051494d2af230dce54d6b31c6af8fc24091316 /core/java/android/speech/recognition
downloadframeworks_base-54b6cfa9a9e5b861a9930af873580d6dc20f773c.zip
frameworks_base-54b6cfa9a9e5b861a9930af873580d6dc20f773c.tar.gz
frameworks_base-54b6cfa9a9e5b861a9930af873580d6dc20f773c.tar.bz2
Initial Contribution
Diffstat (limited to 'core/java/android/speech/recognition')
-rw-r--r--core/java/android/speech/recognition/AbstractEmbeddedGrammarListener.java51
-rw-r--r--core/java/android/speech/recognition/AbstractGrammarListener.java39
-rw-r--r--core/java/android/speech/recognition/AbstractRecognizerListener.java83
-rw-r--r--core/java/android/speech/recognition/AbstractSrecGrammarListener.java59
-rw-r--r--core/java/android/speech/recognition/AudioAlreadyInUseException.java34
-rw-r--r--core/java/android/speech/recognition/AudioDriverErrorException.java33
-rw-r--r--core/java/android/speech/recognition/AudioSource.java45
-rw-r--r--core/java/android/speech/recognition/AudioSourceListener.java44
-rw-r--r--core/java/android/speech/recognition/AudioStream.java35
-rw-r--r--core/java/android/speech/recognition/Codec.java126
-rw-r--r--core/java/android/speech/recognition/DeviceSpeaker.java77
-rw-r--r--core/java/android/speech/recognition/DeviceSpeakerListener.java44
-rw-r--r--core/java/android/speech/recognition/EmbeddedGrammar.java43
-rw-r--r--core/java/android/speech/recognition/EmbeddedGrammarListener.java58
-rw-r--r--core/java/android/speech/recognition/EmbeddedRecognizer.java66
-rw-r--r--core/java/android/speech/recognition/Grammar.java43
-rw-r--r--core/java/android/speech/recognition/GrammarErrorException.java33
-rw-r--r--core/java/android/speech/recognition/GrammarListener.java45
-rw-r--r--core/java/android/speech/recognition/GrammarOverflowException.java33
-rw-r--r--core/java/android/speech/recognition/InvalidURLException.java34
-rw-r--r--core/java/android/speech/recognition/Logger.java127
-rw-r--r--core/java/android/speech/recognition/MediaFileReader.java90
-rw-r--r--core/java/android/speech/recognition/MediaFileReaderListener.java29
-rw-r--r--core/java/android/speech/recognition/MediaFileWriter.java49
-rw-r--r--core/java/android/speech/recognition/MediaFileWriterListener.java40
-rw-r--r--core/java/android/speech/recognition/Microphone.java76
-rw-r--r--core/java/android/speech/recognition/MicrophoneListener.java29
-rw-r--r--core/java/android/speech/recognition/NBestRecognitionResult.java113
-rw-r--r--core/java/android/speech/recognition/ParameterErrorException.java33
-rw-r--r--core/java/android/speech/recognition/ParametersListener.java63
-rw-r--r--core/java/android/speech/recognition/ParseErrorException.java33
-rw-r--r--core/java/android/speech/recognition/RecognitionResult.java27
-rw-r--r--core/java/android/speech/recognition/Recognizer.java102
-rw-r--r--core/java/android/speech/recognition/RecognizerListener.java142
-rw-r--r--core/java/android/speech/recognition/SlotItem.java27
-rw-r--r--core/java/android/speech/recognition/SrecGrammar.java81
-rw-r--r--core/java/android/speech/recognition/SrecGrammarListener.java58
-rw-r--r--core/java/android/speech/recognition/VoicetagItem.java82
-rw-r--r--core/java/android/speech/recognition/VoicetagItemListener.java49
-rw-r--r--core/java/android/speech/recognition/WordItem.java58
-rw-r--r--core/java/android/speech/recognition/impl/AudioStreamImpl.java84
-rw-r--r--core/java/android/speech/recognition/impl/DeviceSpeakerImpl.java164
-rw-r--r--core/java/android/speech/recognition/impl/EmbeddedGrammarImpl.java73
-rw-r--r--core/java/android/speech/recognition/impl/EmbeddedRecognizerImpl.java246
-rw-r--r--core/java/android/speech/recognition/impl/EntryImpl.java147
-rw-r--r--core/java/android/speech/recognition/impl/GrammarImpl.java114
-rw-r--r--core/java/android/speech/recognition/impl/LoggerImpl.java166
-rw-r--r--core/java/android/speech/recognition/impl/MediaFileReaderImpl.java156
-rw-r--r--core/java/android/speech/recognition/impl/MediaFileWriterImpl.java102
-rw-r--r--core/java/android/speech/recognition/impl/MicrophoneImpl.java165
-rw-r--r--core/java/android/speech/recognition/impl/NBestRecognitionResultImpl.java106
-rw-r--r--core/java/android/speech/recognition/impl/SrecGrammarImpl.java120
-rw-r--r--core/java/android/speech/recognition/impl/System.java179
-rw-r--r--core/java/android/speech/recognition/impl/VoicetagItemImpl.java206
-rw-r--r--core/java/android/speech/recognition/impl/WordItemImpl.java157
-rwxr-xr-xcore/java/android/speech/recognition/impl/package.html5
-rw-r--r--core/java/android/speech/recognition/package.html6
57 files changed, 4529 insertions, 0 deletions
diff --git a/core/java/android/speech/recognition/AbstractEmbeddedGrammarListener.java b/core/java/android/speech/recognition/AbstractEmbeddedGrammarListener.java
new file mode 100644
index 0000000..c25a7e3
--- /dev/null
+++ b/core/java/android/speech/recognition/AbstractEmbeddedGrammarListener.java
@@ -0,0 +1,51 @@
+/*---------------------------------------------------------------------------*
+ * AbstractEmbeddedGrammarListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * An EmbeddedGrammarListener whose methods are empty. This class exists as
+ * convenience for creating listener objects.
+ */
+public abstract class AbstractEmbeddedGrammarListener implements EmbeddedGrammarListener
+{
+ public void onCompileAllSlots()
+ {
+ }
+
+ public void onError(Exception e)
+ {
+ }
+
+ public void onLoaded()
+ {
+ }
+
+ public void onResetAllSlots()
+ {
+ }
+
+ public void onSaved(String path)
+ {
+ }
+
+ public void onUnloaded()
+ {
+ }
+}
diff --git a/core/java/android/speech/recognition/AbstractGrammarListener.java b/core/java/android/speech/recognition/AbstractGrammarListener.java
new file mode 100644
index 0000000..fe62290
--- /dev/null
+++ b/core/java/android/speech/recognition/AbstractGrammarListener.java
@@ -0,0 +1,39 @@
+/*---------------------------------------------------------------------------*
+ * AbstractGrammarListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * A GrammarListener whose methods are empty. This class exists as convenience
+ * for creating listener objects.
+ */
+public abstract class AbstractGrammarListener implements GrammarListener
+{
+ public void onError(Exception e)
+ {
+ }
+
+ public void onLoaded()
+ {
+ }
+
+ public void onUnloaded()
+ {
+ }
+}
diff --git a/core/java/android/speech/recognition/AbstractRecognizerListener.java b/core/java/android/speech/recognition/AbstractRecognizerListener.java
new file mode 100644
index 0000000..ee2b8d1
--- /dev/null
+++ b/core/java/android/speech/recognition/AbstractRecognizerListener.java
@@ -0,0 +1,83 @@
+/*---------------------------------------------------------------------------*
+ * AbstractRecognizerListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * A RecognizerListener whose methods are empty. This class exists as
+ * convenience for creating listener objects.
+ */
+public abstract class AbstractRecognizerListener implements RecognizerListener
+{
+ public void onBeginningOfSpeech()
+ {
+ }
+
+ public void onEndOfSpeech()
+ {
+ }
+
+ public void onRecognitionSuccess(RecognitionResult result)
+ {
+ }
+
+ public void onRecognitionFailure(FailureReason reason)
+ {
+ }
+
+ public void onError(Exception e)
+ {
+ }
+
+ public void onParametersGetError(Vector<String> parameters, Exception e)
+ {
+ }
+
+ public void onParametersSetError(Hashtable<String, String> parameters,
+ Exception e)
+ {
+ }
+
+ public void onParametersGet(Hashtable<String, String> parameters)
+ {
+ }
+
+ public void onParametersSet(Hashtable<String, String> parameters)
+ {
+ }
+
+ public void onStartOfSpeechTimeout()
+ {
+ }
+
+ public void onAcousticStateReset()
+ {
+ }
+
+ public void onStarted()
+ {
+ }
+
+ public void onStopped()
+ {
+ }
+}
diff --git a/core/java/android/speech/recognition/AbstractSrecGrammarListener.java b/core/java/android/speech/recognition/AbstractSrecGrammarListener.java
new file mode 100644
index 0000000..e62e4ba
--- /dev/null
+++ b/core/java/android/speech/recognition/AbstractSrecGrammarListener.java
@@ -0,0 +1,59 @@
+/*---------------------------------------------------------------------------*
+ * AbstractSrecGrammarListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * An SrecGrammarListener whose methods are empty. This class exists as
+ * convenience for creating listener objects.
+ */
+public abstract class AbstractSrecGrammarListener implements SrecGrammarListener
+{
+ public void onCompileAllSlots()
+ {
+ }
+
+ public void onError(Exception e)
+ {
+ }
+
+ public void onLoaded()
+ {
+ }
+
+ public void onResetAllSlots()
+ {
+ }
+
+ public void onSaved(String path)
+ {
+ }
+
+ public void onUnloaded()
+ {
+ }
+
+ public void onAddItemList()
+ {
+ }
+
+ public void onAddItemListFailure(int index, Exception e)
+ {
+ }
+}
diff --git a/core/java/android/speech/recognition/AudioAlreadyInUseException.java b/core/java/android/speech/recognition/AudioAlreadyInUseException.java
new file mode 100644
index 0000000..90698a7
--- /dev/null
+++ b/core/java/android/speech/recognition/AudioAlreadyInUseException.java
@@ -0,0 +1,34 @@
+/*---------------------------------------------------------------------------*
+ * AudioAlreadyInUseException.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Thrown when an AudioStream is passed into a component when another component
+ * is already using it.
+ */
+public class AudioAlreadyInUseException extends IllegalArgumentException
+{
+ private static final long serialVersionUID = 0L;
+
+ public AudioAlreadyInUseException(String msg)
+ {
+ super(msg);
+ }
+}
diff --git a/core/java/android/speech/recognition/AudioDriverErrorException.java b/core/java/android/speech/recognition/AudioDriverErrorException.java
new file mode 100644
index 0000000..a755e7f
--- /dev/null
+++ b/core/java/android/speech/recognition/AudioDriverErrorException.java
@@ -0,0 +1,33 @@
+/*---------------------------------------------------------------------------*
+ * AudioDriverErrorException.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Thrown if an error occurs in the audio driver.
+ */
+public class AudioDriverErrorException extends Exception
+{
+ private static final long serialVersionUID = 0L;
+
+ public AudioDriverErrorException(String msg)
+ {
+ super(msg);
+ }
+}
diff --git a/core/java/android/speech/recognition/AudioSource.java b/core/java/android/speech/recognition/AudioSource.java
new file mode 100644
index 0000000..c4cd802
--- /dev/null
+++ b/core/java/android/speech/recognition/AudioSource.java
@@ -0,0 +1,45 @@
+/*---------------------------------------------------------------------------*
+ * AudioSource.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Generates audio data.
+ */
+public interface AudioSource
+{
+ /**
+ * Returns an object that contains the audio samples. This object
+ * is passed to other components that consumes it, such a Recognizer
+ * or a DeviceSpeaker.
+ *
+ * @return an AudioStream instance
+ */
+ AudioStream createAudio();
+
+ /**
+ * Tells the audio source to start collecting audio samples.
+ */
+ void start();
+
+ /**
+ * Tells the audio source to stop collecting audio samples.
+ */
+ void stop();
+}
diff --git a/core/java/android/speech/recognition/AudioSourceListener.java b/core/java/android/speech/recognition/AudioSourceListener.java
new file mode 100644
index 0000000..42e8ebe
--- /dev/null
+++ b/core/java/android/speech/recognition/AudioSourceListener.java
@@ -0,0 +1,44 @@
+/*---------------------------------------------------------------------------*
+ * AudioSourceListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Listens for Microphone events.
+ */
+public interface AudioSourceListener
+{
+ /**
+ * Invoked after the microphone starts recording.
+ */
+ void onStarted();
+
+ /**
+ * Invoked after the microphone stops recording.
+ */
+ void onStopped();
+
+ /**
+ * Invoked when an unexpected error occurs. This is normally followed by
+ * onStopped() if the component shuts down successfully.
+ *
+ * @param e the cause of the failure
+ */
+ void onError(Exception e);
+}
diff --git a/core/java/android/speech/recognition/AudioStream.java b/core/java/android/speech/recognition/AudioStream.java
new file mode 100644
index 0000000..36afe21
--- /dev/null
+++ b/core/java/android/speech/recognition/AudioStream.java
@@ -0,0 +1,35 @@
+/*---------------------------------------------------------------------------*
+ * AudioStream.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Stream used to read audio data.
+ */
+public interface AudioStream
+{
+ /**
+ * Releases resources associated with the object.
+ *
+ * @deprecated this method is deprecated and has no replacement. It will be
+ * removed in a future release of the API.
+ */
+ @Deprecated
+ void dispose();
+}
diff --git a/core/java/android/speech/recognition/Codec.java b/core/java/android/speech/recognition/Codec.java
new file mode 100644
index 0000000..18d9e15
--- /dev/null
+++ b/core/java/android/speech/recognition/Codec.java
@@ -0,0 +1,126 @@
+/*---------------------------------------------------------------------------*
+ * Codec.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Audio formats.
+ */
+public abstract class Codec
+{
+ /**
+ * PCM, 16 bits, 8KHz.
+ */
+ public static final Codec PCM_16BIT_8K = new Codec("PCM/16bit/8KHz")
+ {
+ @Override
+ public byte getBitsPerSample()
+ {
+ return 16;
+ }
+
+ @Override
+ public int getSampleRate()
+ {
+ return 8000;
+ }
+ };
+ /**
+ * PCM, 16 bits, 11KHz.
+ */
+ public static final Codec PCM_16BIT_11K = new Codec("PCM/16bit/11KHz")
+ {
+ @Override
+ public byte getBitsPerSample()
+ {
+ return 16;
+ }
+
+ @Override
+ public int getSampleRate()
+ {
+ return 11025;
+ }
+ };
+ /**
+ * PCM, 16 bits, 22KHz.
+ */
+ public static final Codec PCM_16BIT_22K = new Codec("PCM/16bit/22KHz")
+ {
+ @Override
+ public byte getBitsPerSample()
+ {
+ return 16;
+ }
+
+ @Override
+ public int getSampleRate()
+ {
+ return 22050;
+ }
+ };
+ /**
+ * ULAW, 8 bits, 8KHz.
+ */
+ public static final Codec ULAW_8BIT_8K = new Codec("ULAW/8bit/8KHz")
+ {
+ @Override
+ public byte getBitsPerSample()
+ {
+ return 8;
+ }
+
+ @Override
+ public int getSampleRate()
+ {
+ return 8000;
+ }
+ };
+ private final String message;
+
+ /**
+ * Creates a new Codec.
+ *
+ * @param message the message to associate with the codec
+ */
+ private Codec(String message)
+ {
+ this.message = message;
+ }
+
+ @Override
+ public String toString()
+ {
+ return message;
+ }
+
+ /**
+ * Returns the codec sample-rate.
+ *
+ * @return the codec sample-rate
+ */
+ public abstract int getSampleRate();
+
+ /**
+ * Returns the codec bitrate.
+ *
+ * @return the codec bitrate
+ */
+ public abstract byte getBitsPerSample();
+}
diff --git a/core/java/android/speech/recognition/DeviceSpeaker.java b/core/java/android/speech/recognition/DeviceSpeaker.java
new file mode 100644
index 0000000..bd18687
--- /dev/null
+++ b/core/java/android/speech/recognition/DeviceSpeaker.java
@@ -0,0 +1,77 @@
+/*---------------------------------------------------------------------------*
+ * DeviceSpeaker.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import android.speech.recognition.impl.DeviceSpeakerImpl;
+
+/**
+ * A device for transforming electric signals into audible sound, most
+ * frequently used to reproduce speech and music.
+ */
+public abstract class DeviceSpeaker
+{
+ private static DeviceSpeaker instance;
+
+ /**
+ * Returns the device speaker instance.
+ *
+ * @return an instance of a DeviceSpeaker class.
+ */
+ public static DeviceSpeaker getInstance()
+ {
+ instance = DeviceSpeakerImpl.getInstance();
+ return instance;
+ }
+
+ /**
+ * Starts the audio playback.
+ *
+ * @param source the audio to play
+ * @throws IllegalStateException if the component is already started
+ * @throws IllegalArgumentException if source audio is null, in-use by
+ * another component or is empty.
+ *
+ */
+ public abstract void start(AudioStream source) throws IllegalStateException,
+ IllegalArgumentException;
+
+ /**
+ * Stops audio playback.
+ */
+ public abstract void stop();
+
+ /**
+ * Sets the playback codec. This must be called before start() is called.
+ *
+ * @param playbackCodec the codec to use for the playback operation.
+ * @throws IllegalStateException if the component is already stopped
+ * @throws IllegalArgumentException if the specified codec is not supported
+ */
+ public abstract void setCodec(Codec playbackCodec) throws IllegalStateException,
+ IllegalArgumentException;
+
+ /**
+ * Sets the microphone listener.
+ *
+ * @param listener the device speaker listener.
+ * @throws IllegalStateException if the component is started
+ */
+ public abstract void setListener(DeviceSpeakerListener listener) throws IllegalStateException;
+}
diff --git a/core/java/android/speech/recognition/DeviceSpeakerListener.java b/core/java/android/speech/recognition/DeviceSpeakerListener.java
new file mode 100644
index 0000000..e2baa2e
--- /dev/null
+++ b/core/java/android/speech/recognition/DeviceSpeakerListener.java
@@ -0,0 +1,44 @@
+/*---------------------------------------------------------------------------*
+ * DeviceSpeakerListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Listens for DeviceSpeaker events.
+ */
+public interface DeviceSpeakerListener
+{
+ /**
+ * Invoked after playback begins.
+ */
+ void onStarted();
+
+ /**
+ * Invoked after playback terminates.
+ */
+ void onStopped();
+
+ /**
+ * Invoked when an unexpected error occurs. This is normally followed by
+ * onStopped() if the component shuts down successfully.
+ *
+ * @param e the cause of the failure
+ */
+ void onError(Exception e);
+}
diff --git a/core/java/android/speech/recognition/EmbeddedGrammar.java b/core/java/android/speech/recognition/EmbeddedGrammar.java
new file mode 100644
index 0000000..c6f037b
--- /dev/null
+++ b/core/java/android/speech/recognition/EmbeddedGrammar.java
@@ -0,0 +1,43 @@
+/*---------------------------------------------------------------------------*
+ * EmbeddedGrammar.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Grammar on an embedded recognizer.
+ */
+public interface EmbeddedGrammar extends Grammar
+{
+ /**
+ * Compiles items that were added to any of the grammar slots.
+ */
+ void compileAllSlots();
+
+ /**
+ * Removes all words added to all slots.
+ */
+ void resetAllSlots();
+
+ /**
+ * Saves the compiled grammar.
+ *
+ * @param url the url to save the grammar to
+ */
+ void save(String url);
+}
diff --git a/core/java/android/speech/recognition/EmbeddedGrammarListener.java b/core/java/android/speech/recognition/EmbeddedGrammarListener.java
new file mode 100644
index 0000000..5b8c1a4
--- /dev/null
+++ b/core/java/android/speech/recognition/EmbeddedGrammarListener.java
@@ -0,0 +1,58 @@
+/*---------------------------------------------------------------------------*
+ * EmbeddedGrammarListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Listens for EmbeddedGrammar events.
+ */
+public interface EmbeddedGrammarListener extends GrammarListener
+{
+ /**
+ * Invoked after the grammar is saved.
+ *
+ * @param path the path the grammar was saved to
+ */
+ void onSaved(String path);
+
+ /**
+ * Invoked when a grammar operation fails.
+ *
+ * @param e the cause of the failure.<br/>
+ * {@link GrammarOverflowException} if the grammar slot is full and no
+ * further items may be added to it.<br/>
+ * {@link java.lang.UnsupportedOperationException} if different words with
+ * the same pronunciation are added.<br/>
+ * {@link java.lang.IllegalStateException} if reseting or compiling the
+ * slots fails.<br/>
+ * {@link java.io.IOException} if the grammar could not be loaded or
+ * saved.</p>
+ */
+ void onError(Exception e);
+
+ /**
+ * Invokes after all grammar slots have been compiled.
+ */
+ void onCompileAllSlots();
+
+ /**
+ * Invokes after all grammar slots have been reset.
+ */
+ void onResetAllSlots();
+}
diff --git a/core/java/android/speech/recognition/EmbeddedRecognizer.java b/core/java/android/speech/recognition/EmbeddedRecognizer.java
new file mode 100644
index 0000000..cd79edc
--- /dev/null
+++ b/core/java/android/speech/recognition/EmbeddedRecognizer.java
@@ -0,0 +1,66 @@
+/*---------------------------------------------------------------------------*
+ * EmbeddedRecognizer.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import android.speech.recognition.impl.EmbeddedRecognizerImpl;
+
+/**
+ * Embedded recognizer.
+ */
+public abstract class EmbeddedRecognizer implements Recognizer
+{
+ private static EmbeddedRecognizer instance;
+
+ /**
+ * Returns the embedded recognizer.
+ *
+ * @return the embedded recognizer
+ */
+ public static EmbeddedRecognizer getInstance()
+ {
+ instance = EmbeddedRecognizerImpl.getInstance();
+ return instance;
+ }
+
+ /**
+ * Configures the recognizer.
+ *
+ * @param config recognizer configuration file
+ * @throws IllegalArgumentException if config is null or an empty string
+ * @throws FileNotFoundException if the specified file could not be found
+ * @throws IOException if the specified file could not be opened
+ * @throws UnsatisfiedLinkError if the recognizer plugin could not be loaded
+ * @throws ClassNotFoundException if the recognizer plugin could not be found
+ */
+ public abstract void configure(String config) throws IllegalArgumentException,
+ FileNotFoundException, IOException, UnsatisfiedLinkError,
+ ClassNotFoundException;
+
+ /**
+ * The recognition accuracy improves over time as the recognizer adapts to
+ * the surrounding environment. This method enables developers to reset the
+ * adaptation when the environment is known to have changed.
+ *
+ * @throws IllegalArgumentException if recognizer instance is null
+ */
+ public abstract void resetAcousticState() throws IllegalArgumentException;
+}
diff --git a/core/java/android/speech/recognition/Grammar.java b/core/java/android/speech/recognition/Grammar.java
new file mode 100644
index 0000000..9f1b624
--- /dev/null
+++ b/core/java/android/speech/recognition/Grammar.java
@@ -0,0 +1,43 @@
+/*---------------------------------------------------------------------------*
+ * Grammar.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Speech recognition grammar.
+ */
+public interface Grammar {
+ /**
+ * Load the grammar sets the grammar state to active, indicating that can be used in a recognition process.
+ * Multiple grammars can be loaded, but only one at a time can be used by the recognizer.
+ *
+ */
+ void load();
+
+ /**
+ * Unload the grammar sets the grammar state to inactive (inactive grammars can not be used as a parameter of a recognition).
+ */
+ void unload();
+
+ /**
+ * (Optional operation) Releases resources associated with the object. The
+ * grammar may not be used past this point.
+ */
+ void dispose();
+}
diff --git a/core/java/android/speech/recognition/GrammarErrorException.java b/core/java/android/speech/recognition/GrammarErrorException.java
new file mode 100644
index 0000000..6070758
--- /dev/null
+++ b/core/java/android/speech/recognition/GrammarErrorException.java
@@ -0,0 +1,33 @@
+/*---------------------------------------------------------------------------*
+ * GrammarErrorException.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Thrown if an error occurs in the audio driver.
+ */
+public class GrammarErrorException extends Exception
+{
+ private static final long serialVersionUID = 0L;
+
+ public GrammarErrorException(String msg)
+ {
+ super(msg);
+ }
+}
diff --git a/core/java/android/speech/recognition/GrammarListener.java b/core/java/android/speech/recognition/GrammarListener.java
new file mode 100644
index 0000000..871cbcb
--- /dev/null
+++ b/core/java/android/speech/recognition/GrammarListener.java
@@ -0,0 +1,45 @@
+/*---------------------------------------------------------------------------*
+ * GrammarListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Listens for Grammar events.
+ */
+public interface GrammarListener
+{
+ /**
+ * Invoked after the Grammar is loaded.
+ */
+ void onLoaded();
+
+ /**
+ * Invoked after the Grammar is unloaded.
+ */
+ void onUnloaded();
+
+ /**
+ * Invoked when a grammar operation fails.
+ *
+ * @param e the cause of the failure.<br/>
+ * {@link java.io.IOException} if the grammar could not be loaded or
+ * saved.</p>
+ */
+ void onError(Exception e);
+}
diff --git a/core/java/android/speech/recognition/GrammarOverflowException.java b/core/java/android/speech/recognition/GrammarOverflowException.java
new file mode 100644
index 0000000..227820b
--- /dev/null
+++ b/core/java/android/speech/recognition/GrammarOverflowException.java
@@ -0,0 +1,33 @@
+/*---------------------------------------------------------------------------*
+ * GrammarOverflowException.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Thrown if a SlotItem is added into a grammar slot that is filled to capacity.
+ */
+public class GrammarOverflowException extends Exception
+{
+ private static final long serialVersionUID = 0L;
+
+ public GrammarOverflowException(String message)
+ {
+ super(message);
+ }
+}
diff --git a/core/java/android/speech/recognition/InvalidURLException.java b/core/java/android/speech/recognition/InvalidURLException.java
new file mode 100644
index 0000000..fec9411
--- /dev/null
+++ b/core/java/android/speech/recognition/InvalidURLException.java
@@ -0,0 +1,34 @@
+/*---------------------------------------------------------------------------*
+ * InvalidURLException.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ */
+public class InvalidURLException extends Exception {
+
+ private static final long serialVersionUID = 0L;
+
+ /** Creates a new instance of InvalidURLException */
+ public InvalidURLException(String msg)
+ {
+ super(msg);
+ }
+
+}
diff --git a/core/java/android/speech/recognition/Logger.java b/core/java/android/speech/recognition/Logger.java
new file mode 100644
index 0000000..8a09cb3
--- /dev/null
+++ b/core/java/android/speech/recognition/Logger.java
@@ -0,0 +1,127 @@
+/*---------------------------------------------------------------------------*
+ * Logger.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import android.speech.recognition.impl.LoggerImpl;
+
+/**
+ * Logs debugging information.
+ */
+public abstract class Logger
+{
+ /**
+ * Logging level
+ */
+ public static class LogLevel
+ {
+ /**
+ * Does not log.
+ */
+ public static LogLevel LEVEL_NONE = new LogLevel("Do not log");
+ /**
+ * Logs fatal issues. This level only logs ERROR.
+ */
+ public static LogLevel LEVEL_ERROR = new LogLevel("log UAPI_ERROR logs");
+ /**
+ * Logs non-fatal issues. This level also logs ERROR.
+ */
+ public static LogLevel LEVEL_WARN =
+ new LogLevel("log UAPI_ERROR, UAPI_WARN logs");
+ /**
+ * Logs debugging information, such as the values of variables. This level also logs ERROR, WARN.
+ */
+ public static LogLevel LEVEL_INFO =
+ new LogLevel("log UAPI_ERROR, UAPI_WARN, UAPI_INFO logs");
+ /**
+ * Logs when loggers are created or destroyed. This level also logs INFO, WARN, ERROR.
+ */
+ public static LogLevel LEVEL_TRACE =
+ new LogLevel("log UAPI_ERROR, UAPI_WARN, UAPI_INFO, UAPI_TRACE logs");
+ private String message;
+
+ /**
+ * Creates a new LogLevel.
+ *
+ * @param message the message associated with the LogLevel.
+ */
+ private LogLevel(String message)
+ {
+ this.message = message;
+ }
+
+ @Override
+ public String toString()
+ {
+ return message;
+ }
+ }
+
+ /**
+ * Returns the singleton instance.
+ *
+ * @return the singleton instance
+ */
+ public static Logger getInstance()
+ {
+ return LoggerImpl.getInstance();
+ }
+
+ /**
+ * Sets the logging level.
+ *
+ * @param level the logging level
+ */
+ public abstract void setLoggingLevel(LogLevel level);
+
+ /**
+ * Sets the log path.
+ *
+ * @param path the path of the log file
+ */
+ public abstract void setPath(String path);
+
+ /**
+ * Logs an error message.
+ *
+ * @param message the message to log
+ */
+ public abstract void error(String message);
+
+ /**
+ * Logs a warning message.
+ *
+ * @param message the message to log
+ */
+ public abstract void warn(String message);
+
+ /**
+ * Logs an informational message.
+ *
+ * @param message the message to log
+ */
+ public abstract void info(String message);
+
+ /**
+ * Logs a method tracing message.
+ *
+ * @param message the message to log
+ */
+ public abstract void trace(String message);
+}
diff --git a/core/java/android/speech/recognition/MediaFileReader.java b/core/java/android/speech/recognition/MediaFileReader.java
new file mode 100644
index 0000000..216511f
--- /dev/null
+++ b/core/java/android/speech/recognition/MediaFileReader.java
@@ -0,0 +1,90 @@
+/*---------------------------------------------------------------------------*
+ * MediaFileReader.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import android.speech.recognition.impl.MediaFileReaderImpl;
+
+/**
+ * Reads audio from a file.
+ */
+public abstract class MediaFileReader implements AudioSource
+{
+ /**
+ * Reading mode
+ */
+ public static class Mode
+ {
+ /**
+ * Read the file in "real time".
+ */
+ public static Mode REAL_TIME = new Mode("real-time");
+ /**
+ * Read the file all at once.
+ */
+ public static Mode ALL_AT_ONCE = new Mode("all at once");
+ private String message;
+
+ /**
+ * Creates a new Mode.
+ *
+ * @param message the message associated with the reading mode.
+ */
+ private Mode(String message)
+ {
+ this.message = message;
+ }
+ }
+
+ /**
+ * Creates a new MediaFileReader to read audio samples from a file.
+ *
+ * @param filename the name of the file to read from Note: The file MUST be of type Microsoft WAVE RIFF
+ * format (PCM 16 bits 8000 Hz or PCM 16 bits 11025 Hz).
+ * @param listener listens for MediaFileReader events
+ * @return a new MediaFileReader
+ * @throws IllegalArgumentException if filename is null or is an empty string. Or if offset > file length. Or if codec is null or invalid
+ */
+ public static MediaFileReader create(String filename, AudioSourceListener listener) throws IllegalArgumentException
+ {
+ return new MediaFileReaderImpl(filename, listener);
+ }
+
+ /**
+ * Sets the reading mode.
+ *
+ * @param mode the reading mode
+ */
+ public abstract void setMode(Mode mode);
+
+ /**
+ * Creates an audio source.
+ */
+ public abstract AudioStream createAudio();
+
+ /**
+ * Starts collecting audio samples.
+ */
+ public abstract void start();
+
+ /**
+ * Stops collecting audio samples.
+ */
+ public abstract void stop();
+}
diff --git a/core/java/android/speech/recognition/MediaFileReaderListener.java b/core/java/android/speech/recognition/MediaFileReaderListener.java
new file mode 100644
index 0000000..f76e65f
--- /dev/null
+++ b/core/java/android/speech/recognition/MediaFileReaderListener.java
@@ -0,0 +1,29 @@
+/*---------------------------------------------------------------------------*
+ * MediaFileReaderListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import android.speech.recognition.AudioSourceListener;
+
+/**
+ * Listens for MediaFileReader events.
+ */
+public interface MediaFileReaderListener extends AudioSourceListener
+{
+}
diff --git a/core/java/android/speech/recognition/MediaFileWriter.java b/core/java/android/speech/recognition/MediaFileWriter.java
new file mode 100644
index 0000000..b2d627c
--- /dev/null
+++ b/core/java/android/speech/recognition/MediaFileWriter.java
@@ -0,0 +1,49 @@
+/*---------------------------------------------------------------------------*
+ * MediaFileWriter.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import android.speech.recognition.impl.MediaFileWriterImpl;
+
+/**
+ * Writes audio to a file.
+ */
+public abstract class MediaFileWriter
+{
+ /**
+ * Creates a new MediaFileWriter to write audio samples into a file.
+ *
+ * @param listener listens for MediaFileWriter events
+ * @return a new MediaFileWriter
+ */
+ public static MediaFileWriter create(MediaFileWriterListener listener)
+ {
+ return new MediaFileWriterImpl(listener);
+ }
+
+ /**
+ * Saves audio to a file.
+ *
+ * @param source the audio stream to write
+ * @param filename the file to write to
+ * @throws IllegalArgumentException if source is null, in-use by another
+ * component or contains no data. Or if filename is null or is empty.
+ */
+ public abstract void save(AudioStream source, String filename) throws IllegalArgumentException;
+}
diff --git a/core/java/android/speech/recognition/MediaFileWriterListener.java b/core/java/android/speech/recognition/MediaFileWriterListener.java
new file mode 100644
index 0000000..e2104c8
--- /dev/null
+++ b/core/java/android/speech/recognition/MediaFileWriterListener.java
@@ -0,0 +1,40 @@
+/*---------------------------------------------------------------------------*
+ * MediaFileWriterListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Listens for MediaFileWriter events.
+ */
+public interface MediaFileWriterListener
+{
+ /**
+ * Invoked after the save() operation terminates
+ */
+ void onStopped();
+
+ /**
+ * Invoked when an unexpected error occurs. This is normally followed by
+ * onStopped() if the component shuts down successfully.
+ *
+ * @param e the cause of the failure.<br/>
+ * {@link java.io.IOException} if an error occured opening or writing to the file
+ */
+ void onError(Exception e);
+}
diff --git a/core/java/android/speech/recognition/Microphone.java b/core/java/android/speech/recognition/Microphone.java
new file mode 100644
index 0000000..1b713f5
--- /dev/null
+++ b/core/java/android/speech/recognition/Microphone.java
@@ -0,0 +1,76 @@
+/*---------------------------------------------------------------------------*
+ * Microphone.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import android.speech.recognition.impl.MicrophoneImpl;
+
+/**
+ * Records live audio.
+ */
+public abstract class Microphone implements AudioSource
+{
+ private static Microphone instance;
+
+ /**
+ * Returns the microphone instance
+ *
+ * @return an instance of a Microphone class.
+ */
+ public static Microphone getInstance()
+ {
+ instance = MicrophoneImpl.getInstance();
+ return instance;
+ }
+
+ /**
+ * Sets the recording codec. This must be called before start() is called.
+ *
+ * @param recordingCodec the codec in which the samples will be recorded.
+ * @throws IllegalStateException if Microphone is started
+ * @throws IllegalArgumentException if codec is not supported
+ */
+ public abstract void setCodec(Codec recordingCodec) throws IllegalStateException,
+ IllegalArgumentException;
+
+ /**
+ * Sets the microphone listener.
+ *
+ * @param listener the microphone listener.
+ * @throws IllegalStateException if Microphone is started
+ */
+ public abstract void setListener(AudioSourceListener listener) throws IllegalStateException;
+
+ /**
+ * Creates an audio source
+ */
+ public abstract AudioStream createAudio();
+
+ /**
+ * Start recording audio.
+ *
+ * @throws IllegalStateException if Microphone is already started
+ */
+ public abstract void start() throws IllegalStateException;
+
+ /**
+ * Stops recording audio.
+ */
+ public abstract void stop();
+}
diff --git a/core/java/android/speech/recognition/MicrophoneListener.java b/core/java/android/speech/recognition/MicrophoneListener.java
new file mode 100644
index 0000000..f43eff9
--- /dev/null
+++ b/core/java/android/speech/recognition/MicrophoneListener.java
@@ -0,0 +1,29 @@
+/*---------------------------------------------------------------------------*
+ * MicrophoneListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import android.speech.recognition.AudioSourceListener;
+
+/**
+ * Listens for Microphone events.
+ */
+public interface MicrophoneListener extends AudioSourceListener
+{
+}
diff --git a/core/java/android/speech/recognition/NBestRecognitionResult.java b/core/java/android/speech/recognition/NBestRecognitionResult.java
new file mode 100644
index 0000000..e679c19
--- /dev/null
+++ b/core/java/android/speech/recognition/NBestRecognitionResult.java
@@ -0,0 +1,113 @@
+/*---------------------------------------------------------------------------*
+ * NBestRecognitionResult.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import java.util.Enumeration;
+
+/**
+ * N-Best recognition results. Entries are sorted in decreasing order according
+ * to their probability, from the most probable result to the least probable
+ * result.
+ */
+public interface NBestRecognitionResult extends RecognitionResult
+{
+ /**
+ * Recognition result entry
+ */
+ public static interface Entry
+ {
+ /**
+ * Returns the semantic meaning of a recognition result (i.e.&nbsp;the application-specific value
+ * associated with what the user said). In an example where a person's name is mapped
+ * to a phone-number, the phone-number is the semantic meaning.
+ *
+ * @return the semantic meaning of a recognition result.
+ * @throws IllegalStateException if the object has been disposed
+ */
+ String getSemanticMeaning() throws IllegalStateException;
+
+ /**
+ * The confidence score of a recognition result. Values range from 0 to 100
+ * (inclusive).
+ *
+ * @return the confidence score of a recognition result.
+ * @throws IllegalStateException if the object has been disposed
+ */
+ byte getConfidenceScore() throws IllegalStateException;
+
+ /**
+ * Returns the literal meaning of a recognition result (i.e.&nbsp;literally
+ * what the user said). In an example where a person's name is mapped to a
+ * phone-number, the person's name is the literal meaning.
+ *
+ * @return the literal meaning of a recognition result.
+ * @throws IllegalStateException if the object has been disposed
+ */
+ String getLiteralMeaning() throws IllegalStateException;
+
+ /**
+ * Returns the value associated with the specified key.
+ *
+ * @param key the key to look up
+ * @return the associated value or null if this entry does not contain
+ * any mapping for the key
+ */
+ String get(String key);
+
+ /**
+ * Returns an enumeration of the keys in this Entry.
+ *
+ * @return an enumeration of the keys in this Entry.
+ */
+ Enumeration keys();
+ }
+
+ /**
+ * Returns the number of entries in the n-best list.
+ *
+ * @return the number of entries in the n-best list
+ */
+ int getSize();
+
+ /**
+ * Returns the n-best entry that contains key-value pairs associated with the
+ * recognition result.
+ *
+ * @param index the index of the n-best entry
+ * @return null if all active GrammarConfiguration.grammarToMeaning() return
+ * null
+ * @throws ArrayIndexOutOfBoundsException if index is greater than size of
+ * entries
+ */
+ Entry getEntry(int index) throws ArrayIndexOutOfBoundsException;
+
+ /**
+ * Creates a new VoicetagItem if the last recognition was an enrollment
+ * operation.
+ *
+ * @param VoicetagId string voicetag unique id value.
+ * @param listener listens for Voicetag events
+ * @return the resulting VoicetagItem
+ * @throws IllegalArgumentException if VoicetagId is null or an empty string.
+ * @throws IllegalStateException if the last recognition was not an
+ * enrollment operation
+ */
+ VoicetagItem createVoicetagItem(String VoicetagId, VoicetagItemListener listener) throws IllegalArgumentException,IllegalStateException;
+}
diff --git a/core/java/android/speech/recognition/ParameterErrorException.java b/core/java/android/speech/recognition/ParameterErrorException.java
new file mode 100644
index 0000000..042ed31
--- /dev/null
+++ b/core/java/android/speech/recognition/ParameterErrorException.java
@@ -0,0 +1,33 @@
+/*---------------------------------------------------------------------------*
+ * ParameterErrorException.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Thrown if an error occurs in the audio driver.
+ */
+public class ParameterErrorException extends Exception
+{
+ private static final long serialVersionUID = 0L;
+
+ public ParameterErrorException(String msg)
+ {
+ super(msg);
+ }
+}
diff --git a/core/java/android/speech/recognition/ParametersListener.java b/core/java/android/speech/recognition/ParametersListener.java
new file mode 100644
index 0000000..bdb551e
--- /dev/null
+++ b/core/java/android/speech/recognition/ParametersListener.java
@@ -0,0 +1,63 @@
+/*---------------------------------------------------------------------------*
+ * ParametersListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * Listens for parameter events.
+ */
+public interface ParametersListener
+{
+ /**
+ * Invoked if retrieving parameters has failed.
+ *
+ * @param parameters the parameters that could not be retrieved
+ * @param e the failure reason
+ */
+ void onParametersGetError(Vector<String> parameters, Exception e);
+
+ /**
+ * Invoked if setting parameters has failed.
+ *
+ * @param parameters the parameters that could not be set
+ * @param e the failure reason
+ */
+ void onParametersSetError(Hashtable<String, String> parameters, Exception e);
+
+ /**
+ * This method is called when the parameters specified in setParameters have
+ * successfully been set. This method is guaranteed to be invoked after
+ * onParametersSetError, even if count==0.
+ *
+ * @param parameters the set parameters
+ */
+ void onParametersSet(Hashtable<String, String> parameters);
+
+ /**
+ * This method is called when the parameters specified in getParameters have
+ * successfully been retrieved. This method is guaranteed to be invoked after
+ * onParametersGetError, even if count==0.
+ *
+ * @param parameters the retrieved parameters
+ */
+ void onParametersGet(Hashtable<String, String> parameters);
+}
diff --git a/core/java/android/speech/recognition/ParseErrorException.java b/core/java/android/speech/recognition/ParseErrorException.java
new file mode 100644
index 0000000..2288a90
--- /dev/null
+++ b/core/java/android/speech/recognition/ParseErrorException.java
@@ -0,0 +1,33 @@
+/*---------------------------------------------------------------------------*
+ * ParseErrorException.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Thrown if an error occurs in the audio driver.
+ */
+public class ParseErrorException extends Exception
+{
+ private static final long serialVersionUID = 0L;
+
+ public ParseErrorException(String msg)
+ {
+ super(msg);
+ }
+}
diff --git a/core/java/android/speech/recognition/RecognitionResult.java b/core/java/android/speech/recognition/RecognitionResult.java
new file mode 100644
index 0000000..cbbc938
--- /dev/null
+++ b/core/java/android/speech/recognition/RecognitionResult.java
@@ -0,0 +1,27 @@
+/*---------------------------------------------------------------------------*
+ * RecognitionResult.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Recognition result interface.
+ */
+public interface RecognitionResult
+{
+}
diff --git a/core/java/android/speech/recognition/Recognizer.java b/core/java/android/speech/recognition/Recognizer.java
new file mode 100644
index 0000000..ab7f8f4
--- /dev/null
+++ b/core/java/android/speech/recognition/Recognizer.java
@@ -0,0 +1,102 @@
+/*---------------------------------------------------------------------------*
+ * Recognizer.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * Speech recognizer interface.
+ */
+public interface Recognizer
+{
+ /**
+ * Sets the recognizer event listener.
+ *
+ * @param listener listens for recognizer events
+ */
+ void setListener(RecognizerListener listener);
+
+ /**
+ * Creates an embedded grammar.
+ *
+ * @param value value of that grammarType. Could be a URL or an inline grammar.
+ * @return a grammar
+ * @throws IllegalArgumentException if value is null or listener is not of type
+ * GrammarListener.
+ */
+ Grammar createGrammar(String value, GrammarListener listener) throws IllegalArgumentException;
+
+ /**
+ * Begins speech recognition.
+ *
+ * @param audio the audio stream to recognizer
+ * @param grammars a collection of grammar sets to recognize against
+ * @see #recognize(AudioStream, Grammar)
+ * @throws IllegalStateException if any of the grammars are not loaded
+ * @throws IllegalArgumentException if audio is null, in-use by another
+ * component or empty. Or if grammars is null or grammars count is less than
+ * one. Or if the audio codec differs from recognizer codec.
+ * @throws UnsupportedOperationException if the recognizer does not support
+ * the number of grammars specified.
+ */
+ void recognize(AudioStream audio,
+ Vector<Grammar> grammars) throws IllegalStateException,
+ IllegalArgumentException, UnsupportedOperationException;
+
+ /**
+ * This convenience method is equivalent to invoking
+ * recognize(audio, grammars) with a single grammar.
+ *
+ * @param audio the audio to recognizer
+ * @param grammar a grammar to recognize against
+ * @see #recognize(AudioStream, Vector)
+ * @throws IllegalStateException if grammar is not loaded
+ * @throws IllegalArgumentException if audio is null, in-use by another
+ * component or is empty. Or if grammar is null or if the audio codec differs
+ * from the recognizer codec.
+ */
+ void recognize(AudioStream audio, Grammar grammar) throws IllegalStateException,
+ IllegalArgumentException;
+
+ /**
+ * Terminates a recognition if one is in-progress.
+ * This must not be called until the recognize method
+ * returns; otherwise the result is not defined.
+ *
+ * @see RecognizerListener#onStopped
+ */
+ void stop();
+
+ /**
+ * Sets the values of recognition parameters.
+ *
+ * @param parameters the parameter key-value pairs to set
+ */
+ void setParameters(Hashtable<String, String> parameters);
+
+ /**
+ * Retrieves the values of recognition parameters.
+ *
+ * @param parameters the names of the parameters to retrieve
+ */
+ void getParameters(Vector<String> parameters);
+
+}
diff --git a/core/java/android/speech/recognition/RecognizerListener.java b/core/java/android/speech/recognition/RecognizerListener.java
new file mode 100644
index 0000000..d7bbda9
--- /dev/null
+++ b/core/java/android/speech/recognition/RecognizerListener.java
@@ -0,0 +1,142 @@
+/*---------------------------------------------------------------------------*
+ * RecognizerListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Listens for recognizer events.
+ */
+public interface RecognizerListener extends ParametersListener
+{
+ /**
+ * Recognition failure.
+ */
+ public static class FailureReason
+ {
+ /**
+ * The audio did not generate any results.
+ */
+ public static FailureReason NO_MATCH =
+ new FailureReason("The audio did not generate any results");
+ /**
+ * Beginning of speech occured too soon.
+ */
+ public static FailureReason SPOKE_TOO_SOON =
+ new FailureReason("Beginning of speech occurred too soon");
+ /**
+ * A timeout occured before the beginning of speech.
+ */
+ public static FailureReason BEGINNING_OF_SPEECH_TIMEOUT =
+ new FailureReason("A timeout occurred before the beginning of " + "speech");
+ /**
+ * A timeout occured before the recognition could complete.
+ */
+ public static FailureReason RECOGNITION_TIMEOUT =
+ new FailureReason("A timeout occurred before the recognition " +
+ "could complete");
+ /**
+ * The recognizer encountered more audio than was acceptable according to
+ * its configuration.
+ */
+ public static FailureReason TOO_MUCH_SPEECH =
+ new FailureReason("The " +
+ "recognizer encountered more audio than was acceptable according to " +
+ "its configuration");
+
+ public static FailureReason UNKNOWN =
+ new FailureReason("unknown failure reason");
+
+ private final String message;
+
+ private FailureReason(String message)
+ {
+ this.message = message;
+ }
+
+ @Override
+ public String toString()
+ {
+ return message;
+ }
+ }
+
+ /**
+ * Invoked after recognition begins.
+ */
+ void onStarted();
+
+ /**
+ * Invoked if the recognizer detects the beginning of speech.
+ */
+ void onBeginningOfSpeech();
+
+ /**
+ * Invoked if the recognizer detects the end of speech.
+ */
+ void onEndOfSpeech();
+
+ /**
+ * Invoked if the recognizer does not detect speech within the configured
+ * timeout period.
+ */
+ void onStartOfSpeechTimeout();
+
+ /**
+ * Invoked when the recognizer acoustic state is reset.
+ *
+ * @see android.speech.recognition.EmbeddedRecognizer#resetAcousticState()
+ */
+ void onAcousticStateReset();
+
+ /**
+ * Invoked when a recognition result is generated.
+ *
+ * @param result the recognition result. The result object can not be
+ * used outside of the scope of the onRecognitionSuccess() callback method.
+ * To be able to do so, copy it's contents to an user-defined object.<BR>
+ * An example of this object could be a vector of string arrays; where the
+ * vector represents a list of recognition result entries and each entry
+ * is an array of strings to hold the entry's values (the semantic
+ * meaning, confidence score and literal meaning).
+ */
+ void onRecognitionSuccess(RecognitionResult result);
+
+ /**
+ * Invoked when a recognition failure occurs.
+ *
+ * @param reason the failure reason
+ */
+ void onRecognitionFailure(FailureReason reason);
+
+ /**
+ * Invoked when an unexpected error occurs. This is normally followed by
+ * onStopped() if the component shuts down successfully.
+ *
+ * @param e the cause of the failure
+ */
+ void onError(Exception e);
+
+ /**
+ * Invoked when the recognizer stops (due to normal termination or an error).
+ *
+ * Invoking stop() on a recognizer that is already stopped will not result
+ * in a onStopped() event.
+ */
+ void onStopped();
+}
diff --git a/core/java/android/speech/recognition/SlotItem.java b/core/java/android/speech/recognition/SlotItem.java
new file mode 100644
index 0000000..3abd27a
--- /dev/null
+++ b/core/java/android/speech/recognition/SlotItem.java
@@ -0,0 +1,27 @@
+/*---------------------------------------------------------------------------*
+ * SlotItem.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Item that may be inserted into an embedded grammar slot.
+ */
+public interface SlotItem
+{
+}
diff --git a/core/java/android/speech/recognition/SrecGrammar.java b/core/java/android/speech/recognition/SrecGrammar.java
new file mode 100644
index 0000000..c591e05
--- /dev/null
+++ b/core/java/android/speech/recognition/SrecGrammar.java
@@ -0,0 +1,81 @@
+/*---------------------------------------------------------------------------*
+ * SrecGrammar.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+import java.util.Vector;
+
+/**
+ * Grammar on an SREC recognizer.
+ */
+public interface SrecGrammar extends EmbeddedGrammar
+{
+ /**
+ * SrecGrammar Item
+ */
+ public class Item
+ {
+ public SlotItem _item;
+ public int _weight;
+ public String _semanticMeaning;
+
+ /**
+ * Creates a grammar item.
+ *
+ * @param item the Slotitem.
+ * @param weight the weight of the item. Smaller values are more likely to get recognized. This should be >= 0.
+ * @param semanticMeaning the value that will be returned if this item is recognized.
+ * @throws IllegalArgumentException if item or semanticMeaning are null; if semanticMeaning is empty."
+ */
+ public Item(SlotItem item, int weight, String semanticMeaning)
+ throws IllegalArgumentException
+ {
+ if (item == null)
+ throw new IllegalArgumentException("Item(): item can't be null.");
+ if (semanticMeaning == null || semanticMeaning.length()==0)
+ throw new IllegalArgumentException("Item(): semanticMeaning is null or empty.");
+ _item = item;
+ _weight = weight;
+ _semanticMeaning = semanticMeaning;
+
+ }
+ }
+
+ /**
+ * Adds an item to a slot.
+ *
+ * @param slotName the name of the slot
+ * @param item the item to add to the slot.
+ * @param weight the weight of the item. Smaller values are more likely to get recognized. This should be >= 0.
+ * @param semanticMeaning the value that will be returned if this item is recognized.
+ * @throws IllegalArgumentException if slotName, item or semanticMeaning are null; if semanticMeaning is not of the format "V=&#039;Jen_Parker&#039;"
+ */
+ public void addItem(String slotName, SlotItem item, int weight,
+ String semanticMeaning) throws IllegalArgumentException;
+
+ /**
+ * Add a list of item to a slot.
+ *
+ * @param slotName the name of the slot
+ * @param items the vector of SrecGrammar.Item to add to the slot.
+ * @throws IllegalArgumentException if slotName,items are null or any element in the items(_item, _semanticMeaning) is null; if any semanticMeaning of the list is not of the format "key=&#039;value&#039"
+ */
+ public void addItemList(String slotName, Vector<Item> items)
+ throws IllegalArgumentException;
+
+}
diff --git a/core/java/android/speech/recognition/SrecGrammarListener.java b/core/java/android/speech/recognition/SrecGrammarListener.java
new file mode 100644
index 0000000..e1f7d3f
--- /dev/null
+++ b/core/java/android/speech/recognition/SrecGrammarListener.java
@@ -0,0 +1,58 @@
+/*---------------------------------------------------------------------------*
+ * SrecGrammarListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Listens for SrecGrammar events.
+ */
+public interface SrecGrammarListener extends EmbeddedGrammarListener {
+
+ /**
+ * Invokes after all items of the list have been added.
+ */
+ void onAddItemList();
+
+ /**
+ * Invoked when adding a SlotItem from a list fails.
+ * This callback will be trigger for each element in the list that fails to be
+ * add in the slot, unless there is a grammar fail operation, which will be
+ * reported in the onError callback.
+ * @param index of the list that could not be added to the slot
+ * @param e the cause of the failure.
+ */
+ void onAddItemListFailure(int index, Exception e);
+
+
+ /**
+ * Invoked when a grammar related operation fails.
+ *
+ * @param e the cause of the failure.<br/>
+ * {@link GrammarOverflowException} if the grammar slot is full and no
+ * further items may be added to it.<br/>
+ * {@link java.lang.UnsupportedOperationException} if different words with
+ * the same pronunciation are added.<br/>
+ * {@link java.lang.IllegalStateException} if reseting or compiling the
+ * slots fails.<br/>
+ * {@link java.io.IOException} if the grammar could not be loaded or
+ * saved.</p>
+ */
+ void onError(Exception e);
+
+}
diff --git a/core/java/android/speech/recognition/VoicetagItem.java b/core/java/android/speech/recognition/VoicetagItem.java
new file mode 100644
index 0000000..0b89639
--- /dev/null
+++ b/core/java/android/speech/recognition/VoicetagItem.java
@@ -0,0 +1,82 @@
+/*---------------------------------------------------------------------------*
+ * VoicetagItem.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import android.speech.recognition.impl.VoicetagItemImpl;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+/**
+ * Voicetag that may be inserted into an embedded grammar slot.
+ */
+public abstract class VoicetagItem implements SlotItem
+{
+ /**
+ * Creates a VoicetagItem from a file
+ *
+ * @param filename filename for Voicetag
+ * @param listener listens for Voicetag events
+ * @return the resulting VoicetagItem
+ * @throws IllegalArgumentException if filename is null or an empty string.
+ * @throws FileNotFoundException if the specified filename could not be found
+ * @throws IOException if the specified filename could not be opened
+ */
+ public static VoicetagItem create(String filename, VoicetagItemListener listener) throws IllegalArgumentException,FileNotFoundException,IOException
+ {
+ return VoicetagItemImpl.create(filename,listener);
+ }
+ /**
+ * Returns the audio used to construct the VoicetagItem.
+ * The audio is in PCM format and is start-pointed and end-pointed. The audio
+ * is only generated if the enableGetWaveform recognition parameter
+ * is set prior to recognition.
+ *
+ * @throws IllegalStateException if the recognition parameter 'enableGetWaveform' is not set
+ * @return the audio used to construct the VoicetagItem.
+ */
+ public abstract byte[] getAudio() throws IllegalStateException;
+
+ /**
+ * Sets the audio used to construct the Voicetag. The
+ * audio is in PCM format and is start-pointed and end-pointed. The audio is
+ * only generated if the enableGetWaveform recognition parameter is set
+ * prior to recognition.
+ *
+ * @param waveform the endpointed waveform
+ * @throws IllegalArgumentException if waveform is null or empty.
+ * @throws IllegalStateException if the recognition parameter 'enableGetWaveform' is not set
+ */
+ public abstract void setAudio(byte[] waveform) throws IllegalArgumentException,IllegalStateException;
+
+ /**
+ * Save the Voicetag Item.
+ *
+ * @param path where the Voicetag will be saved. We strongly recommend to set the filename with the same value of the VoicetagId.
+ * @throws IllegalArgumentException if path is null or an empty string.
+ */
+ public abstract void save(String path) throws IllegalArgumentException,IllegalStateException;
+
+ /**
+ * Load a Voicetag Item.
+ *
+ * @throws IllegalStateException if voicetag has not been created from a file.
+ */
+ public abstract void load() throws IllegalStateException;
+
+}
diff --git a/core/java/android/speech/recognition/VoicetagItemListener.java b/core/java/android/speech/recognition/VoicetagItemListener.java
new file mode 100644
index 0000000..610d1c7
--- /dev/null
+++ b/core/java/android/speech/recognition/VoicetagItemListener.java
@@ -0,0 +1,49 @@
+/*---------------------------------------------------------------------------*
+ * VoicetagItemListener.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+/**
+ * Listens for VoicetagItem events.
+ */
+public interface VoicetagItemListener
+{
+ /**
+ * Invoked after the Voicetag is saved.
+ *
+ * @param path the path the Voicetag was saved to
+ */
+ void onSaved(String path);
+
+ /**
+ * Invoked after the Voicetag is loaded.
+ */
+ void onLoaded();
+
+ /**
+ * Invoked when a grammar operation fails.
+ *
+ * @param e the cause of the failure.<br/>
+ * {@link java.io.IOException} if the Voicetag could not be loaded or
+ * saved.</p>
+ * {@link java.io.FileNotFoundException} if the specified file could not be found
+ */
+ void onError(Exception e);
+
+}
diff --git a/core/java/android/speech/recognition/WordItem.java b/core/java/android/speech/recognition/WordItem.java
new file mode 100644
index 0000000..5c21c98
--- /dev/null
+++ b/core/java/android/speech/recognition/WordItem.java
@@ -0,0 +1,58 @@
+/*---------------------------------------------------------------------------*
+ * WordItem.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition;
+
+import android.speech.recognition.impl.WordItemImpl;
+
+/**
+ * Word that may be inserted into an embedded grammar slot.
+ */
+public abstract class WordItem implements SlotItem
+{
+ /**
+ * Creates a new WordItem.
+ *
+ * @param word the word to insert
+ * @param pronunciations the pronunciations to associated with the item. If the list is
+ * is empty (example:new String[0]) the recognizer will attempt to guess the pronunciations.
+ * @return the WordItem
+ * @throws IllegalArgumentException if word is null or if pronunciations is
+ * null or pronunciations contains an element equal to null or empty string.
+ */
+ public static WordItem valueOf(String word, String[] pronunciations) throws IllegalArgumentException
+ {
+ return WordItemImpl.valueOf(word, pronunciations);
+ }
+
+ /**
+ * Creates a new WordItem.
+ *
+ * @param word the word to insert
+ * @param pronunciation the pronunciation to associate with the item. If it
+ * is null the recognizer will attempt to guess the pronunciations.
+ * @return the WordItem
+ * @throws IllegalArgumentException if word is null or if pronunciation is
+ * an empty string
+ */
+ public static WordItem valueOf(String word, String pronunciation) throws IllegalArgumentException
+ {
+ return WordItemImpl.valueOf(word, pronunciation);
+ }
+}
diff --git a/core/java/android/speech/recognition/impl/AudioStreamImpl.java b/core/java/android/speech/recognition/impl/AudioStreamImpl.java
new file mode 100644
index 0000000..730e2d9
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/AudioStreamImpl.java
@@ -0,0 +1,84 @@
+/*---------------------------------------------------------------------------*
+ * AudioStreamImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.AudioStream;
+
+/**
+ */
+public class AudioStreamImpl implements AudioStream, Runnable
+{
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+
+ /**
+ * Creates a new AudioStreamImpl.
+ *
+ * @param nativeObj a reference to the native object
+ */
+ public AudioStreamImpl(long nativeObj)
+ {
+ nativeObject = nativeObj;
+ }
+
+ public synchronized void run()
+ {
+ dispose();
+ }
+
+ public long getNativeObject() {
+ synchronized (AudioStreamImpl.class)
+ {
+ return nativeObject;
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ @SuppressWarnings("deprecation")
+ public void dispose()
+ {
+ synchronized (AudioStreamImpl.class)
+ {
+ if (nativeObject != 0)
+ {
+ deleteNativeObject(nativeObject);
+ nativeObject = 0;
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ /**
+ * Deletes a native object.
+ *
+ * @param nativeObject pointer to the native object
+ */
+ private native void deleteNativeObject(long nativeObject);
+}
diff --git a/core/java/android/speech/recognition/impl/DeviceSpeakerImpl.java b/core/java/android/speech/recognition/impl/DeviceSpeakerImpl.java
new file mode 100644
index 0000000..5d72110
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/DeviceSpeakerImpl.java
@@ -0,0 +1,164 @@
+/*---------------------------------------------------------------------------*
+ * DeviceSpeakerImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.AudioStream;
+import android.speech.recognition.Codec;
+import android.speech.recognition.DeviceSpeaker;
+import android.speech.recognition.DeviceSpeakerListener;
+
+/**
+ */
+public class DeviceSpeakerImpl extends DeviceSpeaker implements Runnable
+{
+ private static DeviceSpeakerImpl instance;
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+ private DeviceSpeakerListener locallistener;
+
+ /**
+ * Private constructor
+ */
+ private DeviceSpeakerImpl()
+ {
+ System system = System.getInstance();
+ nativeObject = initNativeObject();
+ if (nativeObject != 0)
+ system.register(this);
+ }
+
+ public void run()
+ {
+ dispose();
+ }
+
+ /**
+ * Returns the singleton instance.
+ *
+ * @return the singleton instance
+ */
+ public static DeviceSpeakerImpl getInstance()
+ {
+ synchronized (DeviceSpeakerImpl.class)
+ {
+ if (instance == null)
+ instance = new DeviceSpeakerImpl();
+ return instance;
+ }
+ }
+
+ /**
+ * Start audio playback.
+ *
+ * @param source the audio to play
+ */
+ public void start(AudioStream source)
+ {
+ synchronized (DeviceSpeakerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ AudioStreamImpl src = (AudioStreamImpl)source;
+ startProxy(nativeObject,src.getNativeObject());
+ src = null;
+ }
+ }
+
+ /**
+ * Stops audio playback.
+ */
+ public void stop()
+ {
+ synchronized (DeviceSpeakerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ stopProxy(nativeObject);
+ }
+ }
+
+ /**
+ * Set the playback codec. This must be called before start is called.
+ * @param playbackCodec the codec to use for the playback operation.
+ */
+ public void setCodec(Codec playbackCodec)
+ {
+ synchronized (DeviceSpeakerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ setCodecProxy(nativeObject,playbackCodec);
+ }
+ }
+
+ /**
+ * set the microphone listener.
+ * @param listener the device speaker listener.
+ */
+ public void setListener(DeviceSpeakerListener listener)
+ {
+ synchronized (DeviceSpeakerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ locallistener = listener;
+ setListenerProxy(nativeObject,listener);
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ private void dispose()
+ {
+ synchronized (DeviceSpeakerImpl.class)
+ {
+ if (nativeObject != 0)
+ {
+ deleteNativeObject(nativeObject);
+ nativeObject = 0;
+ instance = null;
+ locallistener = null;
+ System.getInstance().unregister(this);
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ private native long initNativeObject();
+
+ private native void startProxy(long nativeObject, long audioNativeObject);
+
+ private native void stopProxy(long nativeObject);
+
+ private native void setCodecProxy(long nativeObject,Codec playbackCodec);
+
+ private native void setListenerProxy(long nativeObject,DeviceSpeakerListener listener);
+
+ private native void deleteNativeObject(long nativeObject);
+}
diff --git a/core/java/android/speech/recognition/impl/EmbeddedGrammarImpl.java b/core/java/android/speech/recognition/impl/EmbeddedGrammarImpl.java
new file mode 100644
index 0000000..0b88cb2
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/EmbeddedGrammarImpl.java
@@ -0,0 +1,73 @@
+/*---------------------------------------------------------------------------*
+ * EmbeddedGrammarImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.EmbeddedGrammar;
+
+/**
+ */
+public class EmbeddedGrammarImpl extends GrammarImpl implements EmbeddedGrammar
+{
+ /**
+ * Creates a new EmbeddedGrammarImpl.
+ *
+ * @param nativeObject a reference to the native object
+ */
+ public EmbeddedGrammarImpl(long nativeObject)
+ {
+ super(nativeObject);
+ }
+
+ public void compileAllSlots()
+ {
+ synchronized (GrammarImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ compileAllSlotsProxy(nativeObject);
+ }
+ }
+
+ public void resetAllSlots()
+ {
+ synchronized (GrammarImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ resetAllSlotsProxy(nativeObject);
+ }
+ }
+
+ public void save(String url)
+ {
+ synchronized (GrammarImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ saveProxy(nativeObject, url.toString());
+ }
+ }
+
+ private native void compileAllSlotsProxy(long nativeObject);
+
+ private native void resetAllSlotsProxy(long nativeObject);
+
+ private native void saveProxy(long nativeObject, String url);
+}
diff --git a/core/java/android/speech/recognition/impl/EmbeddedRecognizerImpl.java b/core/java/android/speech/recognition/impl/EmbeddedRecognizerImpl.java
new file mode 100644
index 0000000..f04bfe4
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/EmbeddedRecognizerImpl.java
@@ -0,0 +1,246 @@
+/*---------------------------------------------------------------------------*
+ * EmbeddedRecognizerImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.Vector;
+import android.speech.recognition.EmbeddedRecognizer;
+import android.speech.recognition.Grammar;
+import android.speech.recognition.AudioStream;
+import android.speech.recognition.Grammar;
+import android.speech.recognition.RecognizerListener;
+import android.speech.recognition.GrammarListener;
+
+/**
+ */
+public class EmbeddedRecognizerImpl extends EmbeddedRecognizer implements Runnable
+{
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+ /**
+ * The singleton instance.
+ */
+ private static EmbeddedRecognizerImpl instance;
+
+ /**
+ * Creates a new instance.
+ */
+ EmbeddedRecognizerImpl()
+ {
+ System system = System.getInstance();
+ nativeObject = getInstanceProxy();
+ if (nativeObject != 0)
+ system.register(this);
+ }
+
+ /**
+ * Returns the singleton instance.
+ *
+ * @return the singleton instance
+ */
+ public synchronized static EmbeddedRecognizerImpl getInstance()
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (instance == null)
+ instance = new EmbeddedRecognizerImpl();
+ return instance;
+ }
+ }
+
+ public void run()
+ {
+ dispose();
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ private void dispose()
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (instance != null)
+ {
+ deleteNativeObject(nativeObject);
+ nativeObject = 0;
+ instance = null;
+ System.getInstance().unregister(this);
+ }
+ }
+ }
+
+ public void configure(String config) throws IllegalArgumentException,
+ FileNotFoundException, IOException, UnsatisfiedLinkError,
+ ClassNotFoundException
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ if (config == null)
+ throw new IllegalArgumentException("Configuration Is Null.");
+ configureProxy(nativeObject,config);
+ }
+ }
+
+ public void setListener(RecognizerListener listener)
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ setListenerProxy(nativeObject,listener);
+ }
+ }
+
+ public Grammar createGrammar(String value, GrammarListener listener)
+ throws IllegalArgumentException
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ long nativeGrammar = createEmbeddedGrammarProxy(nativeObject,value.toString(), listener);
+ return new SrecGrammarImpl(nativeGrammar);
+ }
+ }
+
+ public void resetAcousticState()
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ resetAcousticStateProxy(nativeObject);
+ }
+ }
+
+ public void recognize(AudioStream audio,
+ Vector<Grammar> grammars)
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+
+ if (audio == null)
+ throw new IllegalArgumentException("AudioStream cannot be null.");
+
+ if (grammars == null || grammars.isEmpty() == true)
+ throw new IllegalArgumentException("Grammars are null or empty.");
+ int grammarCount = grammars.size();
+
+ long[] nativeGrammars = new long[grammarCount];
+
+ for (int i = 0; i < grammarCount; ++i)
+ nativeGrammars[i] = ((GrammarImpl) grammars.get(i)).getNativeObject();
+
+ recognizeProxy(nativeObject,((AudioStreamImpl)audio).getNativeObject(), nativeGrammars);
+ }
+ }
+
+ public void recognize(AudioStream audio,
+ Grammar grammar)
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ }
+ Vector<Grammar> grammars = new Vector<Grammar>();
+ grammars.add(grammar);
+ recognize(audio, grammars);
+ }
+
+ public void stop()
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ stopProxy(nativeObject);
+ }
+ }
+
+ public void setParameters(Hashtable<String, String> params)
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ setParametersProxy(nativeObject,params);
+ }
+ }
+
+ public void getParameters(Vector<String> params)
+ {
+ synchronized (EmbeddedRecognizerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ getParametersProxy(nativeObject,params);
+ }
+ }
+
+ /**
+ * Returns the native EmbeddedRecognizer.
+ *
+ * @return a reference to the native object
+ */
+ private native long getInstanceProxy();
+
+ /**
+ * Configures the recognizer instance.
+ *
+ * @param config the recognizer configuration file
+ */
+ private native void configureProxy(long nativeObject, String config) throws IllegalArgumentException,
+ FileNotFoundException, IOException, UnsatisfiedLinkError,
+ ClassNotFoundException;
+
+ /**
+ * Sets the recognizer listener.
+ *
+ * @param listener listens for recognizer events
+ */
+ private native void setListenerProxy(long nativeObject, RecognizerListener listener);
+
+ private native void recognizeProxy(long nativeObject, long audioNativeObject,
+ long[] pGrammars);
+
+ private native long createEmbeddedGrammarProxy(long nativeObject, String url,
+ GrammarListener listener);
+
+ private native void stopProxy(long nativeObject);
+
+ private native void deleteNativeObject(long nativeObject);
+
+ private native void setParametersProxy(long nativeObject, Hashtable<String, String> params);
+
+ private native void getParametersProxy(long nativeObject, Vector<String> params);
+
+ private native void resetAcousticStateProxy(long nativeObject);
+
+}
diff --git a/core/java/android/speech/recognition/impl/EntryImpl.java b/core/java/android/speech/recognition/impl/EntryImpl.java
new file mode 100644
index 0000000..91b2b78
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/EntryImpl.java
@@ -0,0 +1,147 @@
+/*---------------------------------------------------------------------------*
+ * EntryImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.NBestRecognitionResult;
+import java.util.Enumeration;
+
+/**
+ */
+public class EntryImpl implements NBestRecognitionResult.Entry, Runnable
+{
+ private long nativeObject;
+
+ /**
+ * This implementation is a work-around to solve Q bug with
+ * nested classes.
+ *
+ * @param nativeObject the native NBestRecognitionResult.Entry object
+ */
+ public EntryImpl(long nativeObject)
+ {
+ this.nativeObject = nativeObject;
+ }
+
+ public void run()
+ {
+ dispose();
+ }
+
+ public byte getConfidenceScore() throws IllegalStateException
+ {
+ synchronized (EntryImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ return getConfidenceScoreProxy(nativeObject);
+ }
+ }
+
+ public String getLiteralMeaning() throws IllegalStateException
+ {
+ synchronized (EntryImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ return getLiteralMeaningProxy(nativeObject);
+ }
+ }
+
+ public String getSemanticMeaning() throws IllegalStateException
+ {
+ synchronized (EntryImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ return getSemanticMeaningProxy(nativeObject);
+ }
+ }
+
+ public String get(String key)
+ {
+ synchronized (EntryImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ return getProxy(nativeObject,key);
+ }
+ }
+
+ public Enumeration keys()
+ {
+ synchronized (EntryImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+
+ return new Enumeration()
+ {
+ private String[] keys = keysProxy(nativeObject);
+ private int indexOfNextRead = 0;
+
+ public boolean hasMoreElements()
+ {
+ return indexOfNextRead <= keys.length-1;
+ }
+
+ public Object nextElement()
+ {
+ return keys[indexOfNextRead++];
+ }
+ };
+ }
+ }
+
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ private void dispose()
+ {
+ synchronized (EntryImpl.class)
+ {
+ if (nativeObject != 0)
+ {
+ deleteNativeObject(nativeObject);
+ nativeObject = 0;
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ private native void deleteNativeObject(long nativeObject);
+
+ private native String getLiteralMeaningProxy(long nativeObject);
+
+ private native String getSemanticMeaningProxy(long nativeObject);
+
+ private native byte getConfidenceScoreProxy(long nativeObject);
+
+ private native String getProxy(long nativeObject,String key);
+
+ private native String[] keysProxy(long nativeObject);
+
+}
diff --git a/core/java/android/speech/recognition/impl/GrammarImpl.java b/core/java/android/speech/recognition/impl/GrammarImpl.java
new file mode 100644
index 0000000..563d5d9
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/GrammarImpl.java
@@ -0,0 +1,114 @@
+/*---------------------------------------------------------------------------*
+ * GrammarImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.Grammar;
+
+/**
+ */
+public class GrammarImpl implements Grammar, Runnable
+{
+ /**
+ * Reference to the native object.
+ */
+ protected long nativeObject;
+
+ /**
+ * Creates a new GrammarImpl.
+ *
+ * @param nativeObj a reference to the native object
+ */
+ public GrammarImpl(long nativeObj)
+ {
+ nativeObject = nativeObj;
+ }
+
+ public void run()
+ {
+ dispose();
+ }
+
+ public long getNativeObject()
+ {
+ synchronized (GrammarImpl.class)
+ {
+ return nativeObject;
+ }
+ }
+
+ /**
+ * Indicates that the grammar will be used in the near future.
+ */
+ public void load()
+ {
+ synchronized (GrammarImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ loadProxy(nativeObject);
+ }
+ }
+
+ /**
+ * The grammar will be removed from use.
+ */
+ public void unload()
+ {
+ synchronized (GrammarImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ unloadProxy(nativeObject);
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ public void dispose()
+ {
+ synchronized (GrammarImpl.class)
+ {
+ if (nativeObject != 0)
+ {
+ deleteNativeObject(nativeObject);
+ nativeObject = 0;
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ /**
+ * Deletes a native object.
+ *
+ * @param nativeObject pointer to the native object
+ */
+ private native void deleteNativeObject(long nativeObject);
+
+ private native void loadProxy(long nativeObject);
+
+ private native void unloadProxy(long nativeObject);
+}
diff --git a/core/java/android/speech/recognition/impl/LoggerImpl.java b/core/java/android/speech/recognition/impl/LoggerImpl.java
new file mode 100644
index 0000000..9933c56
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/LoggerImpl.java
@@ -0,0 +1,166 @@
+/*---------------------------------------------------------------------------*
+ * LoggerImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.Logger;
+
+/**
+ */
+public class LoggerImpl extends Logger implements Runnable
+{
+ private static LoggerImpl instance;
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+
+ /**
+ * Creates a new instance of LoggerImpl.
+ *
+ * @param function the name of the enclosing function
+ */
+ private LoggerImpl()
+ {
+ System system = System.getInstance();
+ nativeObject = initNativeObject();
+ if (nativeObject!=0)
+ system.register(this);
+ }
+
+ public void run()
+ {
+ dispose();
+ }
+
+ /**
+ * Returns the singleton instance.
+ *
+ * @return the singleton instance
+ */
+ public static LoggerImpl getInstance()
+ {
+ synchronized (LoggerImpl.class)
+ {
+ if (instance == null)
+ instance = new LoggerImpl();
+ return instance;
+ }
+ }
+
+ public void setLoggingLevel(LogLevel level)
+ {
+ synchronized (LoggerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ setLoggingLevelProxy(nativeObject,level);
+ }
+ }
+
+ public void setPath(String path)
+ {
+ synchronized (LoggerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ setPathProxy(nativeObject,path);
+ }
+ }
+
+ public void error(String message)
+ {
+ synchronized (LoggerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ errorProxy(nativeObject,message);
+ }
+ }
+
+ public void warn(String message)
+ {
+ synchronized (LoggerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ warnProxy(nativeObject,message);
+ }
+ }
+
+ public void info(String message)
+ {
+ synchronized (LoggerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ infoProxy(nativeObject,message);
+ }
+ }
+
+ public void trace(String message)
+ {
+ synchronized (LoggerImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ traceProxy(nativeObject,message);
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ private void dispose()
+ {
+ synchronized (LoggerImpl.class)
+ {
+ if (nativeObject!=0)
+ {
+ deleteNativeObject(nativeObject);
+ System.getInstance().unregister(this);
+ }
+ nativeObject = 0;
+ instance = null;
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ private native long initNativeObject();
+
+ private native void setLoggingLevelProxy(long nativeObject, LogLevel level);
+
+ private native void setPathProxy(long nativeObject, String filename);
+
+ private native void errorProxy(long nativeObject, String message);
+
+ private native void warnProxy(long nativeObject, String message);
+
+ private native void infoProxy(long nativeObject, String message);
+
+ private native void traceProxy(long nativeObject,String message);
+
+ private native void deleteNativeObject(long nativeObject);
+}
diff --git a/core/java/android/speech/recognition/impl/MediaFileReaderImpl.java b/core/java/android/speech/recognition/impl/MediaFileReaderImpl.java
new file mode 100644
index 0000000..8ce643d
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/MediaFileReaderImpl.java
@@ -0,0 +1,156 @@
+/*---------------------------------------------------------------------------*
+ * MediaFileReaderImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.MediaFileReader;
+import android.speech.recognition.AudioStream;
+import android.speech.recognition.Codec;
+import android.speech.recognition.AudioSourceListener;
+
+/**
+ */
+public class MediaFileReaderImpl extends MediaFileReader implements Runnable
+{
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+
+ /**
+ * Creates a new MediaFileReaderImpl.
+ *
+ * @param filename the name of the file to read from
+ * @param listener listens for MediaFileReader events
+ */
+ public MediaFileReaderImpl(String filename, AudioSourceListener listener)
+ {
+ System system = System.getInstance();
+ nativeObject =
+ createMediaFileReaderProxy(filename, listener);
+ if (nativeObject != 0)
+ system.register(this);
+ }
+
+ public void run()
+ {
+ dispose();
+ }
+
+ /**
+ * Set the reading mode
+ */
+ public void setMode(Mode mode)
+ {
+ synchronized (MediaFileReaderImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ setModeProxy(nativeObject,mode);
+ }
+ }
+
+ /**
+ * Creates an audioStream source
+ */
+ public AudioStream createAudio()
+ {
+ synchronized (MediaFileReaderImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ return new AudioStreamImpl(createAudioProxy(nativeObject));
+ }
+ }
+
+ /**
+ * Tells the audio source to start collecting audio samples.
+ */
+ public void start()
+ {
+ synchronized (MediaFileReaderImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ startProxy(nativeObject);
+ }
+ }
+
+ /**
+ * Stops this source from collecting audio samples.
+ */
+ public void stop()
+ {
+ synchronized (MediaFileReaderImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ stopProxy(nativeObject);
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ public void dispose()
+ {
+ synchronized (MediaFileReaderImpl.class)
+ {
+ if (nativeObject != 0)
+ {
+ deleteNativeObject(nativeObject);
+ nativeObject = 0;
+ System.getInstance().unregister(this);
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ /**
+ * Deletes a native object.
+ *
+ * @param nativeObject pointer to the native object
+ */
+ private native void deleteNativeObject(long nativeObject);
+
+ /**
+ * Creates a native MediaFileReader.
+ *
+ * @param filename the name of the file to read from
+ * @param offset the offset to begin reading from
+ * @param codec the file audio format
+ * @param listener listens for MediaFileReader events
+ * @return a reference to the native object
+ */
+ private native long createMediaFileReaderProxy(String filename, AudioSourceListener listener);
+
+ private native void setModeProxy(long nativeObject,Mode mode);
+
+ private native long createAudioProxy(long nativeObject);
+
+ private native void startProxy(long nativeObject);
+
+ private native void stopProxy(long nativeObject);
+}
diff --git a/core/java/android/speech/recognition/impl/MediaFileWriterImpl.java b/core/java/android/speech/recognition/impl/MediaFileWriterImpl.java
new file mode 100644
index 0000000..c4bd836
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/MediaFileWriterImpl.java
@@ -0,0 +1,102 @@
+/*---------------------------------------------------------------------------*
+ * MediaFileWriterImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.AudioStream;
+import android.speech.recognition.MediaFileWriter;
+import android.speech.recognition.MediaFileWriterListener;
+
+/**
+ */
+public class MediaFileWriterImpl extends MediaFileWriter implements Runnable
+{
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+
+ /**
+ * Creates a new MediaFileWriterImpl.
+ *
+ * @param listener listens for MediaFileWriter events
+ */
+ public MediaFileWriterImpl(MediaFileWriterListener listener)
+ {
+ System system = System.getInstance();
+ nativeObject = createMediaFileWriterProxy(listener);
+ if (nativeObject != 0)
+ system.register(this);
+ }
+
+ public void run()
+ {
+ dispose();
+ }
+
+ public void save(AudioStream source, String filename)
+ {
+ synchronized (MediaFileWriterImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ saveProxy(nativeObject,((AudioStreamImpl)source).getNativeObject(), filename);
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ public synchronized void dispose()
+ {
+ synchronized (MediaFileWriterImpl.class)
+ {
+ if (nativeObject != 0)
+ {
+ deleteNativeObject(nativeObject);
+ nativeObject = 0;
+ System.getInstance().unregister(this);
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ /**
+ * Creates a native MediaFileWriter.
+ *
+ * @param listener listens for MediaFileReader events
+ * @return a reference to the native object
+ */
+ private native long createMediaFileWriterProxy(MediaFileWriterListener listener);
+
+ /**
+ * Deletes a native object.
+ *
+ * @param nativeObject pointer to the native object
+ */
+ private native void deleteNativeObject(long nativeObject);
+
+ private native void saveProxy(long nativeObject, long audioNativeObject, String filename);
+}
diff --git a/core/java/android/speech/recognition/impl/MicrophoneImpl.java b/core/java/android/speech/recognition/impl/MicrophoneImpl.java
new file mode 100644
index 0000000..a915484
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/MicrophoneImpl.java
@@ -0,0 +1,165 @@
+/*---------------------------------------------------------------------------*
+ * MicrophoneImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.AudioStream;
+import android.speech.recognition.Codec;
+import android.speech.recognition.Microphone;
+import android.speech.recognition.AudioSourceListener;
+
+/**
+ */
+public class MicrophoneImpl extends Microphone implements Runnable
+{
+ private static MicrophoneImpl instance;
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+
+ /**
+ * Creates a new MicrophoneImpl.
+ *
+ * @param nativeObj a reference to the native object
+ */
+ private MicrophoneImpl()
+ {
+ System system = System.getInstance();
+ nativeObject = initNativeObject();
+ if (nativeObject != 0)
+ system.register(this);
+ }
+
+ public void run()
+ {
+ dispose();
+ }
+
+ /**
+ * Returns the singleton instance.
+ *
+ * @return the singleton instance
+ */
+ public static MicrophoneImpl getInstance()
+ {
+ synchronized (MicrophoneImpl.class)
+ {
+ if (instance == null)
+ instance = new MicrophoneImpl();
+ return instance;
+ }
+ }
+
+ /**
+ * set the recording codec. This must be called before Start is called.
+ * @param recordingCodec the codec in which the samples will be recorded.
+ */
+ public void setCodec(Codec recordingCodec)
+ {
+ synchronized (MicrophoneImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ setCodecProxy(nativeObject,recordingCodec);
+ }
+ }
+
+ /**
+ * set the microphone listener.
+ * @param listener the microphone listener.
+ */
+ public void setListener(AudioSourceListener listener)
+ {
+ synchronized (MicrophoneImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ setListenerProxy(nativeObject,listener);
+ }
+ }
+
+ public AudioStream createAudio()
+ {
+ synchronized (MicrophoneImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ return new AudioStreamImpl(createAudioProxy(nativeObject));
+ }
+ }
+
+ public void start()
+ {
+ synchronized (MicrophoneImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ startProxy(nativeObject);
+ }
+ }
+
+ public void stop()
+ {
+ synchronized (MicrophoneImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ stopProxy(nativeObject);
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ private void dispose()
+ {
+ synchronized (MicrophoneImpl.class)
+ {
+ if (nativeObject != 0)
+ {
+ deleteNativeObject(nativeObject);
+ nativeObject = 0;
+ instance = null;
+ System.getInstance().unregister(this);
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ private native long initNativeObject();
+
+ private native void setCodecProxy(long nativeObject,Codec recordingCodec);
+
+ private native void setListenerProxy(long nativeObject, AudioSourceListener listener);
+
+ private native long createAudioProxy(long nativeObject);
+
+ private native void startProxy(long nativeObject);
+
+ private native void stopProxy(long nativeObject);
+
+ private native void deleteNativeObject(long nativeObject);
+}
diff --git a/core/java/android/speech/recognition/impl/NBestRecognitionResultImpl.java b/core/java/android/speech/recognition/impl/NBestRecognitionResultImpl.java
new file mode 100644
index 0000000..4d2e00a
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/NBestRecognitionResultImpl.java
@@ -0,0 +1,106 @@
+/*---------------------------------------------------------------------------*
+ * NBestRecognitionResultImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.NBestRecognitionResult;
+import android.speech.recognition.VoicetagItem;
+import android.speech.recognition.VoicetagItemListener;
+/**
+ */
+public class NBestRecognitionResultImpl implements NBestRecognitionResult
+{
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+
+ /**
+ * Creates a new NBestRecognitionResultImpl.
+ *
+ * @param nativeObject a reference to the native object
+ */
+ public NBestRecognitionResultImpl(long nativeObject)
+ {
+ this.nativeObject = nativeObject;
+ }
+
+ public int getSize()
+ {
+ synchronized (NBestRecognitionResultImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ return getSizeProxy(nativeObject);
+ }
+ }
+
+ public Entry getEntry(int index)
+ {
+ synchronized (NBestRecognitionResultImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ long nativeEntryObject = getEntryProxy(nativeObject,index);
+ if (nativeEntryObject==0)
+ return null;
+ else
+ return new EntryImpl(nativeEntryObject);
+ }
+ }
+
+ public VoicetagItem createVoicetagItem(String VoicetagId, VoicetagItemListener listener)
+ {
+ synchronized (NBestRecognitionResultImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+ if ((VoicetagId == null) || (VoicetagId.length() == 0))
+ throw new IllegalArgumentException("VoicetagId may not be null or empty string.");
+ return new VoicetagItemImpl(createVoicetagItemProxy(nativeObject,VoicetagId,listener),false);
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ private void dispose()
+ {
+ synchronized (NBestRecognitionResultImpl.class)
+ {
+ nativeObject = 0;
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ /**
+ * Returns a reference to the native VoicetagItem.
+ */
+ private native long createVoicetagItemProxy(long nativeObject, String VoicetagId, VoicetagItemListener listener);
+
+ private native long getEntryProxy(long nativeObject, int index);
+
+ private native int getSizeProxy(long nativeObject);
+}
diff --git a/core/java/android/speech/recognition/impl/SrecGrammarImpl.java b/core/java/android/speech/recognition/impl/SrecGrammarImpl.java
new file mode 100644
index 0000000..cb6f4c6
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/SrecGrammarImpl.java
@@ -0,0 +1,120 @@
+/*---------------------------------------------------------------------------*
+ * SrecGrammarImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.SrecGrammar;
+import android.speech.recognition.SlotItem;
+import android.speech.recognition.VoicetagItem;
+import android.speech.recognition.WordItem;
+
+import java.util.Vector;
+
+/**
+ */
+public class SrecGrammarImpl extends EmbeddedGrammarImpl implements SrecGrammar
+{
+ /**
+ * Creates a new SrecGrammarImpl.
+ *
+ * @param nativeObject the native object
+ */
+ public SrecGrammarImpl(long nativeObject)
+ {
+ super(nativeObject);
+ }
+
+ public void addItem(String slotName, SlotItem item, int weight,
+ String semanticValue)
+ {
+ synchronized (GrammarImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+
+ if (slotName == null || slotName.length()==0)
+ throw new IllegalArgumentException("addItem() - Slot name is null or empty.");
+ if (item == null)
+ throw new IllegalArgumentException("addItem() - item can't be null.");
+ if (semanticValue == null || semanticValue.length()==0)
+ throw new IllegalArgumentException("addItem() - semanticValue is null or empty.");
+
+ long itemNativeObject = 0;
+ if (item instanceof VoicetagItem)
+ itemNativeObject = ((VoicetagItemImpl)item).getNativeObject();
+ else if (item instanceof WordItem)
+ itemNativeObject = ((WordItemImpl)item).getNativeObject();
+ else
+ throw new IllegalArgumentException("SlotItem - should be a WordItem or a VoicetagItem object.");
+
+ addItemProxy(nativeObject, slotName, itemNativeObject, weight, semanticValue);
+ }
+ }
+
+ public void addItemList(String slotName, Vector<Item> items)
+ {
+ synchronized (GrammarImpl.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object has been disposed");
+
+ if (slotName == null || slotName.length()==0)
+ throw new IllegalArgumentException("addItemList - Slot name is null or empty.");
+ if (items == null || items.isEmpty() == true)
+ throw new IllegalArgumentException("addItemList - Items is null or empty.");
+
+ int itemsCount = items.size();
+
+ long[] nativeSlots = new long[itemsCount];
+ int[] nativeWeights = new int[itemsCount];
+ String[] nativeSemantic = new String[itemsCount];
+
+ Item element = null;
+ long itemNativeObject = 0;
+ SlotItem item = null;
+ for (int i = 0; i < itemsCount; ++i)
+ {
+ element = items.get(i);
+
+ item = element._item;
+ if (item instanceof VoicetagItem)
+ itemNativeObject = ((VoicetagItemImpl)item).getNativeObject();
+ else if (item instanceof WordItem)
+ itemNativeObject = ((WordItemImpl)item).getNativeObject();
+ else
+ {
+ throw new IllegalArgumentException("SlotItem ["+i+"] - should be a WordItem or a VoicetagItem object.");
+ }
+ nativeSlots[i] = itemNativeObject;
+ nativeWeights[i] = element._weight;
+ nativeSemantic[i]= element._semanticMeaning;
+ itemNativeObject = 0;
+ item = null;
+ }
+ addItemListProxy(nativeObject, slotName,nativeSlots,nativeWeights,nativeSemantic);
+ }
+ }
+
+ private native void addItemProxy(long nativeObject, String slotName, long item, int weight,
+ String semanticValue);
+
+ private native void addItemListProxy(long nativeObject, String slotName, long[] items,
+ int[] weights, String[] semanticValues);
+
+}
diff --git a/core/java/android/speech/recognition/impl/System.java b/core/java/android/speech/recognition/impl/System.java
new file mode 100644
index 0000000..23418fe
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/System.java
@@ -0,0 +1,179 @@
+/*---------------------------------------------------------------------------*
+ * System.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import java.lang.ref.WeakReference;
+import java.util.WeakHashMap;
+
+
+/**
+ */
+public class System
+{
+ private static boolean libraryLoaded;
+ private static System instance;
+ private static WeakHashMap<Object, WeakReference> registerMap;
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+ private boolean shutdownRequested;
+
+ /**
+ * Creates a new instance of System
+ */
+ private System()
+ {
+ shutdownRequested = false;
+ registerMap =
+ new WeakHashMap<Object, WeakReference>();
+ initLibrary();
+ nativeObject = initNativeObject();
+ Runtime.getRuntime().
+ addShutdownHook(new Thread()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ dispose();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ }
+
+ /**
+ * Returns the singleton instance.
+ *
+ * @return the singleton instance
+ */
+ public static System getInstance()
+ {
+ synchronized (System.class)
+ {
+ if (instance == null)
+ instance = new System();
+ return instance;
+ }
+ }
+
+ /**
+ * Loads the native library if necessary.
+ */
+ private void initLibrary()
+ {
+ if (!libraryLoaded)
+ {
+ java.lang.System.loadLibrary("UAPI_jni");
+ libraryLoaded = true;
+ }
+ }
+
+ /**
+ * Registers an object for shutdown when System.dispose() is invoked.
+ *
+ * @param r the code to run on shutdown
+ * @throws IllegalStateException if the System is shutting down
+ */
+ public void register(Runnable r) throws IllegalStateException
+ {
+ synchronized (System.class)
+ {
+ if (shutdownRequested)
+ throw new IllegalStateException("System is shutting down");
+ registerMap.put(r,
+ new WeakReference<Runnable>(r));
+ }
+ }
+
+ /**
+ * Registers an object for shutdown when System.dispose() is invoked.
+ *
+ * @param r the code to run on shutdown
+ */
+ public void unregister(Runnable r)
+ {
+ synchronized (System.class)
+ {
+ if (shutdownRequested)
+ {
+ // System.dispose() will end up removing all entries
+ return;
+ }
+ if (r!=null) registerMap.remove(r);
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ *
+ * @throws java.util.concurrent.TimeoutException if the operation timeouts
+ * @throws IllegalThreadStateException if a native thread error occurs
+ */
+ public void dispose() throws java.util.concurrent.TimeoutException,
+ IllegalThreadStateException
+ {
+ synchronized (System.class)
+ {
+ if (nativeObject == 0)
+ return;
+ shutdownRequested = true;
+ }
+
+ // Traverse the list of WeakReferences
+ // cast to a Runnable object if the weakrerefence is not null
+ // then call the run method.
+ for (Object o: registerMap.keySet())
+ {
+ WeakReference weakReference = registerMap.get(o);
+ Runnable r = (Runnable) weakReference.get();
+ if (r != null)
+ r.run();
+ }
+ registerMap.clear();
+
+ // Call the native dispose method
+ disposeProxy();
+ synchronized (System.class)
+ {
+ nativeObject = 0;
+ instance = null;
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ public static native String getAPIVersion();
+
+ private static native long initNativeObject();
+
+ private static native void disposeProxy();
+}
diff --git a/core/java/android/speech/recognition/impl/VoicetagItemImpl.java b/core/java/android/speech/recognition/impl/VoicetagItemImpl.java
new file mode 100644
index 0000000..f9db399
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/VoicetagItemImpl.java
@@ -0,0 +1,206 @@
+/*---------------------------------------------------------------------------*
+ * VoicetagItemImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.VoicetagItem;
+import android.speech.recognition.VoicetagItemListener;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+/**
+ */
+public class VoicetagItemImpl extends VoicetagItem implements Runnable
+{
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+ /**
+ * Voicetag has a filename need to be loaded before use it.
+ */
+ private boolean needToBeLoaded;
+
+ /**
+ * Creates a new VoicetagItemImpl.
+ *
+ * @param nativeObject the pointer to the native object
+ */
+ public VoicetagItemImpl(long nativeObject, boolean fromfile)
+ {
+ this.nativeObject = nativeObject;
+ needToBeLoaded = fromfile;
+ }
+
+ public void run()
+ {
+ dispose();
+ }
+
+ /**
+ * Creates a VoicetagItem from a file
+ *
+ * @param filename filename for Voicetag
+ * @param listener listens for Voicetag events
+ * @return the resulting VoicetagItem
+ * @throws IllegalArgumentException if filename is null or an empty string.
+ * @throws FileNotFoundException if the specified filename could not be found
+ * @throws IOException if the specified filename could not be opened
+ */
+ public static VoicetagItem create(String filename, VoicetagItemListener listener) throws IllegalArgumentException,FileNotFoundException,IOException
+ {
+ if ((filename == null) || (filename.length() == 0))
+ throw new IllegalArgumentException("Filename may not be null or empty string.");
+
+ VoicetagItemImpl voicetag = null;
+ long nativeVoicetag = createVoicetagProxy(filename,listener);
+ if (nativeVoicetag!=0)
+ {
+ voicetag = new VoicetagItemImpl(nativeVoicetag,true);
+ }
+ return voicetag;
+ }
+ /**
+ * Returns the audio used to construct the VoicetagItem.
+ */
+ public byte[] getAudio() throws IllegalStateException
+ {
+ synchronized (VoicetagItem.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+
+ return getAudioProxy(nativeObject);
+ }
+ }
+
+ /**
+ * Sets the audio used to construct the Voicetag.
+ */
+ public void setAudio(byte[] waveform) throws IllegalArgumentException,IllegalStateException
+ {
+ synchronized (VoicetagItem.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+
+ if ((waveform == null) || (waveform.length == 0))
+ throw new IllegalArgumentException("Waveform may not be null or empty.");
+ setAudioProxy(nativeObject,waveform);
+ }
+ }
+
+ /**
+ * Save the Voicetag.
+ */
+ public void save(String path) throws IllegalArgumentException
+ {
+ synchronized (VoicetagItem.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ if ((path == null) || (path.length() == 0))
+ throw new IllegalArgumentException("Path may not be null or empty string.");
+ saveVoicetagProxy(nativeObject,path);
+ }
+ }
+
+ /**
+ * Load a Voicetag.
+ */
+ public void load() throws IllegalStateException
+ {
+ synchronized (VoicetagItem.class)
+ {
+ if (nativeObject == 0)
+ throw new IllegalStateException("Object was destroyed.");
+ if (!needToBeLoaded)
+ throw new IllegalStateException("This Voicetag was not created from a file, does not need to be loaded.");
+ loadVoicetagProxy(nativeObject);
+ }
+ }
+
+ public long getNativeObject()
+ {
+ synchronized (VoicetagItem.class)
+ {
+ return nativeObject;
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ private void dispose()
+ {
+ synchronized (VoicetagItem.class)
+ {
+ if (nativeObject != 0)
+ {
+ deleteNativeObject(nativeObject);
+ nativeObject = 0;
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+
+ private static native long createVoicetagProxy(String filename, VoicetagItemListener listener);
+ /**
+ * (Optional operation) Returns the audio used to construct the Voicetag. The
+ * audio is in PCM format and is start-pointed and end-pointed. The audio is
+ * only generated if the enableGetWaveform recognition parameter is set
+ * prior to recognition.
+ *
+ * @see RecognizerParameters.enableGetWaveform
+ */
+ private native byte[] getAudioProxy(long nativeObject);
+
+ /**
+ * (Optional operation) Sets the audio used to construct the Voicetag. The
+ * audio is in PCM format and is start-pointed and end-pointed. The audio is
+ * only generated if the enableGetWaveform recognition parameter is set
+ * prior to recognition.
+ *
+ * @param waveform the endpointed waveform
+ */
+ private native void setAudioProxy(long nativeObject, byte[] waveform);
+
+ /**
+ * Save the Voicetag Item.
+ */
+ private native void saveVoicetagProxy(long nativeObject, String path);
+
+ /**
+ * Load a Voicetag Item.
+ */
+ private native void loadVoicetagProxy(long nativeObject);
+
+ /**
+ * Deletes a native object.
+ *
+ * @param nativeObject pointer to the native object
+ */
+ private native void deleteNativeObject(long nativeObject);
+}
diff --git a/core/java/android/speech/recognition/impl/WordItemImpl.java b/core/java/android/speech/recognition/impl/WordItemImpl.java
new file mode 100644
index 0000000..f0daa34
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/WordItemImpl.java
@@ -0,0 +1,157 @@
+/*---------------------------------------------------------------------------*
+ * WordItemImpl.java *
+ * *
+ * Copyright 2007, 2008 Nuance Communciations, Inc. *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the 'License'); *
+ * you may not use this file except in compliance with the License. *
+ * *
+ * You may obtain a copy of the License at *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an 'AS IS' BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ * *
+ *---------------------------------------------------------------------------*/
+
+package android.speech.recognition.impl;
+
+import android.speech.recognition.WordItem;
+
+/**
+ */
+public class WordItemImpl extends WordItem implements Runnable
+{
+ /**
+ * Empty array that gets reused whenever the code requests that the underlying
+ * recognizer guess the pronunciations.
+ */
+ private static final String[] guessPronunciations = new String[0];
+ /**
+ * Reference to the native object.
+ */
+ private long nativeObject;
+
+ /**
+ * Creates a new WordItem.
+ *
+ * @param word the word to insert
+ * @throws IllegalArgumentException if word or pronunciations are null
+ */
+ private WordItemImpl(String word, String[] pronunciations) throws IllegalArgumentException
+ {
+ initNativeObject(word, pronunciations);
+ }
+
+ public void run()
+ {
+ dispose();
+ }
+
+ /**
+ * Creates a new WordItem.
+ *
+ * @param word the word to insert
+ * @param pronunciations the pronunciations to associated with the item. If the list is
+ * is empty (example:new String[0]) the recognizer will attempt to guess the pronunciations.
+ * @return the WordItem
+ * @throws IllegalArgumentException if word is null or if pronunciations is
+ * null or pronunciations contains an element equal to null or empty string.
+ */
+ public static WordItemImpl valueOf(String word, String[] pronunciations)
+ throws IllegalArgumentException
+ {
+ if (word == null)
+ throw new IllegalArgumentException("Word may not be null");
+ else if (pronunciations == null)
+ throw new IllegalArgumentException("Pronunciations may not be null");
+ for (int i = 0, size = pronunciations.length; i < size; ++i)
+ {
+ if (pronunciations[i]==null)
+ {
+ throw new IllegalArgumentException(
+ "Pronunciations element may not be null");
+ }
+ else
+ {
+ if (pronunciations[i].trim().equals(""))
+ throw new IllegalArgumentException(
+ "Pronunciations may not contain empty strings");
+ }
+ }
+ return new WordItemImpl(word, pronunciations);
+ }
+
+ /**
+ * Creates a new WordItem.
+ *
+ * @param word the word to insert
+ * @param pronunciation the pronunciation to associate with the item. If it
+ * is null the recognizer will attempt to guess the pronunciations.
+ * @return the WordItem
+ * @throws IllegalArgumentException if word is null or if pronunciation is
+ * an empty string
+ */
+ public static WordItemImpl valueOf(String word, String pronunciation)
+ throws IllegalArgumentException
+ {
+ String[] pronunciations;
+ if (word == null)
+ throw new IllegalArgumentException("Word may not be null");
+ else if (pronunciation == null)
+ pronunciations = guessPronunciations;
+ else if (pronunciation.trim().equals(""))
+ throw new IllegalArgumentException(
+ "Pronunciation may not be an empty string");
+ else
+ pronunciations = new String[]{pronunciation};
+ return new WordItemImpl(word, pronunciations);
+ }
+
+ /**
+ * Allocates a reference to the native object.
+ *
+ * @param word the word to insert
+ */
+ private native void initNativeObject(String word, String[] pronunciations);
+
+ public long getNativeObject()
+ {
+ synchronized (WordItemImpl.class)
+ {
+ return nativeObject;
+ }
+ }
+
+ /**
+ * Releases the native resources associated with the object.
+ */
+ private void dispose()
+ {
+ synchronized (WordItemImpl.class)
+ {
+ if (nativeObject != 0)
+ {
+ deleteNativeObject(nativeObject);
+ nativeObject = 0;
+ }
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ dispose();
+ super.finalize();
+ }
+
+ /**
+ * Deletes a native object.
+ *
+ * @param nativeObject pointer to the native object
+ */
+ private native void deleteNativeObject(long nativeObject);
+}
diff --git a/core/java/android/speech/recognition/impl/package.html b/core/java/android/speech/recognition/impl/package.html
new file mode 100755
index 0000000..1c9bf9d
--- /dev/null
+++ b/core/java/android/speech/recognition/impl/package.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+ {@hide}
+</body>
+</html>
diff --git a/core/java/android/speech/recognition/package.html b/core/java/android/speech/recognition/package.html
new file mode 100644
index 0000000..3c59962
--- /dev/null
+++ b/core/java/android/speech/recognition/package.html
@@ -0,0 +1,6 @@
+<HTML>
+<BODY>
+{@hide}
+Provides classes for speech recogntion.
+</BODY>
+</HTML>