This is an automated email from the git hooks/post-receive script. unknown user pushed a commit to branch devel in repository Say My Texts. commit 1411fac4cb4478c04f5ed2ab7bca8f5b286d677b Author: kmorin <kmorin@2d65e43e-0f24-4770-8739-84cc4fd997b9> Date: Sat Apr 26 19:43:46 2014 +0000 refs #999 Answer to a sms : reask dictating the message if the user says nothing understandable --- res/values-fr/strings.xml | 1 + res/values/strings.xml | 1 + .../saymytexts/DictateSmsBroadcastReceiver.java | 31 +++++++++++--- .../android/saymytexts/SayMyTextService.java | 48 ++++++++++++++-------- .../saymytexts/SayNextActionBroadcastReceiver.java | 7 ++-- 5 files changed, 63 insertions(+), 25 deletions(-) diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml index 6251e8e..13c2e6d 100644 --- a/res/values-fr/strings.xml +++ b/res/values-fr/strings.xml @@ -29,6 +29,7 @@ <!-- actions --> <string name="ask_next_action">Que voulez-vous faire ? Appeler, répondre ou quitter ?</string> + <string name="dictate_sms">Dictez votre réponse</string> <string name="send_sms_confirmation">Vous avez dicté : %s. Voulez-vous confirmer, corriger ou annuler ?</string> <string name="call_action">appeler</string> diff --git a/res/values/strings.xml b/res/values/strings.xml index f77751d..bd0f4c1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -30,6 +30,7 @@ <!-- actions --> <string name="ask_next_action">What would you like to do? Call, answer or quit?</string> + <string name="dictate_sms">Dictate your answer</string> <string name="send_sms_confirmation">You dictated: %s. Would you like to confirm, modify ou cancel?</string> <string name="call_action">call</string> diff --git a/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java b/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java index edad8ef..486a9c0 100644 --- a/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java +++ b/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java @@ -5,6 +5,8 @@ import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.media.AudioManager; +import android.media.ToneGenerator; import android.net.Uri; import android.os.Bundle; import android.speech.RecognitionListener; @@ -25,16 +27,20 @@ public class DictateSmsBroadcastReceiver extends BroadcastReceiver { public static final String ACTION_DICTATE_SMS = "org.chorem.android.saymytexts.DICTATE_SMS"; - public static final String EXTRA_SMS = "sms"; + public static final String INTENT_EXTRA_SMS = "sms"; + public static final String INTENT_EXTRA_ATTEMPT_NUMBER = "attemptNumber"; @Override - public void onReceive(final Context context, Intent intent) { + public void onReceive(final Context context, final Intent intent) { Log.d(TAG, "next action ?"); - final SMS sms = (SMS) intent.getSerializableExtra(EXTRA_SMS); + final SMS sms = (SMS) intent.getSerializableExtra(INTENT_EXTRA_SMS); if (sms != null) { SpeechRecognizer speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context); speechRecognizer.setRecognitionListener(new RecognitionListener() { + + private ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, ToneGenerator.MAX_VOLUME); + @Override public void onReadyForSpeech(Bundle params) { } @@ -56,9 +62,8 @@ public class DictateSmsBroadcastReceiver extends BroadcastReceiver { @Override public void onError(int error) { Log.d(TAG, "onError " + error); - //TODO if error 6 ERROR_SPEECH_TIMEOUT ask to say it again - //TODO if error 7 ERROR_NO_MATCH ask to say it again - //TODO if other error say there is an error + tg.startTone(ToneGenerator.TONE_PROP_NACK); + reaskToDictate(context, intent, sms); } @Override @@ -73,6 +78,10 @@ public class DictateSmsBroadcastReceiver extends BroadcastReceiver { serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_SMS, sms); serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_DICTATED_MESSAGE, text); context.startService(serviceIntent); + + } else { + tg.startTone(ToneGenerator.TONE_PROP_NACK); + reaskToDictate(context, intent, sms); } } @@ -91,4 +100,14 @@ public class DictateSmsBroadcastReceiver extends BroadcastReceiver { speechRecognizer.startListening(recognizeIntent); } } + + protected void reaskToDictate(Context context, Intent intent, SMS sms) { + int attemptNumber = intent.getIntExtra(INTENT_EXTRA_ATTEMPT_NUMBER, 1); + + Intent serviceIntent = new Intent(context, SayMyTextService.class); + serviceIntent.setAction(SayMyTextService.ACTION_DICTATE_SMS); + serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_SMS, sms); + serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_ATTEMPT_NUMBER, attemptNumber); + context.startService(serviceIntent); + } } diff --git a/src/org/chorem/android/saymytexts/SayMyTextService.java b/src/org/chorem/android/saymytexts/SayMyTextService.java index 6056a0f..8dd2d7a 100644 --- a/src/org/chorem/android/saymytexts/SayMyTextService.java +++ b/src/org/chorem/android/saymytexts/SayMyTextService.java @@ -87,6 +87,9 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList /** null if the texttospeech is not initialized */ protected Boolean canSpeak = null; + // true if music was playing when the firts message in queue arrived + protected boolean musicWasActive; + protected TextToSpeech textToSpeech; /** texts to read, received before the textospeech is ready or while a call is in progress */ @@ -204,9 +207,6 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList break; case ACTION_DICTATE_SMS: - if (attemptNumber > 0) { - - } // if (bluetoothDevices.isEmpty()) { dictateSMS(sms, attemptNumber + 1); // } else { @@ -250,6 +250,10 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList // if the user enabled the reading and // if the headset is plugged, or if there is a bluetooth device connected if (readingEnabled && (audioManager.isWiredHeadsetOn() || !bluetoothDevices.isEmpty())) { + musicWasActive = audioManager.isMusicActive(); + if (musicWasActive) { + audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true); + } if (Boolean.TRUE.equals(canSpeak)) { requestReading(sms); } else { @@ -290,9 +294,14 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList SMS sms = awaitingTexts.remove(0); requestReading(sms); - } else if (!bluetoothDevices.isEmpty()) { - audioManager.stopBluetoothSco(); - audioManager.setMode(AudioManager.MODE_NORMAL); + } else { + if (!bluetoothDevices.isEmpty()) { + audioManager.stopBluetoothSco(); + audioManager.setMode(AudioManager.MODE_NORMAL); + } + if (musicWasActive) { + audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false); + } } } } @@ -420,7 +429,6 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList textToSpeech.speak(getString(R.string.voice_not_recognized), TextToSpeech.QUEUE_ADD, params); } - //TODO add a counter to ask only twice (or 3 times, or it should be configurable) if (attemptNumber <= 3) { params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, btConnected ? BT_ASK_NEXT_ACTION_UTTERANCE_ID : ASK_NEXT_ACTION_UTTERANCE_ID); @@ -446,8 +454,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList @Override public void onDone(String utteranceId) { Intent dictateAction = new Intent(DictateSmsBroadcastReceiver.ACTION_DICTATE_SMS); - dictateAction.putExtra(DictateSmsBroadcastReceiver.EXTRA_SMS, sms); -// dictateAction.putExtra(DictateSmsBroadcastReceiver.INTENT_EXTRA_SMS, attemptNumber); + dictateAction.putExtra(DictateSmsBroadcastReceiver.INTENT_EXTRA_SMS, sms); + dictateAction.putExtra(DictateSmsBroadcastReceiver.INTENT_EXTRA_ATTEMPT_NUMBER, attemptNumber); sendBroadcast(dictateAction); } @@ -455,13 +463,22 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList HashMap<String, String> params = new HashMap<>(); params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL)); - params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID); - textToSpeech.setLanguage(Locale.getDefault()); - textToSpeech.setSpeechRate(1f); - textToSpeech.setPitch(1f); -// String text = getString(R.string.send_sms_confirmation); - textToSpeech.speak("dictez votre sms", TextToSpeech.QUEUE_ADD, params); + if (attemptNumber > 1) { + textToSpeech.speak(getString(R.string.voice_not_recognized), TextToSpeech.QUEUE_ADD, params); + } + + if (attemptNumber <= 3) { + params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID); + textToSpeech.setLanguage(Locale.getDefault()); + textToSpeech.setSpeechRate(1f); + textToSpeech.setPitch(1f); + textToSpeech.speak(getString(R.string.dictate_sms), TextToSpeech.QUEUE_ADD, params); + + } else { + setCanSpeak(true); + } + } protected void askSendingConfirmation(final String message, final SMS originSms, final int attemptNumber) { @@ -499,7 +516,6 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList textToSpeech.speak(getString(R.string.voice_not_recognized), TextToSpeech.QUEUE_ADD, params); } - //TODO add a counter to ask only twice (or 3 times, or it should be configurable) if (attemptNumber <= 3) { params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID); String text = getString(R.string.send_sms_confirmation, message); diff --git a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java b/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java index 4d7bae4..a8e1471 100644 --- a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java +++ b/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java @@ -63,9 +63,6 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver { @Override public void onError(int error) { Log.d(TAG, "onError " + error); - //TODO if error 6 ERROR_SPEECH_TIMEOUT ask to say it again - //TODO if error 7 ERROR_NO_MATCH ask to say it again - //TODO if other error say there is an error tg.startTone(ToneGenerator.TONE_PROP_NACK); reaskAction(context, intent, sms); } @@ -120,6 +117,10 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver { tg.startTone(ToneGenerator.TONE_PROP_NACK); reaskAction(context, intent, sms); } + + } else { + tg.startTone(ToneGenerator.TONE_PROP_NACK); + reaskAction(context, intent, sms); } } -- To stop receiving notification emails like this one, please contact Chorem.org SCM administrator <admin+scm@chorem.org>.