|
|
|
@ -1,7 +1,6 @@
|
|
|
|
package com.todoroo.aacenc;
|
|
|
|
package com.todoroo.astrid.voice;
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
import android.app.Activity;
|
|
|
|
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
@ -29,6 +28,7 @@ public class RecognizerApi implements RecognitionListener {
|
|
|
|
|
|
|
|
|
|
|
|
public static interface RecognizerApiListener {
|
|
|
|
public static interface RecognizerApiListener {
|
|
|
|
public void onSpeechResult(String result);
|
|
|
|
public void onSpeechResult(String result);
|
|
|
|
|
|
|
|
|
|
|
|
public void onSpeechError(int error);
|
|
|
|
public void onSpeechError(int error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -44,7 +44,7 @@ public class RecognizerApi implements RecognitionListener {
|
|
|
|
this.mListener = listener;
|
|
|
|
this.mListener = listener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void play(Activity activity, String file, PlaybackExceptionHandler handler) {
|
|
|
|
public static void play(String file, PlaybackExceptionHandler handler) {
|
|
|
|
MediaPlayer mediaPlayer = new MediaPlayer();
|
|
|
|
MediaPlayer mediaPlayer = new MediaPlayer();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
@ -61,14 +61,7 @@ public class RecognizerApi implements RecognitionListener {
|
|
|
|
private ProgressDialog speakPd;
|
|
|
|
private ProgressDialog speakPd;
|
|
|
|
private ProgressDialog processingPd;
|
|
|
|
private ProgressDialog processingPd;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
public void start(String callingPackage, String speakNowMessage) {
|
|
|
|
* Start speech recognition
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param callingPackage e.g. com.myapp.example
|
|
|
|
|
|
|
|
* @param speakNowMessage e.g. "Speak now!"
|
|
|
|
|
|
|
|
* @param processingMessage e.g. "Processing..."
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void start(String callingPackage, String speakNowMessage, String processingMessage) {
|
|
|
|
|
|
|
|
sr.setRecognitionListener(this);
|
|
|
|
sr.setRecognitionListener(this);
|
|
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
|
|
|
|
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
|
|
|
|
@ -147,8 +140,9 @@ public class RecognizerApi implements RecognitionListener {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onError(int error) {
|
|
|
|
public void onError(int error) {
|
|
|
|
if (mListener != null)
|
|
|
|
if (mListener != null) {
|
|
|
|
mListener.onSpeechError(error);
|
|
|
|
mListener.onSpeechError(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
Log.w("Speech Error", "Error code: " + error);
|
|
|
|
Log.w("Speech Error", "Error code: " + error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -170,8 +164,9 @@ public class RecognizerApi implements RecognitionListener {
|
|
|
|
public void onResults(Bundle results) {
|
|
|
|
public void onResults(Bundle results) {
|
|
|
|
processingPd.dismiss();
|
|
|
|
processingPd.dismiss();
|
|
|
|
ArrayList<String> strings = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
|
|
|
|
ArrayList<String> strings = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
|
|
|
|
if (mListener != null)
|
|
|
|
if (mListener != null) {
|
|
|
|
mListener.onSpeechResult(strings.size() == 0 ? "" : strings.get(0));
|
|
|
|
mListener.onSpeechResult(strings == null || strings.size() == 0 ? "" : strings.get(0));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|