Say-my-texts-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 143 discussions
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository say-my-texts.
See http://git.chorem.org/say-my-texts.git
commit 4ebccb5bab434a240e85faad0d8223a2734e87db
Author: Kevin Morin <morin(a)codelutin.com>
Date: Thu May 8 20:46:31 2014 +0000
add rotation management
---
AndroidManifest.xml | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f9d8f06..df9b9ab 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -29,7 +29,8 @@
<activity android:name=".SettingsActivity"
android:label="@string/app_name"
- android:launchMode="singleTop">
+ android:launchMode="singleTop"
+ android:configChanges="orientation|screenSize|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
@@ -53,7 +54,8 @@
android:theme="@android:style/Theme.Holo.Dialog"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
- android:finishOnTaskLaunch="true" />
+ android:finishOnTaskLaunch="true"
+ android:configChanges="orientation|screenSize|keyboardHidden"/>
<receiver android:name=".SayMyTextsWidgetProvider" >
<intent-filter>
--
To stop receiving notification emails like this one, please contact
chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
07/10: improve preferences + add max number of attempts in the preferences
by chorem.org scm 25 May '14
by chorem.org scm 25 May '14
25 May '14
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository say-my-texts.
See http://git.chorem.org/say-my-texts.git
commit a8d3d8df4b681cc001f1c89fceed01ee17214e0d
Author: Kevin Morin <morin(a)codelutin.com>
Date: Thu May 1 17:28:26 2014 +0000
improve preferences + add max number of attempts in the preferences
---
res/values-fr/strings.xml | 5 +-
res/values/preference_keys.xml | 1 +
res/values/strings.xml | 5 +-
res/xml/preferences.xml | 8 +-
.../android/saymytexts/SayMyTextService.java | 119 +++++++++++----------
.../android/saymytexts/SettingsActivity.java | 45 ++++++--
6 files changed, 110 insertions(+), 73 deletions(-)
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index 6bb82b6..ef69b45 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -9,6 +9,7 @@
<string name="preferences_settings_label">Paramètres</string>
<string name="preference_reading_profile_label">Lecture des SMS</string>
<string name="preference_enable_interaction_label">Intéraction (appel ou réponse)</string>
+ <string name="preference_voice_recognizer_max_attempt_number_label">Nombre maximum d\'essais</string>
<string name="preference_enable_heisendroid_mode_label">Mode Heisendroid</string>
<string name="preference_test_sms_label">Tester en m\'envoyant un SMS</string>
<string name="test_sms_content">Heisendroïd</string>
@@ -29,13 +30,13 @@
<string name="crash_dialog_ok_toast">Merci !</string>
<!-- actions -->
- <string name="ask_next_action">Que voulez-vous faire ? Appeler, répondre ou quitter ?</string>
+ <string name="ask_next_action">Que voulez-vous faire ? Appeler, répondre ou rien ?</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>
<string name="answer_action">répondre</string>
- <string name="quit_action">quitter</string>
+ <string name="quit_action">rien</string>
<string name="confirm_action">confirmer</string>
<string name="modifiy_action">corriger</string>
diff --git a/res/values/preference_keys.xml b/res/values/preference_keys.xml
index 379b53c..43006d2 100644
--- a/res/values/preference_keys.xml
+++ b/res/values/preference_keys.xml
@@ -3,6 +3,7 @@
<string name="preference_reading_profile_key">reading_profile</string>
<string name="preference_enable_interaction_key">enable_interaction</string>
<string name="preference_enable_heisendroid_mode_key">enable_heisendroid_mode</string>
+ <string name="preference_voice_recognizer_max_attempt_number_key">preference_voice_recognizer_max_attempt_number</string>
<string name="preference_test_sms_key">test_sms</string>
<string name="preference_version_key">version</string>
<string name="preference_documentation_key">documentation</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0410b73..f67cb39 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -9,6 +9,7 @@
<string name="preferences_settings_label">Settings</string>
<string name="preference_reading_profile_label">SMS reading</string>
<string name="preference_enable_interaction_label">Interaction (call or answer)</string>
+ <string name="preference_voice_recognizer_max_attempt_number_label">Maximum attempt number</string>
<string name="preference_enable_heisendroid_mode_label">Heisendroid mode</string>
<string name="preference_test_sms_label">Test by sending an SMS to myself</string>
<string name="test_sms_content">Heisendroïd</string>
@@ -30,13 +31,13 @@
<string name="crash_dialog_ok_toast">Thank you !</string>
<!-- actions -->
- <string name="ask_next_action">What would you like to do? Call, answer or quit?</string>
+ <string name="ask_next_action">What would you like to do? Call, answer or nothing?</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>
<string name="answer_action">answer</string>
- <string name="quit_action">quit</string>
+ <string name="quit_action">nothing</string>
<string name="confirm_action">confirm</string>
<string name="modifiy_action">modify</string>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index d3bad81..1afb239 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -10,14 +10,18 @@
android:entryValues="@array/preferences_reading_profile_values"
android:defaultValue="anyDeviceConnected"/>
-
<SwitchPreference android:key="@string/preference_enable_interaction_key"
android:title="@string/preference_enable_interaction_label"
android:defaultValue="true" />
+ <EditTextPreference android:key="@string/preference_voice_recognizer_max_attempt_number_key"
+ android:title="@string/preference_voice_recognizer_max_attempt_number_label"
+ android:defaultValue="3"
+ android:numeric="integer"/>
+
<SwitchPreference android:key="@string/preference_enable_heisendroid_mode_key"
android:title="@string/preference_enable_heisendroid_mode_label"
- android:defaultValue="false" />
+ android:defaultValue="false"/>
<Preference android:key="@string/preference_test_sms_key"
android:title="@string/preference_test_sms_label"
diff --git a/src/org/chorem/android/saymytexts/SayMyTextService.java b/src/org/chorem/android/saymytexts/SayMyTextService.java
index acca74a..0d701a6 100644
--- a/src/org/chorem/android/saymytexts/SayMyTextService.java
+++ b/src/org/chorem/android/saymytexts/SayMyTextService.java
@@ -54,7 +54,7 @@ import java.util.Map;
* @author Kevin Morin (Code Lutin)
* @since 1.0
*/
-public class SayMyTextService extends Service implements TextToSpeech.OnInitListener {
+public class SayMyTextService extends Service implements TextToSpeech.OnInitListener, SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = "SayMyTextService";
@@ -82,6 +82,14 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
protected static final String ASK_NEXT_ACTION_UTTERANCE_ID = "askNextActionUtteranceId";
protected static final String OTHER_UTTERANCE_ID = "oherUtteranceId";
+ protected int maxAttemptNumber;
+
+ protected String readingProfile;
+
+ protected boolean heisendroidModeEnabled;
+
+ protected boolean interactionEnabled;
+
protected AudioManager audioManager;
/** null if the texttospeech is not initialized */
@@ -133,6 +141,27 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
intentFilter = new IntentFilter(DictateSmsBroadcastReceiver.ACTION_DICTATE_SMS);
registerReceiver(new DictateSmsBroadcastReceiver(), intentFilter);
+ SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
+ String key = getString(R.string.preference_voice_recognizer_max_attempt_number_key);
+ String maxAttemptValue = sharedPref.getString(key, null);
+ try {
+ maxAttemptNumber = Integer.parseInt(maxAttemptValue);
+ } catch (NumberFormatException e) {
+ maxAttemptNumber = 3;
+ }
+
+ String[] readingProfileValues = getResources().getStringArray(R.array.preferences_reading_profile_values);
+ String readingProfileKey = getString(R.string.preference_reading_profile_key);
+ readingProfile = sharedPref.getString(readingProfileKey, readingProfileValues[0]);
+
+ String heisendroidModeEnabledKey = getString(R.string.preference_enable_heisendroid_mode_key);
+ heisendroidModeEnabled = sharedPref.getBoolean(heisendroidModeEnabledKey, true);
+
+ String interactionPrefKey = getString(R.string.preference_enable_interaction_key);
+ interactionEnabled = sharedPref.getBoolean(interactionPrefKey, true);
+
+ sharedPref.registerOnSharedPreferenceChangeListener(this);
+
//// Get the default adapter
// final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
//
@@ -179,11 +208,6 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
public int onStartCommand(Intent intent, int flags, int startId) {
int result = super.onStartCommand(intent, flags, startId);
- SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
- String[] readingProfileValues = getResources().getStringArray(R.array.preferences_reading_profile_values);
- String readingProfileKey = getString(R.string.preference_reading_profile_key);
- String readingProfile = sharedPref.getString(readingProfileKey, readingProfileValues[0]);
-
if (intent != null) {
String action = intent.getAction();
Log.d(TAG, "action " + action);
@@ -211,39 +235,13 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
break;
case ACTION_DICTATE_SMS:
-// if (bluetoothDevices.isEmpty()) {
- dictateSMS(sms, attemptNumber + 1);
-// } else {
-// requestBluetoothSpeakingActivation(new Function<Void, Void>() {
-// @Override
-// public Void apply(Void input) {
-// dictateSMS(sms);
-// return null;
-// }
-// });
-// }
+ dictateSMS(sms, attemptNumber + 1);
break;
case ACTION_CONFIRM_SMS_SENDING:
// if a message has just been dictated
final String dictatedMessage = intent.getStringExtra(INTENT_EXTRA_DICTATED_MESSAGE);
-// if (!bluetoothDevices.isEmpty()) {
-// registerReceiver(new BroadcastReceiver() {
-// @Override
-// public void onReceive(Context context, Intent intent) {
-// int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE);
-// if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
-// context.unregisterReceiver(this);
-// askSendingConfirmation(dictatedMessage, sms);
-// }
-// }
-// }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
-// audioManager.setMode(AudioManager.MODE_IN_CALL);
-// audioManager.startBluetoothSco();
-//
-// } else {
- askSendingConfirmation(dictatedMessage, sms, ++attemptNumber);
-// }
+ askSendingConfirmation(dictatedMessage, sms, ++attemptNumber);
break;
case ACTION_READ_NEXT_SMS:
@@ -252,8 +250,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
default:
boolean readingEnabled;
+ String[] readingProfileValues = getResources().getStringArray(R.array.preferences_reading_profile_values);
if (readingProfileValues[0].equals(readingProfile)) {
- //TODO set speaker on
readingEnabled = true;
} else if (readingProfileValues[1].equals(readingProfile)) {
@@ -382,11 +380,6 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
// disable the reading of the nexts sms while reading the current one
setCanSpeak(false);
- SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
- String heisendroidModeEnabledKey = getString(R.string.preference_enable_heisendroid_mode_key);
- boolean heisendroidModeEnabled = sharedPref.getBoolean(heisendroidModeEnabledKey, true);
-
-
textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onStart(String utteranceId) {
@@ -406,12 +399,6 @@ 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));
-// if (btConnected) {
-// params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, BT_UTTERANCE_ID);
-// }
-
- String interactionPrefKey = getString(R.string.preference_enable_interaction_key);
- boolean interaction = sharedPref.getBoolean(interactionPrefKey, true);
if (heisendroidModeEnabled) {
textToSpeech.setLanguage(Locale.US);
@@ -420,7 +407,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak("Say my text.", TextToSpeech.QUEUE_ADD, params);
}
- if (!interaction && !heisendroidModeEnabled) {
+ if (!interactionEnabled && !heisendroidModeEnabled) {
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID);
}
textToSpeech.setLanguage(Locale.getDefault());
@@ -430,7 +417,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params);
if (heisendroidModeEnabled) {
- if (interaction) {
+ if (interactionEnabled) {
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID);
}
textToSpeech.setLanguage(Locale.US);
@@ -439,7 +426,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params);
}
- if (interaction) {
+ if (interactionEnabled) {
askForActionAfterReading(sms, btConnected, 1);
}
}
@@ -457,12 +444,6 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
@Override
public void onDone(String utteranceId) {
-// if (BT_UTTERANCE_ID.equals(utteranceId)) {
-// // when the text has been read by the bluetooth device, stop the connection
-// audioManager.stopBluetoothSco();
-// audioManager.setMode(AudioManager.MODE_NORMAL);
-// }
-
if (ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId) ||
BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) {
Intent sayaction = new Intent(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION);
@@ -486,7 +467,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak(getString(R.string.voice_not_recognized), TextToSpeech.QUEUE_ADD, params);
}
- if (attemptNumber <= 3) {
+ if (attemptNumber <= maxAttemptNumber) {
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
btConnected ? BT_ASK_NEXT_ACTION_UTTERANCE_ID : ASK_NEXT_ACTION_UTTERANCE_ID);
textToSpeech.speak(getString(R.string.ask_next_action), TextToSpeech.QUEUE_ADD, params);
@@ -525,7 +506,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak(getString(R.string.voice_not_recognized), TextToSpeech.QUEUE_ADD, params);
}
- if (attemptNumber <= 3) {
+ if (attemptNumber <= maxAttemptNumber) {
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID);
textToSpeech.setLanguage(Locale.getDefault());
textToSpeech.setSpeechRate(1f);
@@ -573,7 +554,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak(getString(R.string.voice_not_recognized), TextToSpeech.QUEUE_ADD, params);
}
- if (attemptNumber <= 3) {
+ if (attemptNumber <= maxAttemptNumber) {
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID);
String text = getString(R.string.send_sms_confirmation, message);
textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params);
@@ -584,4 +565,26 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
}
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ if (key.equals(getString(R.string.preference_voice_recognizer_max_attempt_number_key))) {
+ String maxAttemptValue = sharedPreferences.getString(key, null);
+ try {
+ maxAttemptNumber = Integer.parseInt(maxAttemptValue);
+ } catch (NumberFormatException e) {
+ maxAttemptNumber = 3;
+ }
+
+ } else if (key.equals(getString(R.string.preference_reading_profile_key))) {
+ String[] readingProfileValues =
+ getResources().getStringArray(R.array.preferences_reading_profile_values);
+ readingProfile = sharedPreferences.getString(key, readingProfileValues[0]);
+
+ } else if (key.equals(getString(R.string.preference_enable_heisendroid_mode_key))) {
+ heisendroidModeEnabled = sharedPreferences.getBoolean(key, true);
+
+ } else if (key.equals(getString(R.string.preference_enable_interaction_key))) {
+ interactionEnabled = sharedPreferences.getBoolean(key, true);
+ }
+ }
}
diff --git a/src/org/chorem/android/saymytexts/SettingsActivity.java b/src/org/chorem/android/saymytexts/SettingsActivity.java
index aeaf63f..4908995 100644
--- a/src/org/chorem/android/saymytexts/SettingsActivity.java
+++ b/src/org/chorem/android/saymytexts/SettingsActivity.java
@@ -122,24 +122,30 @@ public class SettingsActivity extends Activity {
addWebsitePreferenceClickListener(R.string.preference_documentation_key);
addWebsitePreferenceClickListener(R.string.preference_issue_tracker_key);
- }
-
- @Override
- public void onResume() {
- super.onResume();
-
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
String key = getString(R.string.preference_reading_profile_key);
- ListPreference preference = (ListPreference) findPreference(key);
- CharSequence summary = preference.getEntry();
- preference.setSummary(summary);
+ ListPreference listPreference = (ListPreference) findPreference(key);
+ CharSequence summary = listPreference.getEntry();
+ listPreference.setSummary(summary);
key = getString(R.string.preference_enable_interaction_key);
SwitchPreference switchPreference = (SwitchPreference) findPreference(key);
boolean enabled = sharedPref.getBoolean(key, switchPreference.isChecked());
switchPreference.setChecked(enabled);
+ key = getString(R.string.preference_voice_recognizer_max_attempt_number_key);
+ String maxAttemptValue = sharedPref.getString(key, null);
+ int maxAttemptNumber;
+ try {
+ maxAttemptNumber = Integer.parseInt(maxAttemptValue);
+ } catch (NumberFormatException e) {
+ maxAttemptNumber = 3;
+ }
+ Preference preference = findPreference(key);
+ preference.setSummary(String.valueOf(maxAttemptNumber));
+ preference.setEnabled(enabled);
+
key = getString(R.string.preference_enable_heisendroid_mode_key);
switchPreference = (SwitchPreference) findPreference(key);
enabled = sharedPref.getBoolean(key, switchPreference.isChecked());
@@ -155,6 +161,27 @@ public class SettingsActivity extends Activity {
ListPreference preference = (ListPreference) findPreference(key);
CharSequence summary = preference.getEntry();
preference.setSummary(summary);
+
+ } else if (getString(R.string.preference_enable_interaction_key).equals(key)) {
+ SwitchPreference switchPreference = (SwitchPreference) findPreference(key);
+ boolean enabled = sharedPreferences.getBoolean(key, switchPreference.isChecked());
+ switchPreference.setChecked(enabled);
+ findPreference(getString(R.string.preference_voice_recognizer_max_attempt_number_key)).setEnabled(enabled);
+
+ } else if (getString(R.string.preference_voice_recognizer_max_attempt_number_key).equals(key)) {
+ String maxAttemptValue = sharedPreferences.getString(key, null);
+ int maxAttemptNumber;
+ try {
+ maxAttemptNumber = Integer.parseInt(maxAttemptValue);
+ } catch (NumberFormatException e) {
+ maxAttemptNumber = 3;
+ }
+ findPreference(key).setSummary(String.valueOf(maxAttemptNumber));
+
+ } else if (getString(R.string.preference_enable_heisendroid_mode_key).equals(key)) {
+ SwitchPreference switchPreference = (SwitchPreference) findPreference(key);
+ boolean enabled = sharedPreferences.getBoolean(key, switchPreference.isChecked());
+ switchPreference.setChecked(enabled);
}
}
--
To stop receiving notification emails like this one, please contact
chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository say-my-texts.
See http://git.chorem.org/say-my-texts.git
commit d20a60af263f0955c164872399ec040e642f9bdf
Author: Kevin Morin <morin(a)codelutin.com>
Date: Mon Apr 28 20:06:47 2014 +0000
fixes #1018 [Settings] Make reading profiles
---
res/values-fr/arrays.xml | 11 +++
res/values-fr/strings.xml | 2 +-
res/values/arrays.xml | 18 +++++
res/values/preference_keys.xml | 2 +-
res/values/strings.xml | 2 +-
res/xml/preferences.xml | 9 ++-
.../android/saymytexts/SayMyTextService.java | 82 ++++++++++++++++++----
.../saymytexts/SayMyTextsWidgetProvider.java | 42 +++++------
.../android/saymytexts/SettingsActivity.java | 35 ++++++---
9 files changed, 154 insertions(+), 49 deletions(-)
diff --git a/res/values-fr/arrays.xml b/res/values-fr/arrays.xml
new file mode 100644
index 0000000..da4a5db
--- /dev/null
+++ b/res/values-fr/arrays.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string-array name="preferences_reading_profile_entries">
+ <item>Toujours</item>
+ <item>Quand un casque ou un appareil bluetooth est connecté</item>
+ <item>Quand un casque est connecté</item>
+ <item>Jamais</item>
+ </string-array>
+
+</resources>
\ No newline at end of file
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index 6ecfea7..6bb82b6 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -7,7 +7,7 @@
<!-- Preferences -->
<string name="preferences_settings_label">Paramètres</string>
- <string name="preference_enable_reading_label">Lecture des SMS</string>
+ <string name="preference_reading_profile_label">Lecture des SMS</string>
<string name="preference_enable_interaction_label">Intéraction (appel ou réponse)</string>
<string name="preference_enable_heisendroid_mode_label">Mode Heisendroid</string>
<string name="preference_test_sms_label">Tester en m\'envoyant un SMS</string>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
new file mode 100644
index 0000000..d851bcc
--- /dev/null
+++ b/res/values/arrays.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string-array name="preferences_reading_profile_values">
+ <item>always</item>
+ <item>anyDeviceConnected</item>
+ <item>wiredDeviceConnected</item>
+ <item>never</item>
+ </string-array>
+
+ <string-array name="preferences_reading_profile_entries">
+ <item>Always</item>
+ <item>When a headset, headphone or bluetooth device is connected</item>
+ <item>When a headset, headphone is connected</item>
+ <item>Never</item>
+ </string-array>
+
+</resources>
\ No newline at end of file
diff --git a/res/values/preference_keys.xml b/res/values/preference_keys.xml
index b10ea17..379b53c 100644
--- a/res/values/preference_keys.xml
+++ b/res/values/preference_keys.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="preference_enable_reading_key">enable_reading</string>
+ <string name="preference_reading_profile_key">reading_profile</string>
<string name="preference_enable_interaction_key">enable_interaction</string>
<string name="preference_enable_heisendroid_mode_key">enable_heisendroid_mode</string>
<string name="preference_test_sms_key">test_sms</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ffdde79..0410b73 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7,7 +7,7 @@
<!-- Preferences -->
<string name="preferences_settings_label">Settings</string>
- <string name="preference_enable_reading_label">SMS reading</string>
+ <string name="preference_reading_profile_label">SMS reading</string>
<string name="preference_enable_interaction_label">Interaction (call or answer)</string>
<string name="preference_enable_heisendroid_mode_label">Heisendroid mode</string>
<string name="preference_test_sms_label">Test by sending an SMS to myself</string>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 1c6e89a..d3bad81 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -4,9 +4,12 @@
<PreferenceCategory android:title="@string/preferences_settings_label">
- <SwitchPreference android:key="@string/preference_enable_reading_key"
- android:title="@string/preference_enable_reading_label"
- android:defaultValue="true" />
+ <ListPreference android:key="@string/preference_reading_profile_key"
+ android:title="@string/preference_reading_profile_label"
+ android:entries="@array/preferences_reading_profile_entries"
+ android:entryValues="@array/preferences_reading_profile_values"
+ android:defaultValue="anyDeviceConnected"/>
+
<SwitchPreference android:key="@string/preference_enable_interaction_key"
android:title="@string/preference_enable_interaction_label"
diff --git a/src/org/chorem/android/saymytexts/SayMyTextService.java b/src/org/chorem/android/saymytexts/SayMyTextService.java
index aceb047..acca74a 100644
--- a/src/org/chorem/android/saymytexts/SayMyTextService.java
+++ b/src/org/chorem/android/saymytexts/SayMyTextService.java
@@ -87,9 +87,12 @@ 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
+ // true if music was playing when the first message in queue arrived
protected boolean musicWasActive;
+ // true if the speaker was on when the first message in queue arrived
+ protected boolean speakerWasOn;
+
protected TextToSpeech textToSpeech;
/** texts to read, received before the textospeech is ready or while a call is in progress */
@@ -177,8 +180,9 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
int result = super.onStartCommand(intent, flags, startId);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
- String readingEnabledKey = getString(R.string.preference_enable_reading_key);
- boolean readingEnabled = sharedPref.getBoolean(readingEnabledKey, true);
+ String[] readingProfileValues = getResources().getStringArray(R.array.preferences_reading_profile_values);
+ String readingProfileKey = getString(R.string.preference_reading_profile_key);
+ String readingProfile = sharedPref.getString(readingProfileKey, readingProfileValues[0]);
if (intent != null) {
String action = intent.getAction();
@@ -247,15 +251,40 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
break;
default:
- // 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);
+ boolean readingEnabled;
+ if (readingProfileValues[0].equals(readingProfile)) {
+ //TODO set speaker on
+ readingEnabled = true;
+
+ } else if (readingProfileValues[1].equals(readingProfile)) {
+ readingEnabled = audioManager.isWiredHeadsetOn() || !bluetoothDevices.isEmpty();
+
+ } else if (readingProfileValues[2].equals(readingProfile)) {
+ readingEnabled = audioManager.isWiredHeadsetOn();
+
+ } else {
+ readingEnabled = false;
+ }
+
+ if (readingEnabled) {
+ if (!Boolean.FALSE.equals(canSpeak)) {
+ musicWasActive = audioManager.isMusicActive();
+ speakerWasOn = audioManager.isSpeakerphoneOn();
+
+ if (musicWasActive) {
+ audioManager.setStreamMute(AudioManager.STREAM_MUSIC, musicWasActive);
+ }
+
+ if (readingProfileValues[0].equals(readingProfile)
+ && !audioManager.isWiredHeadsetOn() && bluetoothDevices.isEmpty()) {
+ audioManager.setMode(AudioManager.MODE_IN_CALL);
+ audioManager.setSpeakerphoneOn(true);
+ }
}
+
if (Boolean.TRUE.equals(canSpeak)) {
requestReading(sms);
+
} else {
awaitingTexts.add(sms);
}
@@ -297,11 +326,12 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
} else {
if (!bluetoothDevices.isEmpty()) {
audioManager.stopBluetoothSco();
- audioManager.setMode(AudioManager.MODE_NORMAL);
}
if (musicWasActive) {
audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
}
+ audioManager.setSpeakerphoneOn(speakerWasOn);
+ audioManager.setMode(AudioManager.MODE_NORMAL);
}
}
}
@@ -356,7 +386,23 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
String heisendroidModeEnabledKey = getString(R.string.preference_enable_heisendroid_mode_key);
boolean heisendroidModeEnabled = sharedPref.getBoolean(heisendroidModeEnabledKey, true);
-// waiting = true;
+
+ textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
+ @Override
+ public void onStart(String utteranceId) {
+ }
+
+ @Override
+ public void onError(String utteranceId) {
+ Log.e(TAG, "Error speaking: " + utteranceId);
+ }
+
+ @Override
+ public void onDone(String utteranceId) {
+ Log.d(TAG, "done");
+ setCanSpeak(true);
+ }
+ });
HashMap<String, String> params = new HashMap<>();
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));
@@ -364,6 +410,9 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
// params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, BT_UTTERANCE_ID);
// }
+ String interactionPrefKey = getString(R.string.preference_enable_interaction_key);
+ boolean interaction = sharedPref.getBoolean(interactionPrefKey, true);
+
if (heisendroidModeEnabled) {
textToSpeech.setLanguage(Locale.US);
textToSpeech.setSpeechRate(0.3f);
@@ -371,6 +420,9 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak("Say my text.", TextToSpeech.QUEUE_ADD, params);
}
+ if (!interaction && !heisendroidModeEnabled) {
+ params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID);
+ }
textToSpeech.setLanguage(Locale.getDefault());
textToSpeech.setSpeechRate(1f);
textToSpeech.setPitch(1f);
@@ -378,17 +430,17 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params);
if (heisendroidModeEnabled) {
+ if (interaction) {
+ params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID);
+ }
textToSpeech.setLanguage(Locale.US);
textToSpeech.setSpeechRate(0.3f);
textToSpeech.setPitch(0.1f);
textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params);
}
- String interactionPrefKey = getString(R.string.preference_enable_interaction_key);
- if (sharedPref.getBoolean(interactionPrefKey, true)) {
+ if (interaction) {
askForActionAfterReading(sms, btConnected, 1);
- } else {
- setCanSpeak(true);
}
}
diff --git a/src/org/chorem/android/saymytexts/SayMyTextsWidgetProvider.java b/src/org/chorem/android/saymytexts/SayMyTextsWidgetProvider.java
index b5e6cfd..16bd523 100644
--- a/src/org/chorem/android/saymytexts/SayMyTextsWidgetProvider.java
+++ b/src/org/chorem/android/saymytexts/SayMyTextsWidgetProvider.java
@@ -62,15 +62,16 @@ public class SayMyTextsWidgetProvider extends AppWidgetProvider {
RemoteViews views = updateButtonState(context);
views.setOnClickPendingIntent(R.id.say_my_texts_widget, pendingIntent);
+ //TODO
PreferenceManager.getDefaultSharedPreferences(context)
.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- String enableReadingKey = context.getString(R.string.preference_enable_reading_key);
- if (key.equals(enableReadingKey)) {
- RemoteViews views = updateButtonState(context);
- appWidgetManager.updateAppWidget(appWidgetId, views);
- }
+// String enableReadingKey = context.getString(R.string.preference_enable_reading_key);
+// if (key.equals(enableReadingKey)) {
+// RemoteViews views = updateButtonState(context);
+// appWidgetManager.updateAppWidget(appWidgetId, views);
+// }
}
});
@@ -85,25 +86,26 @@ public class SayMyTextsWidgetProvider extends AppWidgetProvider {
Log.d(TAG, "on receive " + intent.getAction());
if (CLICK_ACTION.equals(intent.getAction())) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
- String key = context.getString(R.string.preference_enable_reading_key);
- boolean enabled = sharedPref.getBoolean(key, true);
- Log.d(TAG, "enabled " + enabled);
- sharedPref.edit().putBoolean(key, !enabled).commit();
+// String key = context.getString(R.string.preference_enable_reading_key);
+// boolean enabled = sharedPref.getBoolean(key, true);
+// Log.d(TAG, "enabled " + enabled);
+// sharedPref.edit().putBoolean(key, !enabled).commit();
}
}
protected RemoteViews updateButtonState(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
- String key = context.getString(R.string.preference_enable_reading_key);
-
- boolean enabled = sharedPreferences.getBoolean(key, true);
- int drawableId = enabled ?
- android.R.drawable.button_onoff_indicator_on :
- android.R.drawable.button_onoff_indicator_off;
-
- RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.say_my_texts_widget);
- views.setImageViewResource(R.id.say_my_texts_widget_onoff_icon, drawableId);
-
- return views;
+// String key = context.getString(R.string.preference_enable_reading_key);
+//
+// boolean enabled = sharedPreferences.getBoolean(key, true);
+// int drawableId = enabled ?
+// android.R.drawable.button_onoff_indicator_on :
+// android.R.drawable.button_onoff_indicator_off;
+//
+// RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.say_my_texts_widget);
+// views.setImageViewResource(R.id.say_my_texts_widget_onoff_icon, drawableId);
+
+// return views;
+ return null;
}
}
diff --git a/src/org/chorem/android/saymytexts/SettingsActivity.java b/src/org/chorem/android/saymytexts/SettingsActivity.java
index 2a0f1c8..aeaf63f 100644
--- a/src/org/chorem/android/saymytexts/SettingsActivity.java
+++ b/src/org/chorem/android/saymytexts/SettingsActivity.java
@@ -34,6 +34,7 @@ import android.database.Cursor;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
+import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
@@ -89,7 +90,8 @@ public class SettingsActivity extends Activity {
}
}
- public static class SettingsFragment extends PreferenceFragment {
+ public static class SettingsFragment extends PreferenceFragment
+ implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -128,15 +130,32 @@ public class SettingsActivity extends Activity {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
- String key = getString(R.string.preference_enable_reading_key);
- SwitchPreference enableReadingPref = (SwitchPreference) getPreferenceScreen().findPreference(key);
- boolean enabled = sharedPref.getBoolean(key, enableReadingPref.isChecked());
- enableReadingPref.setChecked(enabled);
+ String key = getString(R.string.preference_reading_profile_key);
+ ListPreference preference = (ListPreference) findPreference(key);
+ CharSequence summary = preference.getEntry();
+ preference.setSummary(summary);
+
+ key = getString(R.string.preference_enable_interaction_key);
+ SwitchPreference switchPreference = (SwitchPreference) findPreference(key);
+ boolean enabled = sharedPref.getBoolean(key, switchPreference.isChecked());
+ switchPreference.setChecked(enabled);
key = getString(R.string.preference_enable_heisendroid_mode_key);
- enableReadingPref = (SwitchPreference) getPreferenceScreen().findPreference(key);
- enabled = sharedPref.getBoolean(key, enableReadingPref.isChecked());
- enableReadingPref.setChecked(enabled);
+ switchPreference = (SwitchPreference) findPreference(key);
+ enabled = sharedPref.getBoolean(key, switchPreference.isChecked());
+ switchPreference.setChecked(enabled);
+
+ sharedPref.registerOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+
+ if (getString(R.string.preference_reading_profile_key).equals(key)) {
+ ListPreference preference = (ListPreference) findPreference(key);
+ CharSequence summary = preference.getEntry();
+ preference.setSummary(summary);
+ }
}
protected void addWebsitePreferenceClickListener(int keyId) {
--
To stop receiving notification emails like this one, please contact
chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository say-my-texts.
See http://git.chorem.org/say-my-texts.git
commit a834a05f2d325d73bf4c3c0e79129fc32fabba9f
Author: Kevin Morin <morin(a)codelutin.com>
Date: Sat Apr 26 20:02:37 2014 +0000
fixes #1009 [Settings] Enable the answer to a sms
---
res/values-fr/strings.xml | 1 +
res/values/preference_keys.xml | 1 +
res/values/strings.xml | 1 +
res/xml/preferences.xml | 4 ++++
src/org/chorem/android/saymytexts/SayMyTextService.java | 7 ++++++-
5 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index 13c2e6d..6ecfea7 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -8,6 +8,7 @@
<!-- Preferences -->
<string name="preferences_settings_label">Paramètres</string>
<string name="preference_enable_reading_label">Lecture des SMS</string>
+ <string name="preference_enable_interaction_label">Intéraction (appel ou réponse)</string>
<string name="preference_enable_heisendroid_mode_label">Mode Heisendroid</string>
<string name="preference_test_sms_label">Tester en m\'envoyant un SMS</string>
<string name="test_sms_content">Heisendroïd</string>
diff --git a/res/values/preference_keys.xml b/res/values/preference_keys.xml
index 2fe1b9b..b10ea17 100644
--- a/res/values/preference_keys.xml
+++ b/res/values/preference_keys.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="preference_enable_reading_key">enable_reading</string>
+ <string name="preference_enable_interaction_key">enable_interaction</string>
<string name="preference_enable_heisendroid_mode_key">enable_heisendroid_mode</string>
<string name="preference_test_sms_key">test_sms</string>
<string name="preference_version_key">version</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index bd0f4c1..ffdde79 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -8,6 +8,7 @@
<!-- Preferences -->
<string name="preferences_settings_label">Settings</string>
<string name="preference_enable_reading_label">SMS reading</string>
+ <string name="preference_enable_interaction_label">Interaction (call or answer)</string>
<string name="preference_enable_heisendroid_mode_label">Heisendroid mode</string>
<string name="preference_test_sms_label">Test by sending an SMS to myself</string>
<string name="test_sms_content">Heisendroïd</string>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 972d6fb..1c6e89a 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -8,6 +8,10 @@
android:title="@string/preference_enable_reading_label"
android:defaultValue="true" />
+ <SwitchPreference android:key="@string/preference_enable_interaction_key"
+ android:title="@string/preference_enable_interaction_label"
+ android:defaultValue="true" />
+
<SwitchPreference android:key="@string/preference_enable_heisendroid_mode_key"
android:title="@string/preference_enable_heisendroid_mode_label"
android:defaultValue="false" />
diff --git a/src/org/chorem/android/saymytexts/SayMyTextService.java b/src/org/chorem/android/saymytexts/SayMyTextService.java
index 8dd2d7a..aceb047 100644
--- a/src/org/chorem/android/saymytexts/SayMyTextService.java
+++ b/src/org/chorem/android/saymytexts/SayMyTextService.java
@@ -384,7 +384,12 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params);
}
- askForActionAfterReading(sms, btConnected, 1);
+ String interactionPrefKey = getString(R.string.preference_enable_interaction_key);
+ if (sharedPref.getBoolean(interactionPrefKey, true)) {
+ askForActionAfterReading(sms, btConnected, 1);
+ } else {
+ setCanSpeak(true);
+ }
}
protected void askForActionAfterReading(final SMS sms, boolean btConnected, final int attemptNumber) {
--
To stop receiving notification emails like this one, please contact
chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
04/10: refs #999 Answer to a sms : reask dictating the message if the user says nothing understandable
by chorem.org scm 25 May '14
by chorem.org scm 25 May '14
25 May '14
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository say-my-texts.
See http://git.chorem.org/say-my-texts.git
commit 4404a9d192095fc6ef5233bd7affa9f17d1bc8be
Author: Kevin Morin <morin(a)codelutin.com>
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(a)chorem.org>.
1
0
03/10: refs #999 Answer to a sms : reask saying the action if the user says nothing understandable
by chorem.org scm 25 May '14
by chorem.org scm 25 May '14
25 May '14
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository say-my-texts.
See http://git.chorem.org/say-my-texts.git
commit 4aadb7611b3fae4c6f64255b5e2f35b1b1702f07
Author: Kevin Morin <morin(a)codelutin.com>
Date: Wed Apr 16 07:41:48 2014 +0000
refs #999 Answer to a sms : reask saying the action if the user says nothing understandable
---
pom.xml | 8 +-
res/values-fr/strings.xml | 2 +
res/values/strings.xml | 1 +
.../android/saymytexts/SayMyTextService.java | 259 +++++++++++++--------
.../saymytexts/SayNextActionBroadcastReceiver.java | 30 ++-
5 files changed, 196 insertions(+), 104 deletions(-)
diff --git a/pom.xml b/pom.xml
index 2bda178..b6ed9c4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>5.0.1</version>
+ <version>5.0.5</version>
</parent>
<groupId>org.chorem.android</groupId>
@@ -153,6 +153,12 @@
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>${guavaVersion}</version>
+ </dependency>
+
+ <dependency>
<groupId>ch.acra</groupId>
<artifactId>acra</artifactId>
<version>4.5.0</version>
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index b652157..6251e8e 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -39,4 +39,6 @@
<string name="modifiy_action">corriger</string>
<string name="cancel_action">annuler</string>
+ <string name="voice_not_recognized">Je n\'ai pas compris.</string>
+
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 182790a..f77751d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -39,5 +39,6 @@
<string name="confirm_action">confirm</string>
<string name="modifiy_action">modify</string>
<string name="cancel_action">cancel</string>
+ <string name="voice_not_recognized">I did not understand.</string>
</resources>
diff --git a/src/org/chorem/android/saymytexts/SayMyTextService.java b/src/org/chorem/android/saymytexts/SayMyTextService.java
index c137d98..6056a0f 100644
--- a/src/org/chorem/android/saymytexts/SayMyTextService.java
+++ b/src/org/chorem/android/saymytexts/SayMyTextService.java
@@ -26,6 +26,7 @@ package org.chorem.android.saymytexts;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothHeadset;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -39,9 +40,9 @@ import android.speech.tts.UtteranceProgressListener;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
+import com.google.common.base.Function;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -60,6 +61,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
public static final String ACTION_READ_SMS = "org.chorem.android.saymytexts.READ_SMS";
public static final String ACTION_READ_NEXT_SMS = "org.chorem.android.saymytexts.READ_NEXT_SMS";
public static final String ACTION_MANAGE_BT_DEVICE = "org.chorem.android.saymytexts.ADD_BT_DEVICE";
+ public static final String ACTION_REASK_ACTION = "org.chorem.android.saymytexts.REASK_ACTION";
public static final String ACTION_DICTATE_SMS = "org.chorem.android.saymytexts.DICTATE_SMS";
public static final String ACTION_CONFIRM_SMS_SENDING = "org.chorem.android.saymytexts.CONFIRM_SMS_SENDING";
@@ -71,6 +73,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
public static final String INTENT_EXTRA_ADD_BT_DEVICE = "addBtDevice";
/** Bluetooth device which has just connected or disconnected */
public static final String INTENT_EXTRA_DICTATED_MESSAGE = "dictatedMessage";
+ /** Attempt number: if set, it means that the user said something not understandable, so ask again */
+ public static final String INTENT_EXTRA_ATTEMPT_NUMBER = "attemptNumber";
/** utterance id when the bluetooth device is connected */
protected static final String BT_UTTERANCE_ID = "btUtteranceId";
@@ -104,6 +108,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
}
};
+ BluetoothHeadset mBluetoothHeadset;
+
@Override
public void onCreate() {
super.onCreate();
@@ -120,6 +126,34 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
intentFilter = new IntentFilter(DictateSmsBroadcastReceiver.ACTION_DICTATE_SMS);
registerReceiver(new DictateSmsBroadcastReceiver(), intentFilter);
+
+//// Get the default adapter
+// final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+//
+//// Define Service Listener of BluetoothProfile
+// BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
+// public void onServiceConnected(int profile, BluetoothProfile proxy) {
+// if (profile == BluetoothProfile.HEADSET) {
+// mBluetoothHeadset = (BluetoothHeadset) proxy;
+// List<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices();
+// for ( final BluetoothDevice dev : devices ) {
+// if (mBluetoothHeadset.isAudioConnected(dev)) {
+// bluetoothDevices.put(dev, dev.getBluetoothClass().getDeviceClass());
+// }
+// }
+// mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
+// }
+// }
+// public void onServiceDisconnected(int profile) {
+// if (profile == BluetoothProfile.HEADSET) {
+// mBluetoothHeadset = null;
+// }
+// }
+// };
+//
+//// Establish connection to the proxy.
+// mBluetoothAdapter.getProfileProxy(this, mProfileListener, BluetoothProfile.HEADSET);
+
}
@Override
@@ -148,6 +182,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
Log.d(TAG, "action " + action);
final SMS sms = (SMS) intent.getSerializableExtra(INTENT_EXTRA_SMS);
+ int attemptNumber = intent.getIntExtra(INTENT_EXTRA_ATTEMPT_NUMBER, 0);
+
switch (action) {
case ACTION_MANAGE_BT_DEVICE:
BluetoothDevice device = intent.getParcelableExtra(INTENT_EXTRA_BT_DEVICE);
@@ -163,46 +199,47 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
}
break;
+ case ACTION_REASK_ACTION:
+ askForActionAfterReading(sms, !bluetoothDevices.isEmpty(), ++attemptNumber);
+ break;
+
case ACTION_DICTATE_SMS:
- if (!bluetoothDevices.isEmpty()) {
- registerReceiver(new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE);
- if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
- context.unregisterReceiver(this);
- dictateSMS(sms);
- }
- }
- }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
- audioManager.setMode(AudioManager.MODE_IN_CALL);
- audioManager.startBluetoothSco();
-
- } else {
- dictateSMS(sms);
+ if (attemptNumber > 0) {
+
}
+// if (bluetoothDevices.isEmpty()) {
+ dictateSMS(sms, attemptNumber + 1);
+// } else {
+// requestBluetoothSpeakingActivation(new Function<Void, Void>() {
+// @Override
+// public Void apply(Void input) {
+// dictateSMS(sms);
+// return null;
+// }
+// });
+// }
break;
case ACTION_CONFIRM_SMS_SENDING:
// if a message has just been dictated
final String dictatedMessage = intent.getStringExtra(INTENT_EXTRA_DICTATED_MESSAGE);
- if (!bluetoothDevices.isEmpty()) {
- registerReceiver(new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE);
- if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
- context.unregisterReceiver(this);
- askSendingConfirmation(dictatedMessage, sms);
- }
- }
- }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
- audioManager.setMode(AudioManager.MODE_IN_CALL);
- audioManager.startBluetoothSco();
-
- } else {
- askSendingConfirmation(dictatedMessage, sms);
- }
+// if (!bluetoothDevices.isEmpty()) {
+// registerReceiver(new BroadcastReceiver() {
+// @Override
+// public void onReceive(Context context, Intent intent) {
+// int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE);
+// if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
+// context.unregisterReceiver(this);
+// askSendingConfirmation(dictatedMessage, sms);
+// }
+// }
+// }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
+// audioManager.setMode(AudioManager.MODE_IN_CALL);
+// audioManager.startBluetoothSco();
+//
+// } else {
+ askSendingConfirmation(dictatedMessage, sms, ++attemptNumber);
+// }
break;
case ACTION_READ_NEXT_SMS:
@@ -248,9 +285,15 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
*/
protected void setCanSpeak(Boolean canSpeak) {
this.canSpeak = canSpeak;
- if (Boolean.TRUE.equals(canSpeak) && !awaitingTexts.isEmpty()) {
- SMS sms = awaitingTexts.remove(0);
- requestReading(sms);
+ if (Boolean.TRUE.equals(canSpeak)) {
+ if (!awaitingTexts.isEmpty()) {
+ SMS sms = awaitingTexts.remove(0);
+ requestReading(sms);
+
+ } else if (!bluetoothDevices.isEmpty()) {
+ audioManager.stopBluetoothSco();
+ audioManager.setMode(AudioManager.MODE_NORMAL);
+ }
}
}
@@ -258,26 +301,32 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
* Requests the reading of one text through the wired headset or bluetooth device
* @param sms the text to read
*/
- protected void requestReading(SMS sms) {
+ protected void requestReading(final SMS sms) {
if (bluetoothDevices.isEmpty()) {
readText(sms, false);
} else {
- requestReadingOverBt(sms);
+ requestBluetoothSpeakingActivation(new Function<Void, Void>() {
+ @Override
+ public Void apply(Void input) {
+ readText(sms, true);
+ return null;
+ }
+ });
}
}
/**
* Starts the connection with the bluetooth device and requests the reading
- * @param sms the texts to read
+ * @param callback the function called when the bluetooth is ready
*/
- protected void requestReadingOverBt(final SMS sms) {
+ protected void requestBluetoothSpeakingActivation(final Function<Void, Void> callback) {
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE);
if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
context.unregisterReceiver(this);
- readText(sms, true);
+ callback.apply(null);
}
}
}, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
@@ -300,7 +349,36 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
// waiting = true;
- // init texttospeech
+ HashMap<String, String> params = new HashMap<>();
+ params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));
+// if (btConnected) {
+// params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, BT_UTTERANCE_ID);
+// }
+
+ if (heisendroidModeEnabled) {
+ textToSpeech.setLanguage(Locale.US);
+ textToSpeech.setSpeechRate(0.3f);
+ textToSpeech.setPitch(0.1f);
+ textToSpeech.speak("Say my text.", TextToSpeech.QUEUE_ADD, params);
+ }
+
+ textToSpeech.setLanguage(Locale.getDefault());
+ textToSpeech.setSpeechRate(1f);
+ textToSpeech.setPitch(1f);
+ String text = getString(R.string.sms_received, sms.getSenderName(), sms.getMessage());
+ textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params);
+
+ if (heisendroidModeEnabled) {
+ textToSpeech.setLanguage(Locale.US);
+ textToSpeech.setSpeechRate(0.3f);
+ textToSpeech.setPitch(0.1f);
+ textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params);
+ }
+
+ askForActionAfterReading(sms, btConnected, 1);
+ }
+
+ protected void askForActionAfterReading(final SMS sms, boolean btConnected, final int attemptNumber) {
textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onStart(String utteranceId) {
@@ -313,17 +391,19 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
@Override
public void onDone(String utteranceId) {
- if (BT_UTTERANCE_ID.equals(utteranceId) ||
- BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) {
- // when the text has been read by the bluetooth device, stop the connection
- audioManager.stopBluetoothSco();
- audioManager.setMode(AudioManager.MODE_NORMAL);
- }
+// if (BT_UTTERANCE_ID.equals(utteranceId)) {
+// // when the text has been read by the bluetooth device, stop the connection
+// audioManager.stopBluetoothSco();
+// audioManager.setMode(AudioManager.MODE_NORMAL);
+// }
if (ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId) ||
BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) {
Intent sayaction = new Intent(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION);
- sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_SMS, sms);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_SMS, sms);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_ATTEMPT_NUMBER, attemptNumber);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_FALLBACK_ACTION, ACTION_REASK_ACTION);
+
sendBroadcast(sayaction);
}
}
@@ -331,39 +411,27 @@ 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));
- if (btConnected) {
- params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, BT_UTTERANCE_ID);
- }
-
- if (heisendroidModeEnabled) {
- textToSpeech.setLanguage(Locale.US);
- textToSpeech.setSpeechRate(0.3f);
- textToSpeech.setPitch(0.1f);
- textToSpeech.speak("Say my text.", TextToSpeech.QUEUE_ADD, params);
- }
textToSpeech.setLanguage(Locale.getDefault());
textToSpeech.setSpeechRate(1f);
textToSpeech.setPitch(1f);
- String text = getString(R.string.sms_received, sms.getSenderName(), sms.getMessage());
- textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params);
- if (heisendroidModeEnabled) {
- textToSpeech.setLanguage(Locale.US);
- textToSpeech.setSpeechRate(0.3f);
- textToSpeech.setPitch(0.1f);
- textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params);
+ if (attemptNumber > 1) {
+ textToSpeech.speak(getString(R.string.voice_not_recognized), TextToSpeech.QUEUE_ADD, params);
}
- params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
- btConnected ? BT_ASK_NEXT_ACTION_UTTERANCE_ID : ASK_NEXT_ACTION_UTTERANCE_ID);
- textToSpeech.setLanguage(Locale.getDefault());
- textToSpeech.setSpeechRate(1f);
- textToSpeech.setPitch(1f);
- textToSpeech.speak(getString(R.string.ask_next_action), 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);
+ textToSpeech.speak(getString(R.string.ask_next_action), TextToSpeech.QUEUE_ADD, params);
+
+ } else {
+ setCanSpeak(true);
+ }
}
- protected void dictateSMS(final SMS sms) {
+ protected void dictateSMS(final SMS sms, final int attemptNumber) {
Log.d(TAG, "dictateSMS " );
textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
@@ -377,14 +445,9 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
@Override
public void onDone(String utteranceId) {
- if (BT_UTTERANCE_ID.equals(utteranceId)) {
- // when the text has been read by the bluetooth device, stop the connection
- audioManager.stopBluetoothSco();
- audioManager.setMode(AudioManager.MODE_NORMAL);
- }
-
Intent dictateAction = new Intent(DictateSmsBroadcastReceiver.ACTION_DICTATE_SMS);
dictateAction.putExtra(DictateSmsBroadcastReceiver.EXTRA_SMS, sms);
+// dictateAction.putExtra(DictateSmsBroadcastReceiver.INTENT_EXTRA_SMS, attemptNumber);
sendBroadcast(dictateAction);
}
@@ -392,8 +455,7 @@ 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,
- bluetoothDevices.isEmpty() ? BT_UTTERANCE_ID : OTHER_UTTERANCE_ID);
+ params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, OTHER_UTTERANCE_ID);
textToSpeech.setLanguage(Locale.getDefault());
textToSpeech.setSpeechRate(1f);
@@ -402,7 +464,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak("dictez votre sms", TextToSpeech.QUEUE_ADD, params);
}
- protected void askSendingConfirmation(final String message, final SMS originSms) {
+ protected void askSendingConfirmation(final String message, final SMS originSms, final int attemptNumber) {
Log.d(TAG, "askSendingConfirmation " + message);
textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
@@ -416,15 +478,11 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
@Override
public void onDone(String utteranceId) {
- if (BT_UTTERANCE_ID.equals(utteranceId)) {
- // when the text has been read by the bluetooth device, stop the connection
- audioManager.stopBluetoothSco();
- audioManager.setMode(AudioManager.MODE_NORMAL);
- }
-
Intent sayaction = new Intent(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION);
- sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_SMS, originSms);
- sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_MESSAGE, message);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_SMS, originSms);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_MESSAGE, message);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_ATTEMPT_NUMBER, attemptNumber);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.INTENT_EXTRA_FALLBACK_ACTION, ACTION_CONFIRM_SMS_SENDING);
sendBroadcast(sayaction);
}
@@ -432,14 +490,25 @@ 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,
- bluetoothDevices.isEmpty() ? BT_UTTERANCE_ID : OTHER_UTTERANCE_ID);
textToSpeech.setLanguage(Locale.getDefault());
textToSpeech.setSpeechRate(1f);
textToSpeech.setPitch(1f);
- String text = getString(R.string.send_sms_confirmation, message);
- textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params);
+
+ if (attemptNumber > 1) {
+ 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);
+ textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params);
+
+ } else {
+ setCanSpeak(true);
+ }
+
}
}
diff --git a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java b/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
index 5689405..4d7bae4 100644
--- a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
+++ b/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
@@ -4,7 +4,6 @@ import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import android.content.IntentFilter;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.net.Uri;
@@ -27,13 +26,15 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
public static final String ACTION_SAY_NEXT_ACTION = "org.chorem.android.saymytexts.SAY_NEXT_ACTION";
- public static final String EXTRA_SMS = "sms";
- public static final String EXTRA_MESSAGE = "message";
+ public static final String INTENT_EXTRA_SMS = "sms";
+ public static final String INTENT_EXTRA_MESSAGE = "message";
+ public static final String INTENT_EXTRA_ATTEMPT_NUMBER = "attemptNumber";
+ public static final String INTENT_EXTRA_FALLBACK_ACTION = "fallbackAction";
@Override
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);
@@ -66,7 +67,7 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
//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);
- readNext(context);
+ reaskAction(context, intent, sms);
}
@Override
@@ -99,7 +100,7 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
context.startService(serviceIntent);
} else if (results.contains(context.getString(R.string.confirm_action))) {
- String message = intent.getStringExtra(EXTRA_MESSAGE);
+ String message = intent.getStringExtra(INTENT_EXTRA_MESSAGE);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(sms.getSenderNumber(), null, message, null, null);
@@ -116,8 +117,8 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
readNext(context);
} else {
- //TODO add a counter to ask only twice (or 3 times, or it should be configurable)
- // recognizeVoice(sms);
+ tg.startTone(ToneGenerator.TONE_PROP_NACK);
+ reaskAction(context, intent, sms);
}
}
}
@@ -138,6 +139,19 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
}
}
+ protected void reaskAction(Context context, Intent intent, SMS sms) {
+ int attemptNumber = intent.getIntExtra(INTENT_EXTRA_ATTEMPT_NUMBER, 1);
+ String fallbackAction = intent.getStringExtra(INTENT_EXTRA_FALLBACK_ACTION);
+ String dictatedMessage = intent.getStringExtra(INTENT_EXTRA_MESSAGE);
+
+ Intent serviceIntent = new Intent(context, SayMyTextService.class);
+ serviceIntent.setAction(fallbackAction);
+ serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_SMS, sms);
+ serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_ATTEMPT_NUMBER, attemptNumber);
+ serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_DICTATED_MESSAGE, dictatedMessage);
+ context.startService(serviceIntent);
+ }
+
protected void readNext(Context context) {
Intent serviceIntent = new Intent(context, SayMyTextService.class);
serviceIntent.setAction(SayMyTextService.ACTION_READ_NEXT_SMS);
--
To stop receiving notification emails like this one, please contact
chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository say-my-texts.
See http://git.chorem.org/say-my-texts.git
commit bfe79b778e479eacd335b8b9faac1549aef9aab3
Author: Kevin Morin <morin(a)codelutin.com>
Date: Mon Apr 7 21:16:56 2014 +0000
fixes #1008 Send back an SMS to the sender
---
res/values-fr/strings.xml | 3 +-
res/values/strings.xml | 4 +-
...eiver.java => DictateSmsBroadcastReceiver.java} | 41 +--
.../saymytexts/NewTextBroadcastReceiver.java | 3 +-
.../android/saymytexts/SayMyTextService.java | 319 +++++++++++++++------
.../saymytexts/SayNextActionBroadcastReceiver.java | 51 +++-
6 files changed, 290 insertions(+), 131 deletions(-)
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index 05dbca1..b652157 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -3,7 +3,7 @@
<string name="app_name">Say My Texts</string>
<string name="app_description">Application Android qui lit à voix haute the SMS reçus quand un casque est branché.</string>
- <string name="sms_received">Nouveau message de %1$s : %2$s</string>
+ <string name="sms_received">Nouveau message de %1$s : %2$s.</string>
<!-- Preferences -->
<string name="preferences_settings_label">Paramètres</string>
@@ -29,6 +29,7 @@
<!-- actions -->
<string name="ask_next_action">Que voulez-vous faire ? Appeler, répondre ou quitter ?</string>
+ <string name="send_sms_confirmation">Vous avez dicté : %s. Voulez-vous confirmer, corriger ou annuler ?</string>
<string name="call_action">appeler</string>
<string name="answer_action">répondre</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ee0365f..182790a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3,7 +3,7 @@
<string name="app_name">Say My Texts</string>
<string name="app_description">Android application which reads out loud the new SMS when the headset is plugged.</string>
- <string name="sms_received">New message from %1$s: %2$s</string>
+ <string name="sms_received">New message from %1$s: %2$s.</string>
<!-- Preferences -->
<string name="preferences_settings_label">Settings</string>
@@ -30,6 +30,8 @@
<!-- actions -->
<string name="ask_next_action">What would you like to do? Call, answer or quit?</string>
+ <string name="send_sms_confirmation">You dictated: %s. Would you like to confirm, modify ou cancel?</string>
+
<string name="call_action">call</string>
<string name="answer_action">answer</string>
<string name="quit_action">quit</string>
diff --git a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java b/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java
similarity index 60%
copy from src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
copy to src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java
index 221ea1b..edad8ef 100644
--- a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
+++ b/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java
@@ -1,5 +1,6 @@
package org.chorem.android.saymytexts;
+import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -9,6 +10,7 @@ import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
+import android.telephony.SmsManager;
import android.util.Log;
import java.util.List;
@@ -17,23 +19,21 @@ import java.util.List;
* @author Kevin Morin (Code Lutin)
* @since x.x
*/
-public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
+public class DictateSmsBroadcastReceiver extends BroadcastReceiver {
- private static final String TAG = "SayNextActionBroadcastReceiver";
+ private static final String TAG = "DictateSmsBroadcastReceiver";
- public static final String ACTION_SAY_NEXT_ACTION = "org.chorem.android.saymytexts.SAY_NEXT_ACTION";
+ public static final String ACTION_DICTATE_SMS = "org.chorem.android.saymytexts.DICTATE_SMS";
public static final String EXTRA_SMS = "sms";
- protected SpeechRecognizer speechRecognizer;
-
@Override
public void onReceive(final Context context, Intent intent) {
Log.d(TAG, "next action ?");
final SMS sms = (SMS) intent.getSerializableExtra(EXTRA_SMS);
if (sms != null) {
- speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context);
+ SpeechRecognizer speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context);
speechRecognizer.setRecognitionListener(new RecognitionListener() {
@Override
public void onReadyForSpeech(Bundle params) {
@@ -67,29 +67,12 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
Log.d(TAG, "results " + results);
if (results != null) {
-
- if (results.contains(context.getString(R.string.call_action))) {
- try {
- Intent callIntent = new Intent(Intent.ACTION_CALL);
- callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- callIntent.setData(Uri.parse("tel:" + sms.getSenderNumber()));
- context.startActivity(callIntent);
-
- } catch (ActivityNotFoundException activityException) {
- Log.e(TAG, "Calling a Phone Number failed", activityException);
- }
-
- } else if (results.contains(context.getString(R.string.answer_action))) {
- //TODO ask the user to dictate the message
- Log.d(TAG, "Répondre");
-
- } else if (results.contains(context.getString(R.string.quit_action))) {
- // do nothing
-
- } else {
- //TODO add a counter to ask only twice (or 3 times, or it should be configurable)
- // recognizeVoice(sms);
- }
+ String text = results.get(0);
+ Intent serviceIntent = new Intent(context, SayMyTextService.class);
+ serviceIntent.setAction(SayMyTextService.ACTION_CONFIRM_SMS_SENDING);
+ serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_SMS, sms);
+ serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_DICTATED_MESSAGE, text);
+ context.startService(serviceIntent);
}
}
diff --git a/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java b/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java
index f589aa9..d8db7f0 100644
--- a/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java
+++ b/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java
@@ -51,7 +51,6 @@ public class NewTextBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent(context, SayMyTextService.class);
-Log.d(TAG, "received");
String action = intent.getAction();
if ("android.provider.Telephony.SMS_RECEIVED".equals(action)) {
@@ -77,11 +76,13 @@ Log.d(TAG, "received");
Log.d(TAG,messageReceived);
// start the service to say it out loud
serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_SMS, sms);
+ serviceIntent.setAction(SayMyTextService.ACTION_READ_SMS);
context.startService(serviceIntent);
}
} else {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ serviceIntent.setAction(SayMyTextService.ACTION_MANAGE_BT_DEVICE);
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
int majorDeviceClass = device.getBluetoothClass().getMajorDeviceClass();
diff --git a/src/org/chorem/android/saymytexts/SayMyTextService.java b/src/org/chorem/android/saymytexts/SayMyTextService.java
index d7c218e..c137d98 100644
--- a/src/org/chorem/android/saymytexts/SayMyTextService.java
+++ b/src/org/chorem/android/saymytexts/SayMyTextService.java
@@ -57,17 +57,26 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
private static final String TAG = "SayMyTextService";
+ public static final String ACTION_READ_SMS = "org.chorem.android.saymytexts.READ_SMS";
+ public static final String ACTION_READ_NEXT_SMS = "org.chorem.android.saymytexts.READ_NEXT_SMS";
+ public static final String ACTION_MANAGE_BT_DEVICE = "org.chorem.android.saymytexts.ADD_BT_DEVICE";
+ public static final String ACTION_DICTATE_SMS = "org.chorem.android.saymytexts.DICTATE_SMS";
+ public static final String ACTION_CONFIRM_SMS_SENDING = "org.chorem.android.saymytexts.CONFIRM_SMS_SENDING";
+
/** SMS to read */
public static final String INTENT_EXTRA_SMS = "sms";
/** Bluetooth device which has just connected or disconnected */
public static final String INTENT_EXTRA_BT_DEVICE = "btDevice";
/** If true, the device has just connected, else disconnected */
public static final String INTENT_EXTRA_ADD_BT_DEVICE = "addBtDevice";
+ /** Bluetooth device which has just connected or disconnected */
+ public static final String INTENT_EXTRA_DICTATED_MESSAGE = "dictatedMessage";
/** utterance id when the bluetooth device is connected */
protected static final String BT_UTTERANCE_ID = "btUtteranceId";
protected static final String BT_ASK_NEXT_ACTION_UTTERANCE_ID = "btAskNextActionUtteranceId";
protected static final String ASK_NEXT_ACTION_UTTERANCE_ID = "askNextActionUtteranceId";
+ protected static final String OTHER_UTTERANCE_ID = "oherUtteranceId";
protected AudioManager audioManager;
@@ -83,7 +92,7 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
protected Map<BluetoothDevice, Integer> bluetoothDevices = new HashMap<>();
/**
- * Listener to clal state change
+ * Listener to call state change
*/
protected final PhoneStateListener callStateListener = new PhoneStateListener() {
@Override
@@ -108,6 +117,9 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
IntentFilter intentFilter = new IntentFilter(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION);
registerReceiver(new SayNextActionBroadcastReceiver(), intentFilter);
+
+ intentFilter = new IntentFilter(DictateSmsBroadcastReceiver.ACTION_DICTATE_SMS);
+ registerReceiver(new DictateSmsBroadcastReceiver(), intentFilter);
}
@Override
@@ -132,28 +144,81 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
boolean readingEnabled = sharedPref.getBoolean(readingEnabledKey, true);
if (intent != null) {
- BluetoothDevice device = intent.getParcelableExtra(INTENT_EXTRA_BT_DEVICE);
- // if a device is passed to the service
- // add or remove the device from the connected devices
- if (device != null) {
- boolean addBtDevice = intent.getBooleanExtra(INTENT_EXTRA_ADD_BT_DEVICE, false);
- if (addBtDevice) {
- bluetoothDevices.put(device, device.getBluetoothClass().getDeviceClass());
- } else {
- bluetoothDevices.remove(device);
- }
-
-
- // else if the user enabled the reading and
- // if the headset is plugged, or if there is a bluetooth device connected
- } else if (readingEnabled && (audioManager.isWiredHeadsetOn() || !bluetoothDevices.isEmpty())) {
-
- SMS sms = (SMS) intent.getSerializableExtra(INTENT_EXTRA_SMS);
- if (canSpeak != null && canSpeak) {
- requestReading(sms);
- } else {
- awaitingTexts.add(sms);
- }
+ String action = intent.getAction();
+ Log.d(TAG, "action " + action);
+
+ final SMS sms = (SMS) intent.getSerializableExtra(INTENT_EXTRA_SMS);
+ switch (action) {
+ case ACTION_MANAGE_BT_DEVICE:
+ BluetoothDevice device = intent.getParcelableExtra(INTENT_EXTRA_BT_DEVICE);
+ // if a device is passed to the service
+ // add or remove the device from the connected devices
+ if (device != null) {
+ boolean addBtDevice = intent.getBooleanExtra(INTENT_EXTRA_ADD_BT_DEVICE, false);
+ if (addBtDevice) {
+ bluetoothDevices.put(device, device.getBluetoothClass().getDeviceClass());
+ } else {
+ bluetoothDevices.remove(device);
+ }
+ }
+ break;
+
+ case ACTION_DICTATE_SMS:
+ if (!bluetoothDevices.isEmpty()) {
+ registerReceiver(new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE);
+ if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
+ context.unregisterReceiver(this);
+ dictateSMS(sms);
+ }
+ }
+ }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
+ audioManager.setMode(AudioManager.MODE_IN_CALL);
+ audioManager.startBluetoothSco();
+
+ } else {
+ dictateSMS(sms);
+ }
+ break;
+
+ case ACTION_CONFIRM_SMS_SENDING:
+ // if a message has just been dictated
+ final String dictatedMessage = intent.getStringExtra(INTENT_EXTRA_DICTATED_MESSAGE);
+ if (!bluetoothDevices.isEmpty()) {
+ registerReceiver(new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE);
+ if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
+ context.unregisterReceiver(this);
+ askSendingConfirmation(dictatedMessage, sms);
+ }
+ }
+ }, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
+ audioManager.setMode(AudioManager.MODE_IN_CALL);
+ audioManager.startBluetoothSco();
+
+ } else {
+ askSendingConfirmation(dictatedMessage, sms);
+ }
+ break;
+
+ case ACTION_READ_NEXT_SMS:
+ setCanSpeak(true);
+ break;
+
+ default:
+ // 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())) {
+ if (Boolean.TRUE.equals(canSpeak)) {
+ requestReading(sms);
+ } else {
+ awaitingTexts.add(sms);
+ }
+ }
}
result = START_STICKY;
@@ -183,9 +248,9 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
*/
protected void setCanSpeak(Boolean canSpeak) {
this.canSpeak = canSpeak;
- if (canSpeak != null && canSpeak) {
- requestReading(awaitingTexts);
- awaitingTexts.clear();
+ if (Boolean.TRUE.equals(canSpeak) && !awaitingTexts.isEmpty()) {
+ SMS sms = awaitingTexts.remove(0);
+ requestReading(sms);
}
}
@@ -194,33 +259,25 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
* @param sms the text to read
*/
protected void requestReading(SMS sms) {
- requestReading(Collections.singletonList(sms));
- }
-
- /**
- * Requests the reading of a list of texts through the wired headset or bluetooth device
- * @param smsList the texts to read
- */
- protected void requestReading(List<SMS> smsList) {
if (bluetoothDevices.isEmpty()) {
- readText(smsList, false);
+ readText(sms, false);
} else {
- requestReadingOverBt(smsList);
+ requestReadingOverBt(sms);
}
}
/**
* Starts the connection with the bluetooth device and requests the reading
- * @param smsList the texts to read
+ * @param sms the texts to read
*/
- protected void requestReadingOverBt(final List<SMS> smsList) {
+ protected void requestReadingOverBt(final SMS sms) {
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int state = intent.getExtras().getInt(AudioManager.EXTRA_SCO_AUDIO_STATE);
if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
context.unregisterReceiver(this);
- readText(smsList, true);
+ readText(sms, true);
}
}
}, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
@@ -230,79 +287,159 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
/**
* Reads the texts out loud
- * @param smsList the texts to read
+ * @param sms the text to read
* @param btConnected if true, adds the utterance id for the bluetooth device
*/
- protected void readText(List<SMS> smsList, boolean btConnected) {
+ protected void readText(final SMS sms, boolean btConnected) {
+ // disable the reading of the nexts sms while reading the current one
+ setCanSpeak(false);
+
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String heisendroidModeEnabledKey = getString(R.string.preference_enable_heisendroid_mode_key);
boolean heisendroidModeEnabled = sharedPref.getBoolean(heisendroidModeEnabledKey, true);
- for (final SMS sms : smsList) {
// waiting = true;
- // init texttospeech
- textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
- @Override
- public void onStart(String utteranceId) {
+ // init texttospeech
+ textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
+ @Override
+ public void onStart(String utteranceId) {
+ }
+
+ @Override
+ public void onError(String utteranceId) {
+ Log.e(TAG, "Error speaking: " + utteranceId);
+ }
+
+ @Override
+ public void onDone(String utteranceId) {
+ if (BT_UTTERANCE_ID.equals(utteranceId) ||
+ BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) {
+ // when the text has been read by the bluetooth device, stop the connection
+ audioManager.stopBluetoothSco();
+ audioManager.setMode(AudioManager.MODE_NORMAL);
}
- @Override
- public void onError(String utteranceId) {
- Log.e(TAG, "Error speaking: " + utteranceId);
+ if (ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId) ||
+ BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) {
+ Intent sayaction = new Intent(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_SMS, sms);
+ sendBroadcast(sayaction);
}
+ }
+ });
- @Override
- public void onDone(String utteranceId) {
- if (BT_UTTERANCE_ID.equals(utteranceId) ||
- BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) {
- // when the text has been read by the bluetooth device, stop the connection
- audioManager.stopBluetoothSco();
- audioManager.setMode(AudioManager.MODE_NORMAL);
- }
+ HashMap<String, String> params = new HashMap<>();
+ params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));
+ if (btConnected) {
+ params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, BT_UTTERANCE_ID);
+ }
- if (ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId) ||
- BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) {
- Intent sayaction = new Intent(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION);
- sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_SMS, sms);
- sendBroadcast(sayaction);
- }
+ if (heisendroidModeEnabled) {
+ textToSpeech.setLanguage(Locale.US);
+ textToSpeech.setSpeechRate(0.3f);
+ textToSpeech.setPitch(0.1f);
+ textToSpeech.speak("Say my text.", TextToSpeech.QUEUE_ADD, params);
+ }
+
+ textToSpeech.setLanguage(Locale.getDefault());
+ textToSpeech.setSpeechRate(1f);
+ textToSpeech.setPitch(1f);
+ String text = getString(R.string.sms_received, sms.getSenderName(), sms.getMessage());
+ textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params);
+
+ if (heisendroidModeEnabled) {
+ textToSpeech.setLanguage(Locale.US);
+ textToSpeech.setSpeechRate(0.3f);
+ textToSpeech.setPitch(0.1f);
+ textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params);
+ }
+
+ params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
+ btConnected ? BT_ASK_NEXT_ACTION_UTTERANCE_ID : ASK_NEXT_ACTION_UTTERANCE_ID);
+ textToSpeech.setLanguage(Locale.getDefault());
+ textToSpeech.setSpeechRate(1f);
+ textToSpeech.setPitch(1f);
+ textToSpeech.speak(getString(R.string.ask_next_action), TextToSpeech.QUEUE_ADD, params);
+ }
+
+ protected void dictateSMS(final SMS sms) {
+ Log.d(TAG, "dictateSMS " );
+ textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
+ @Override
+ public void onStart(String utteranceId) {
+ }
+
+ @Override
+ public void onError(String utteranceId) {
+ Log.e(TAG, "Error speaking: " + utteranceId);
+ }
+
+ @Override
+ public void onDone(String utteranceId) {
+ if (BT_UTTERANCE_ID.equals(utteranceId)) {
+ // when the text has been read by the bluetooth device, stop the connection
+ audioManager.stopBluetoothSco();
+ audioManager.setMode(AudioManager.MODE_NORMAL);
}
- });
- HashMap<String, String> params = new HashMap<>();
- params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));
- if (btConnected) {
- params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, BT_UTTERANCE_ID);
+ Intent dictateAction = new Intent(DictateSmsBroadcastReceiver.ACTION_DICTATE_SMS);
+ dictateAction.putExtra(DictateSmsBroadcastReceiver.EXTRA_SMS, sms);
+ sendBroadcast(dictateAction);
+
}
+ });
+
+ 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,
+ bluetoothDevices.isEmpty() ? BT_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 (heisendroidModeEnabled) {
- textToSpeech.setLanguage(Locale.US);
- textToSpeech.setSpeechRate(0.3f);
- textToSpeech.setPitch(0.1f);
- textToSpeech.speak("Say my text.", TextToSpeech.QUEUE_ADD, params);
+ protected void askSendingConfirmation(final String message, final SMS originSms) {
+ Log.d(TAG, "askSendingConfirmation " + message);
+ textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
+ @Override
+ public void onStart(String utteranceId) {
}
- textToSpeech.setLanguage(Locale.getDefault());
- textToSpeech.setSpeechRate(1f);
- textToSpeech.setPitch(1f);
- String text = getString(R.string.sms_received, sms.getSenderName(), sms.getMessage());
- textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params);
-
- if (heisendroidModeEnabled) {
- textToSpeech.setLanguage(Locale.US);
- textToSpeech.setSpeechRate(0.3f);
- textToSpeech.setPitch(0.1f);
- textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params);
+ @Override
+ public void onError(String utteranceId) {
+ Log.e(TAG, "Error speaking: " + utteranceId);
}
- params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
- btConnected ? BT_ASK_NEXT_ACTION_UTTERANCE_ID : ASK_NEXT_ACTION_UTTERANCE_ID);
- textToSpeech.setLanguage(Locale.getDefault());
- textToSpeech.setSpeechRate(1f);
- textToSpeech.setPitch(1f);
- textToSpeech.speak(getString(R.string.ask_next_action), TextToSpeech.QUEUE_ADD, params);
- }
+ @Override
+ public void onDone(String utteranceId) {
+ if (BT_UTTERANCE_ID.equals(utteranceId)) {
+ // when the text has been read by the bluetooth device, stop the connection
+ audioManager.stopBluetoothSco();
+ audioManager.setMode(AudioManager.MODE_NORMAL);
+ }
+
+ Intent sayaction = new Intent(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_SMS, originSms);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_MESSAGE, message);
+ sendBroadcast(sayaction);
+
+ }
+ });
+
+ 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,
+ bluetoothDevices.isEmpty() ? BT_UTTERANCE_ID : OTHER_UTTERANCE_ID);
+
+ textToSpeech.setLanguage(Locale.getDefault());
+ textToSpeech.setSpeechRate(1f);
+ textToSpeech.setPitch(1f);
+ String text = getString(R.string.send_sms_confirmation, message);
+ textToSpeech.speak(text, TextToSpeech.QUEUE_ADD, params);
}
}
diff --git a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java b/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
index 221ea1b..5689405 100644
--- a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
+++ b/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
@@ -4,11 +4,15 @@ import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
+import android.media.AudioManager;
+import android.media.ToneGenerator;
import android.net.Uri;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
+import android.telephony.SmsManager;
import android.util.Log;
import java.util.List;
@@ -24,17 +28,19 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
public static final String ACTION_SAY_NEXT_ACTION = "org.chorem.android.saymytexts.SAY_NEXT_ACTION";
public static final String EXTRA_SMS = "sms";
-
- protected SpeechRecognizer speechRecognizer;
+ public static final String EXTRA_MESSAGE = "message";
@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);
if (sms != null) {
- speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context);
+ 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) {
}
@@ -59,6 +65,8 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
//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);
+ readNext(context);
}
@Override
@@ -77,14 +85,35 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
} catch (ActivityNotFoundException activityException) {
Log.e(TAG, "Calling a Phone Number failed", activityException);
+ tg.startTone(ToneGenerator.TONE_PROP_NACK);
+ readNext(context);
}
- } else if (results.contains(context.getString(R.string.answer_action))) {
- //TODO ask the user to dictate the message
- Log.d(TAG, "Répondre");
+ } else if (results.contains(context.getString(R.string.answer_action))
+ || results.contains(context.getString(R.string.modifiy_action))) {
+ Log.d(TAG, "Répondre ou corriger");
+
+ Intent serviceIntent = new Intent(context, SayMyTextService.class);
+ serviceIntent.setAction(SayMyTextService.ACTION_DICTATE_SMS);
+ serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_SMS, sms);
+ context.startService(serviceIntent);
+
+ } else if (results.contains(context.getString(R.string.confirm_action))) {
+ String message = intent.getStringExtra(EXTRA_MESSAGE);
+ SmsManager smsManager = SmsManager.getDefault();
+ smsManager.sendTextMessage(sms.getSenderNumber(), null, message, null, null);
- } else if (results.contains(context.getString(R.string.quit_action))) {
+ tg.startTone(ToneGenerator.TONE_PROP_ACK);
+
+ readNext(context);
+
+ } else if (results.contains(context.getString(R.string.quit_action))
+ || results.contains(context.getString(R.string.cancel_action))) {
// do nothing
+ Log.d(TAG, "Quitter");
+ tg.startTone(ToneGenerator.TONE_PROP_ACK);
+
+ readNext(context);
} else {
//TODO add a counter to ask only twice (or 3 times, or it should be configurable)
@@ -108,4 +137,10 @@ public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
speechRecognizer.startListening(recognizeIntent);
}
}
+
+ protected void readNext(Context context) {
+ Intent serviceIntent = new Intent(context, SayMyTextService.class);
+ serviceIntent.setAction(SayMyTextService.ACTION_READ_NEXT_SMS);
+ context.startService(serviceIntent);
+ }
}
--
To stop receiving notification emails like this one, please contact
chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
This is an automated email from the git hooks/post-receive script.
New commit to branch devel in repository say-my-texts.
See http://git.chorem.org/say-my-texts.git
commit bbe1fc2327fd56b9dfeb5a54fc0d1e3a3168d7ed
Author: Kevin Morin <morin(a)codelutin.com>
Date: Thu Apr 3 12:20:29 2014 +0000
refs #999 Answer to a sms
---
res/values-fr/strings.xml | 2 +
res/values/strings.xml | 1 +
.../android/saymytexts/SayMyTextService.java | 178 ++++++---------------
.../saymytexts/SayNextActionBroadcastReceiver.java | 111 +++++++++++++
4 files changed, 163 insertions(+), 129 deletions(-)
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index e58b1aa..05dbca1 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -28,6 +28,8 @@
<string name="crash_dialog_ok_toast">Merci !</string>
<!-- actions -->
+ <string name="ask_next_action">Que voulez-vous faire ? Appeler, répondre ou quitter ?</string>
+
<string name="call_action">appeler</string>
<string name="answer_action">répondre</string>
<string name="quit_action">quitter</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 08e9875..ee0365f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -29,6 +29,7 @@
<string name="crash_dialog_ok_toast">Thank you !</string>
<!-- actions -->
+ <string name="ask_next_action">What would you like to do? Call, answer or quit?</string>
<string name="call_action">call</string>
<string name="answer_action">answer</string>
<string name="quit_action">quit</string>
diff --git a/src/org/chorem/android/saymytexts/SayMyTextService.java b/src/org/chorem/android/saymytexts/SayMyTextService.java
index 5e114a6..d7c218e 100644
--- a/src/org/chorem/android/saymytexts/SayMyTextService.java
+++ b/src/org/chorem/android/saymytexts/SayMyTextService.java
@@ -24,34 +24,21 @@ package org.chorem.android.saymytexts;
* #L%
*/
-import android.app.PendingIntent;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
-import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
-import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
-import android.database.Cursor;
import android.media.AudioManager;
-import android.net.Uri;
-import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
-import android.provider.BaseColumns;
-import android.provider.ContactsContract;
-import android.speech.RecognitionListener;
-import android.speech.RecognizerIntent;
-import android.speech.SpeechRecognizer;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
-import android.widget.Toast;
import java.util.ArrayList;
import java.util.Collections;
@@ -79,7 +66,8 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
/** utterance id when the bluetooth device is connected */
protected static final String BT_UTTERANCE_ID = "btUtteranceId";
- protected static final String OTHER_UTTERANCE_ID = "otherUtteranceId";
+ protected static final String BT_ASK_NEXT_ACTION_UTTERANCE_ID = "btAskNextActionUtteranceId";
+ protected static final String ASK_NEXT_ACTION_UTTERANCE_ID = "askNextActionUtteranceId";
protected AudioManager audioManager;
@@ -88,8 +76,6 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
protected TextToSpeech textToSpeech;
- protected SpeechRecognizer speechRecognizer;
-
/** texts to read, received before the textospeech is ready or while a call is in progress */
protected List<SMS> awaitingTexts = new ArrayList<>();
@@ -114,12 +100,14 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
super.onCreate();
textToSpeech = new TextToSpeech(this, this);
- speechRecognizer = SpeechRecognizer.createSpeechRecognizer(SayMyTextService.this);
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
+
+ IntentFilter intentFilter = new IntentFilter(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION);
+ registerReceiver(new SayNextActionBroadcastReceiver(), intentFilter);
}
@Override
@@ -177,28 +165,6 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
- // init texttospeech
- textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
- @Override
- public void onStart(String utteranceId) {
- }
-
- @Override
- public void onError(String utteranceId) {
- Log.e(TAG, "Error speaking: " + utteranceId);
- }
-
- @Override
- public void onDone(String utteranceId) {
- if (BT_UTTERANCE_ID.equals(utteranceId)) {
- // when the text has been read by the bluetooth device, stop the connection
- audioManager.stopBluetoothSco();
- audioManager.setMode(AudioManager.MODE_NORMAL);
- }
- waiting = false;
- }
- });
-
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
setCanSpeak(tm.getCallState() == TelephonyManager.CALL_STATE_IDLE);
@@ -268,16 +234,48 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
* @param btConnected if true, adds the utterance id for the bluetooth device
*/
protected void readText(List<SMS> smsList, boolean btConnected) {
- 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, btConnected ? BT_UTTERANCE_ID : OTHER_UTTERANCE_ID);
-
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String heisendroidModeEnabledKey = getString(R.string.preference_enable_heisendroid_mode_key);
boolean heisendroidModeEnabled = sharedPref.getBoolean(heisendroidModeEnabledKey, true);
- for (SMS sms : smsList) {
- waiting = true;
+ for (final SMS sms : smsList) {
+// waiting = true;
+
+ // init texttospeech
+ textToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
+ @Override
+ public void onStart(String utteranceId) {
+ }
+
+ @Override
+ public void onError(String utteranceId) {
+ Log.e(TAG, "Error speaking: " + utteranceId);
+ }
+
+ @Override
+ public void onDone(String utteranceId) {
+ if (BT_UTTERANCE_ID.equals(utteranceId) ||
+ BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) {
+ // when the text has been read by the bluetooth device, stop the connection
+ audioManager.stopBluetoothSco();
+ audioManager.setMode(AudioManager.MODE_NORMAL);
+ }
+
+ if (ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId) ||
+ BT_ASK_NEXT_ACTION_UTTERANCE_ID.equals(utteranceId)) {
+ Intent sayaction = new Intent(SayNextActionBroadcastReceiver.ACTION_SAY_NEXT_ACTION);
+ sayaction.putExtra(SayNextActionBroadcastReceiver.EXTRA_SMS, sms);
+ sendBroadcast(sayaction);
+ }
+ }
+ });
+
+ HashMap<String, String> params = new HashMap<>();
+ params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));
+ if (btConnected) {
+ params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, BT_UTTERANCE_ID);
+ }
+
if (heisendroidModeEnabled) {
textToSpeech.setLanguage(Locale.US);
textToSpeech.setSpeechRate(0.3f);
@@ -298,91 +296,13 @@ public class SayMyTextService extends Service implements TextToSpeech.OnInitList
textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params);
}
- while (waiting) {
- }
- waiting = true;
- recognizeVoice(sms);
- while (waiting) {
- }
+ params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
+ btConnected ? BT_ASK_NEXT_ACTION_UTTERANCE_ID : ASK_NEXT_ACTION_UTTERANCE_ID);
+ textToSpeech.setLanguage(Locale.getDefault());
+ textToSpeech.setSpeechRate(1f);
+ textToSpeech.setPitch(1f);
+ textToSpeech.speak(getString(R.string.ask_next_action), TextToSpeech.QUEUE_ADD, params);
}
}
- protected void recognizeVoice(final SMS sms) {
- Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
- // Specify free form input
- intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
- RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
-
- speechRecognizer.setRecognitionListener(new RecognitionListener() {
- @Override
- public void onReadyForSpeech(Bundle params) {
- }
-
- @Override
- public void onBeginningOfSpeech() {
- }
-
- @Override
- public void onRmsChanged(float rmsdB) {
- }
-
- @Override
- public void onBufferReceived(byte[] buffer) {
- }
-
- @Override
- public void onEndOfSpeech() {
- }
-
- @Override
- public void onError(int error) {
- Log.d(TAG, "onError " + error);
- waiting = false;
- }
-
- @Override
- public void onResults(Bundle data) {
- List<String> results = data.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
-
- Log.d(TAG, "results " + results);
- if (results != null) {
-
- if (results.contains(getString(R.string.call_action))) {
- try {
- Intent callIntent = new Intent(Intent.ACTION_CALL);
- callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- callIntent.setData(Uri.parse("tel:" + sms.getSenderNumber()));
- startActivity(callIntent);
-
- } catch (ActivityNotFoundException activityException) {
- Log.e("Calling a Phone Number", "Call failed", activityException);
- }
-
- } else if (results.contains(getString(R.string.answer_action))) {
- //TODO ask the user to dictate the message
- } else if (results.contains(getString(R.string.quit_action))) {
- // do nothing
- } else {
- //TODO add a counter to ask only twice (or 3 times, or it should be configurable)
- recognizeVoice(sms);
- }
- }
-
- waiting = false;
- }
-
- @Override
- public void onPartialResults(Bundle partialResults) {
- }
-
- @Override
- public void onEvent(int eventType, Bundle params) {
- }
- });
-
- speechRecognizer.startListening(intent);
- }
-
- boolean waiting = false;
-
}
diff --git a/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java b/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
new file mode 100644
index 0000000..221ea1b
--- /dev/null
+++ b/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
@@ -0,0 +1,111 @@
+package org.chorem.android.saymytexts;
+
+import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.speech.RecognitionListener;
+import android.speech.RecognizerIntent;
+import android.speech.SpeechRecognizer;
+import android.util.Log;
+
+import java.util.List;
+
+/**
+ * @author Kevin Morin (Code Lutin)
+ * @since x.x
+ */
+public class SayNextActionBroadcastReceiver extends BroadcastReceiver {
+
+ private static final String TAG = "SayNextActionBroadcastReceiver";
+
+ public static final String ACTION_SAY_NEXT_ACTION = "org.chorem.android.saymytexts.SAY_NEXT_ACTION";
+
+ public static final String EXTRA_SMS = "sms";
+
+ protected SpeechRecognizer speechRecognizer;
+
+ @Override
+ public void onReceive(final Context context, Intent intent) {
+ Log.d(TAG, "next action ?");
+ final SMS sms = (SMS) intent.getSerializableExtra(EXTRA_SMS);
+
+ if (sms != null) {
+ speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context);
+ speechRecognizer.setRecognitionListener(new RecognitionListener() {
+ @Override
+ public void onReadyForSpeech(Bundle params) {
+ }
+
+ @Override
+ public void onBeginningOfSpeech() {
+ }
+
+ @Override
+ public void onRmsChanged(float rmsdB) {
+ }
+
+ @Override
+ public void onBufferReceived(byte[] buffer) {}
+
+ @Override
+ public void onEndOfSpeech() {}
+
+ @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
+ }
+
+ @Override
+ public void onResults(Bundle data) {
+ List<String> results = data.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
+
+ Log.d(TAG, "results " + results);
+ if (results != null) {
+
+ if (results.contains(context.getString(R.string.call_action))) {
+ try {
+ Intent callIntent = new Intent(Intent.ACTION_CALL);
+ callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ callIntent.setData(Uri.parse("tel:" + sms.getSenderNumber()));
+ context.startActivity(callIntent);
+
+ } catch (ActivityNotFoundException activityException) {
+ Log.e(TAG, "Calling a Phone Number failed", activityException);
+ }
+
+ } else if (results.contains(context.getString(R.string.answer_action))) {
+ //TODO ask the user to dictate the message
+ Log.d(TAG, "Répondre");
+
+ } else if (results.contains(context.getString(R.string.quit_action))) {
+ // do nothing
+
+ } else {
+ //TODO add a counter to ask only twice (or 3 times, or it should be configurable)
+ // recognizeVoice(sms);
+ }
+ }
+ }
+
+ @Override
+ public void onPartialResults(Bundle partialResults) {}
+
+ @Override
+ public void onEvent(int eventType, Bundle params) {}
+ });
+
+ Intent recognizeIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
+ // Specify free form input
+ recognizeIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
+ RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
+
+ speechRecognizer.startListening(recognizeIntent);
+ }
+ }
+}
--
To stop receiving notification emails like this one, please contact
chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
[say-my-texts-commits] 01/01: update scm info (new git repo instead of svn) and description
by Chorem.org scm 24 May '14
by Chorem.org scm 24 May '14
24 May '14
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 4d7fa9b0552dbad50d8a4c218b62585171190a9d
Author: kmorin <morin(a)codelutin.com>
Date: Sat May 24 17:54:11 2014 +0200
update scm info (new git repo instead of svn) and description
---
pom.xml | 71 +++++++++++++++++++++++++++++++++--------------------------------
1 file changed, 36 insertions(+), 35 deletions(-)
diff --git a/pom.xml b/pom.xml
index 0efac68..e6e50bc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,7 +37,9 @@
<name>Say My Texts</name>
<description>
- Android application which reads out loud the new SMS when the headset is plugged. Very useful when your are riding a bike or running.
+ Say My Texts is an Android application which reads out loud the SMS you receive.
+ This is particulary useful when you are riding, running or driving.
+ You also can reply to the sender by calling him or by dictating the reply.
</description>
<url>https://forge.chorem.org/projects/say-my-texts</url>
<inceptionYear>2014</inceptionYear>
@@ -64,14 +66,13 @@
</developers>
<scm>
- <url>https://svn.chorem.org/say-my-texts</url>
- <connection>
- scm:svn:https://svn.chorem.org/say-my-texts/trunk
- </connection>
+ <connection>scm:git:https://git.chorem.org/say-my-texts.git</connection>
<developerConnection>
- scm:svn:https://svn.chorem.org/say-my-texts/trunk
+ scm:git:https://git.chorem.org/say-my-texts.git
</developerConnection>
+ <url>http://forge.chorem.org/projects/say-my-texts/repository</url>
</scm>
+
<distributionManagement>
<site>
<id>doc.${platform}</id>
@@ -106,35 +107,35 @@
</properties>
- <repositories>
- <repository>
- <id>saymytexts-public-group</id>
- <url>https://nexus.nuiton.org/nexus/content/groups/say-my-texts-group/</url>
- <snapshots>
- <enabled>true</enabled>
- <checksumPolicy>fail</checksumPolicy>
- </snapshots>
- <releases>
- <enabled>true</enabled>
- <checksumPolicy>fail</checksumPolicy>
- </releases>
- </repository>
- </repositories>
-
- <pluginRepositories>
- <pluginRepository>
- <id>saymytexts-public-group</id>
- <url>https://nexus.nuiton.org/nexus/content/groups/say-my-texts-group/</url>
- <snapshots>
- <enabled>true</enabled>
- <checksumPolicy>fail</checksumPolicy>
- </snapshots>
- <releases>
- <enabled>true</enabled>
- <checksumPolicy>fail</checksumPolicy>
- </releases>
- </pluginRepository>
- </pluginRepositories>
+ <!--<repositories>-->
+ <!--<repository>-->
+ <!--<id>saymytexts-public-group</id>-->
+ <!--<url>https://nexus.nuiton.org/nexus/content/groups/say-my-texts-group/</url>-->
+ <!--<snapshots>-->
+ <!--<enabled>true</enabled>-->
+ <!--<checksumPolicy>fail</checksumPolicy>-->
+ <!--</snapshots>-->
+ <!--<releases>-->
+ <!--<enabled>true</enabled>-->
+ <!--<checksumPolicy>fail</checksumPolicy>-->
+ <!--</releases>-->
+ <!--</repository>-->
+ <!--</repositories>-->
+
+ <!--<pluginRepositories>-->
+ <!--<pluginRepository>-->
+ <!--<id>saymytexts-public-group</id>-->
+ <!--<url>https://nexus.nuiton.org/nexus/content/groups/say-my-texts-group/</url>-->
+ <!--<snapshots>-->
+ <!--<enabled>true</enabled>-->
+ <!--<checksumPolicy>fail</checksumPolicy>-->
+ <!--</snapshots>-->
+ <!--<releases>-->
+ <!--<enabled>true</enabled>-->
+ <!--<checksumPolicy>fail</checksumPolicy>-->
+ <!--</releases>-->
+ <!--</pluginRepository>-->
+ <!--</pluginRepositories>-->
<dependencies>
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0
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 d78a2f8ac0f1569c31a51bc5e2a454fd145d46e4
Author: kmorin <kmorin@2d65e43e-0f24-4770-8739-84cc4fd997b9>
Date: Wed May 14 17:54:15 2014 +0000
upgrade mavenpom
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index b6ed9c4..0efac68 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>5.0.5</version>
+ <version>5.0.6</version>
</parent>
<groupId>org.chorem.android</groupId>
--
To stop receiving notification emails like this one, please contact
Chorem.org SCM administrator <admin+scm(a)chorem.org>.
1
0