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
April 2014
- 1 participants
- 7 discussions
r46 - in trunk: res/values res/values-fr res/xml src/org/chorem/android/saymytexts
by kmorin@users.chorem.org 28 Apr '14
by kmorin@users.chorem.org 28 Apr '14
28 Apr '14
Author: kmorin
Date: 2014-04-28 22:06:47 +0200 (Mon, 28 Apr 2014)
New Revision: 46
Url: http://forge.chorem.org/projects/say-my-texts/repository/revisions/46
Log:
fixes #1018 [Settings] Make reading profiles
Added:
trunk/res/values-fr/arrays.xml
trunk/res/values/arrays.xml
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/preference_keys.xml
trunk/res/values/strings.xml
trunk/res/xml/preferences.xml
trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
trunk/src/org/chorem/android/saymytexts/SayMyTextsWidgetProvider.java
trunk/src/org/chorem/android/saymytexts/SettingsActivity.java
Added: trunk/res/values/arrays.xml
===================================================================
--- trunk/res/values/arrays.xml (rev 0)
+++ trunk/res/values/arrays.xml 2014-04-28 20:06:47 UTC (rev 46)
@@ -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
Modified: trunk/res/values/preference_keys.xml
===================================================================
--- trunk/res/values/preference_keys.xml 2014-04-26 20:02:37 UTC (rev 45)
+++ trunk/res/values/preference_keys.xml 2014-04-28 20:06:47 UTC (rev 46)
@@ -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>
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-04-26 20:02:37 UTC (rev 45)
+++ trunk/res/values/strings.xml 2014-04-28 20:06:47 UTC (rev 46)
@@ -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>
Added: trunk/res/values-fr/arrays.xml
===================================================================
--- trunk/res/values-fr/arrays.xml (rev 0)
+++ trunk/res/values-fr/arrays.xml 2014-04-28 20:06:47 UTC (rev 46)
@@ -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
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-04-26 20:02:37 UTC (rev 45)
+++ trunk/res/values-fr/strings.xml 2014-04-28 20:06:47 UTC (rev 46)
@@ -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>
Modified: trunk/res/xml/preferences.xml
===================================================================
--- trunk/res/xml/preferences.xml 2014-04-26 20:02:37 UTC (rev 45)
+++ trunk/res/xml/preferences.xml 2014-04-28 20:06:47 UTC (rev 46)
@@ -4,10 +4,13 @@
<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"
android:defaultValue="true" />
Modified: trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-26 20:02:37 UTC (rev 45)
+++ trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-28 20:06:47 UTC (rev 46)
@@ -87,9 +87,12 @@
/** 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 @@
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 @@
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 @@
} 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,14 +386,33 @@
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));
// 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);
textToSpeech.setSpeechRate(0.3f);
@@ -371,6 +420,9 @@
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 @@
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);
}
}
Modified: trunk/src/org/chorem/android/saymytexts/SayMyTextsWidgetProvider.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayMyTextsWidgetProvider.java 2014-04-26 20:02:37 UTC (rev 45)
+++ trunk/src/org/chorem/android/saymytexts/SayMyTextsWidgetProvider.java 2014-04-28 20:06:47 UTC (rev 46)
@@ -62,15 +62,16 @@
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 @@
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);
+// 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);
- 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 views;
+ return null;
}
}
Modified: trunk/src/org/chorem/android/saymytexts/SettingsActivity.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SettingsActivity.java 2014-04-26 20:02:37 UTC (rev 45)
+++ trunk/src/org/chorem/android/saymytexts/SettingsActivity.java 2014-04-28 20:06:47 UTC (rev 46)
@@ -34,6 +34,7 @@
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 static class SettingsFragment extends PreferenceFragment {
+ public static class SettingsFragment extends PreferenceFragment
+ implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -128,17 +130,34 @@
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) {
Preference preference = findPreference(getString(keyId));
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
1
0
r45 - in trunk: res/values res/values-fr res/xml src/org/chorem/android/saymytexts
by kmorin@users.chorem.org 26 Apr '14
by kmorin@users.chorem.org 26 Apr '14
26 Apr '14
Author: kmorin
Date: 2014-04-26 22:02:37 +0200 (Sat, 26 Apr 2014)
New Revision: 45
Url: http://forge.chorem.org/projects/say-my-texts/repository/revisions/45
Log:
fixes #1009 [Settings] Enable the answer to a sms
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/preference_keys.xml
trunk/res/values/strings.xml
trunk/res/xml/preferences.xml
trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
Modified: trunk/res/values/preference_keys.xml
===================================================================
--- trunk/res/values/preference_keys.xml 2014-04-26 19:43:46 UTC (rev 44)
+++ trunk/res/values/preference_keys.xml 2014-04-26 20:02:37 UTC (rev 45)
@@ -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>
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-04-26 19:43:46 UTC (rev 44)
+++ trunk/res/values/strings.xml 2014-04-26 20:02:37 UTC (rev 45)
@@ -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>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-04-26 19:43:46 UTC (rev 44)
+++ trunk/res/values-fr/strings.xml 2014-04-26 20:02:37 UTC (rev 45)
@@ -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>
Modified: trunk/res/xml/preferences.xml
===================================================================
--- trunk/res/xml/preferences.xml 2014-04-26 19:43:46 UTC (rev 44)
+++ trunk/res/xml/preferences.xml 2014-04-26 20:02:37 UTC (rev 45)
@@ -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" />
Modified: trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-26 19:43:46 UTC (rev 44)
+++ trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-26 20:02:37 UTC (rev 45)
@@ -384,7 +384,12 @@
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) {
1
0
r44 - in trunk: res/values res/values-fr src/org/chorem/android/saymytexts
by kmorin@users.chorem.org 26 Apr '14
by kmorin@users.chorem.org 26 Apr '14
26 Apr '14
Author: kmorin
Date: 2014-04-26 21:43:46 +0200 (Sat, 26 Apr 2014)
New Revision: 44
Url: http://forge.chorem.org/projects/say-my-texts/repository/revisions/44
Log:
refs #999 Answer to a sms : reask dictating the message if the user says nothing understandable
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java
trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-04-16 07:41:48 UTC (rev 43)
+++ trunk/res/values/strings.xml 2014-04-26 19:43:46 UTC (rev 44)
@@ -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>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-04-16 07:41:48 UTC (rev 43)
+++ trunk/res/values-fr/strings.xml 2014-04-26 19:43:46 UTC (rev 44)
@@ -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>
Modified: trunk/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java 2014-04-16 07:41:48 UTC (rev 43)
+++ trunk/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java 2014-04-26 19:43:46 UTC (rev 44)
@@ -5,6 +5,8 @@
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 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 @@
@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 @@
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 @@
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);
+ }
}
Modified: trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-16 07:41:48 UTC (rev 43)
+++ trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-26 19:43:46 UTC (rev 44)
@@ -87,6 +87,9 @@
/** 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 @@
break;
case ACTION_DICTATE_SMS:
- if (attemptNumber > 0) {
-
- }
// if (bluetoothDevices.isEmpty()) {
dictateSMS(sms, attemptNumber + 1);
// } else {
@@ -250,6 +250,10 @@
// 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 @@
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 @@
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 @@
@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 @@
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 @@
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);
Modified: trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java 2014-04-16 07:41:48 UTC (rev 43)
+++ trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java 2014-04-26 19:43:46 UTC (rev 44)
@@ -63,9 +63,6 @@
@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 @@
tg.startTone(ToneGenerator.TONE_PROP_NACK);
reaskAction(context, intent, sms);
}
+
+ } else {
+ tg.startTone(ToneGenerator.TONE_PROP_NACK);
+ reaskAction(context, intent, sms);
}
}
1
0
r43 - in trunk: . res/values res/values-fr src/org/chorem/android/saymytexts
by kmorin@users.chorem.org 16 Apr '14
by kmorin@users.chorem.org 16 Apr '14
16 Apr '14
Author: kmorin
Date: 2014-04-16 09:41:48 +0200 (Wed, 16 Apr 2014)
New Revision: 43
Url: http://forge.chorem.org/projects/say-my-texts/repository/revisions/43
Log:
refs #999 Answer to a sms : reask saying the action if the user says nothing understandable
Modified:
trunk/pom.xml
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-04-07 21:16:56 UTC (rev 42)
+++ trunk/pom.xml 2014-04-16 07:41:48 UTC (rev 43)
@@ -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>
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-04-07 21:16:56 UTC (rev 42)
+++ trunk/res/values/strings.xml 2014-04-16 07:41:48 UTC (rev 43)
@@ -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>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-04-07 21:16:56 UTC (rev 42)
+++ trunk/res/values-fr/strings.xml 2014-04-16 07:41:48 UTC (rev 43)
@@ -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>
Modified: trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-07 21:16:56 UTC (rev 42)
+++ trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-16 07:41:48 UTC (rev 43)
@@ -26,6 +26,7 @@
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.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 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 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 @@
}
};
+ BluetoothHeadset mBluetoothHeadset;
+
@Override
public void onCreate() {
super.onCreate();
@@ -120,6 +126,34 @@
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 @@
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 @@
}
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();
+ if (attemptNumber > 0) {
- } else {
- dictateSMS(sms);
}
+// 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 @@
*/
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 @@
* 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 @@
// 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 @@
@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 @@
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 @@
@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 @@
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 @@
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 @@
@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 @@
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);
+ }
+
}
}
Modified: trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java 2014-04-07 21:16:56 UTC (rev 42)
+++ trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java 2014-04-16 07:41:48 UTC (rev 43)
@@ -4,7 +4,6 @@
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 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 @@
//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 @@
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 @@
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 @@
}
}
+ 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);
1
0
r42 - in trunk: res/values res/values-fr src/org/chorem/android/saymytexts
by kmorin@users.chorem.org 07 Apr '14
by kmorin@users.chorem.org 07 Apr '14
07 Apr '14
Author: kmorin
Date: 2014-04-07 23:16:56 +0200 (Mon, 07 Apr 2014)
New Revision: 42
Url: http://forge.chorem.org/projects/say-my-texts/repository/revisions/42
Log:
fixes #1008 Send back an SMS to the sender
Added:
trunk/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java
trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-04-03 12:20:29 UTC (rev 41)
+++ trunk/res/values/strings.xml 2014-04-07 21:16:56 UTC (rev 42)
@@ -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>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-04-03 12:20:29 UTC (rev 41)
+++ trunk/res/values-fr/strings.xml 2014-04-07 21:16:56 UTC (rev 42)
@@ -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>
Copied: trunk/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java (from rev 41, trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java)
===================================================================
--- trunk/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java (rev 0)
+++ trunk/src/org/chorem/android/saymytexts/DictateSmsBroadcastReceiver.java 2014-04-07 21:16:56 UTC (rev 42)
@@ -0,0 +1,94 @@
+package org.chorem.android.saymytexts;
+
+import android.app.PendingIntent;
+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.telephony.SmsManager;
+import android.util.Log;
+
+import java.util.List;
+
+/**
+ * @author Kevin Morin (Code Lutin)
+ * @since x.x
+ */
+public class DictateSmsBroadcastReceiver extends BroadcastReceiver {
+
+ private static final String TAG = "DictateSmsBroadcastReceiver";
+
+ public static final String ACTION_DICTATE_SMS = "org.chorem.android.saymytexts.DICTATE_SMS";
+
+ public static final String EXTRA_SMS = "sms";
+
+ @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 = 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) {
+ 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);
+ }
+ }
+
+ @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);
+ }
+ }
+}
Modified: trunk/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java 2014-04-03 12:20:29 UTC (rev 41)
+++ trunk/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java 2014-04-07 21:16:56 UTC (rev 42)
@@ -51,7 +51,6 @@
@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,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();
Modified: trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-03 12:20:29 UTC (rev 41)
+++ trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-07 21:16:56 UTC (rev 42)
@@ -57,17 +57,26 @@
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 @@
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 @@
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 @@
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);
- }
+ 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;
- // 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())) {
+ 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();
- SMS sms = (SMS) intent.getSerializableExtra(INTENT_EXTRA_SMS);
- if (canSpeak != null && canSpeak) {
- requestReading(sms);
- } else {
- awaitingTexts.add(sms);
- }
+ } 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 @@
*/
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 @@
* @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 @@
/**
* 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);
+
}
+ });
- if (heisendroidModeEnabled) {
- textToSpeech.setLanguage(Locale.US);
- textToSpeech.setSpeechRate(0.3f);
- textToSpeech.setPitch(0.1f);
- textToSpeech.speak("Say my text.", TextToSpeech.QUEUE_ADD, params);
+ 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);
+ }
+
+ 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);
+ @Override
+ public void onError(String utteranceId) {
+ Log.e(TAG, "Error speaking: " + utteranceId);
+ }
- 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 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);
+
}
+ });
- 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);
- }
+ 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);
}
}
Modified: trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java 2014-04-03 12:20:29 UTC (rev 41)
+++ trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java 2014-04-07 21:16:56 UTC (rev 42)
@@ -4,11 +4,15 @@
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 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";
- protected SpeechRecognizer speechRecognizer;
-
@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 @@
//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,15 +85,36 @@
} 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");
- } else if (results.contains(context.getString(R.string.quit_action))) {
+ 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);
+
+ 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)
// recognizeVoice(sms);
@@ -108,4 +137,10 @@
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);
+ }
}
1
0
r41 - in trunk: res/values res/values-fr src/org/chorem/android/saymytexts
by kmorin@users.chorem.org 03 Apr '14
by kmorin@users.chorem.org 03 Apr '14
03 Apr '14
Author: kmorin
Date: 2014-04-03 14:20:29 +0200 (Thu, 03 Apr 2014)
New Revision: 41
Url: http://forge.chorem.org/projects/say-my-texts/repository/revisions/41
Log:
refs #999 Answer to a sms
Added:
trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
Modified:
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-04-02 11:59:25 UTC (rev 40)
+++ trunk/res/values/strings.xml 2014-04-03 12:20:29 UTC (rev 41)
@@ -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>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-04-02 11:59:25 UTC (rev 40)
+++ trunk/res/values-fr/strings.xml 2014-04-03 12:20:29 UTC (rev 41)
@@ -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>
Modified: trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-02 11:59:25 UTC (rev 40)
+++ trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-03 12:20:29 UTC (rev 41)
@@ -24,34 +24,21 @@
* #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 @@
/** 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 @@
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 @@
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 @@
@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 @@
* @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 @@
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;
-
}
Added: trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java (rev 0)
+++ trunk/src/org/chorem/android/saymytexts/SayNextActionBroadcastReceiver.java 2014-04-03 12:20:29 UTC (rev 41)
@@ -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);
+ }
+ }
+}
1
0
r40 - in trunk: . res/values res/values-fr src/org/chorem/android/saymytexts
by kmorin@users.chorem.org 02 Apr '14
by kmorin@users.chorem.org 02 Apr '14
02 Apr '14
Author: kmorin
Date: 2014-04-02 13:59:25 +0200 (Wed, 02 Apr 2014)
New Revision: 40
Url: http://forge.chorem.org/projects/say-my-texts/repository/revisions/40
Log:
refs #999 Answer to a sms
Added:
trunk/src/org/chorem/android/saymytexts/SMS.java
Modified:
trunk/AndroidManifest.xml
trunk/pom.xml
trunk/res/values-fr/strings.xml
trunk/res/values/strings.xml
trunk/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java
trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
trunk/src/org/chorem/android/saymytexts/SettingsActivity.java
Modified: trunk/AndroidManifest.xml
===================================================================
--- trunk/AndroidManifest.xml 2014-03-31 08:54:08 UTC (rev 39)
+++ trunk/AndroidManifest.xml 2014-04-02 11:59:25 UTC (rev 40)
@@ -16,6 +16,7 @@
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
+ <uses-permission android:name="android.permission.CALL_PHONE" />
<uses-feature android:name="android.hardware.telephony" android:required="true"/>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-03-31 08:54:08 UTC (rev 39)
+++ trunk/pom.xml 2014-04-02 11:59:25 UTC (rev 40)
@@ -108,7 +108,7 @@
<repositories>
<repository>
- <id>tutti-public-group</id>
+ <id>saymytexts-public-group</id>
<url>https://nexus.nuiton.org/nexus/content/groups/say-my-texts-group/</url>
<snapshots>
<enabled>true</enabled>
@@ -120,9 +120,10 @@
</releases>
</repository>
</repositories>
+
<pluginRepositories>
<pluginRepository>
- <id>tutti-public-group</id>
+ <id>saymytexts-public-group</id>
<url>https://nexus.nuiton.org/nexus/content/groups/say-my-texts-group/</url>
<snapshots>
<enabled>true</enabled>
Modified: trunk/res/values/strings.xml
===================================================================
--- trunk/res/values/strings.xml 2014-03-31 08:54:08 UTC (rev 39)
+++ trunk/res/values/strings.xml 2014-04-02 11:59:25 UTC (rev 40)
@@ -28,4 +28,13 @@
<string name="crash_dialog_comment_prompt">You might add your comments about the problem below:</string>
<string name="crash_dialog_ok_toast">Thank you !</string>
+ <!-- actions -->
+ <string name="call_action">call</string>
+ <string name="answer_action">answer</string>
+ <string name="quit_action">quit</string>
+
+ <string name="confirm_action">confirm</string>
+ <string name="modifiy_action">modify</string>
+ <string name="cancel_action">cancel</string>
+
</resources>
Modified: trunk/res/values-fr/strings.xml
===================================================================
--- trunk/res/values-fr/strings.xml 2014-03-31 08:54:08 UTC (rev 39)
+++ trunk/res/values-fr/strings.xml 2014-04-02 11:59:25 UTC (rev 40)
@@ -27,4 +27,13 @@
<string name="crash_dialog_comment_prompt">Vous pouvez ajouter un commentaire ci-dessous:</string>
<string name="crash_dialog_ok_toast">Merci !</string>
+ <!-- actions -->
+ <string name="call_action">appeler</string>
+ <string name="answer_action">répondre</string>
+ <string name="quit_action">quitter</string>
+
+ <string name="confirm_action">confirmer</string>
+ <string name="modifiy_action">corriger</string>
+ <string name="cancel_action">annuler</string>
+
</resources>
Modified: trunk/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java 2014-03-31 08:54:08 UTC (rev 39)
+++ trunk/src/org/chorem/android/saymytexts/NewTextBroadcastReceiver.java 2014-04-02 11:59:25 UTC (rev 40)
@@ -27,9 +27,14 @@
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.database.Cursor;
+import android.net.Uri;
import android.os.Bundle;
+import android.provider.BaseColumns;
+import android.provider.ContactsContract;
import android.telephony.SmsMessage;
import android.util.Log;
@@ -66,11 +71,12 @@
// Get the Sender Phone Number
String senderPhoneNumber = msgs[0].getDisplayOriginatingAddress();
+ String senderName = getContactDisplayNameByNumber(context, senderPhoneNumber);
+ SMS sms = new SMS(senderPhoneNumber, senderName, messageReceived);
Log.d(TAG,messageReceived);
// start the service to say it out loud
- serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_SMS_BODY, messageReceived);
- serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_SMS_SENDER, senderPhoneNumber);
+ serviceIntent.putExtra(SayMyTextService.INTENT_EXTRA_SMS, sms);
context.startService(serviceIntent);
}
@@ -92,4 +98,32 @@
}
}
}
+
+ /**
+ * Finds the contact name in the contact book
+ * @param number the number of the contact
+ * @return the name if the contact is known, the number otherwise
+ */
+ protected String getContactDisplayNameByNumber(Context context, String number) {
+ Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
+ String name = number;
+
+ ContentResolver contentResolver = context.getContentResolver();
+ Cursor contactLookup = contentResolver.query(uri,
+ new String[] { BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME },
+ null, null, null);
+
+ try {
+ if (contactLookup != null && contactLookup.getCount() > 0) {
+ contactLookup.moveToNext();
+ name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
+ }
+ } finally {
+ if (contactLookup != null) {
+ contactLookup.close();
+ }
+ }
+
+ return name;
+ }
}
Added: trunk/src/org/chorem/android/saymytexts/SMS.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SMS.java (rev 0)
+++ trunk/src/org/chorem/android/saymytexts/SMS.java 2014-04-02 11:59:25 UTC (rev 40)
@@ -0,0 +1,44 @@
+package org.chorem.android.saymytexts;
+
+import java.io.Serializable;
+
+/**
+ * @author Kevin Morin (Code Lutin)
+ * @since x.x
+ */
+public class SMS implements Serializable {
+
+ protected String senderNumber;
+ protected String senderName;
+ protected String message;
+
+ public SMS(String senderNumber, String senderName, String message) {
+ this.senderNumber = senderNumber;
+ this.senderName = senderName;
+ this.message = message;
+ }
+
+ public String getSenderNumber() {
+ return senderNumber;
+ }
+
+ public void setSenderNumber(String senderNumber) {
+ this.senderNumber = senderNumber;
+ }
+
+ public String getSenderName() {
+ return senderName;
+ }
+
+ public void setSenderName(String senderName) {
+ this.senderName = senderName;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+}
Modified: trunk/src/org/chorem/android/saymytexts/SayMyTextService.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-03-31 08:54:08 UTC (rev 39)
+++ trunk/src/org/chorem/android/saymytexts/SayMyTextService.java 2014-04-02 11:59:25 UTC (rev 40)
@@ -24,8 +24,10 @@
* #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;
@@ -68,10 +70,8 @@
private static final String TAG = "SayMyTextService";
- /** Body of the SMS */
- public static final String INTENT_EXTRA_SMS_BODY = "smsBody";
- /** Number of the sender of the SMS */
- public static final String INTENT_EXTRA_SMS_SENDER = "smsSender";
+ /** 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 */
@@ -88,8 +88,10 @@
protected TextToSpeech textToSpeech;
+ protected SpeechRecognizer speechRecognizer;
+
/** texts to read, received before the textospeech is ready or while a call is in progress */
- protected List<String> awaitingTexts = new ArrayList<>();
+ protected List<SMS> awaitingTexts = new ArrayList<>();
/** bluetooth devices which are currently connected */
protected Map<BluetoothDevice, Integer> bluetoothDevices = new HashMap<>();
@@ -112,6 +114,7 @@
super.onCreate();
textToSpeech = new TextToSpeech(this, this);
+ speechRecognizer = SpeechRecognizer.createSpeechRecognizer(SayMyTextService.this);
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
@@ -157,15 +160,11 @@
// if the headset is plugged, or if there is a bluetooth device connected
} else if (readingEnabled && (audioManager.isWiredHeadsetOn() || !bluetoothDevices.isEmpty())) {
- String sms = intent.getStringExtra(INTENT_EXTRA_SMS_BODY);
- String sender = intent.getStringExtra(INTENT_EXTRA_SMS_SENDER);
- sender = getContactDisplayNameByNumber(sender);
- String text = getString(R.string.sms_received, sender, sms);
-
+ SMS sms = (SMS) intent.getSerializableExtra(INTENT_EXTRA_SMS);
if (canSpeak != null && canSpeak) {
- requestReading(text);
+ requestReading(sms);
} else {
- awaitingTexts.add(text);
+ awaitingTexts.add(sms);
}
}
@@ -196,6 +195,7 @@
audioManager.stopBluetoothSco();
audioManager.setMode(AudioManager.MODE_NORMAL);
}
+ waiting = false;
}
});
@@ -225,36 +225,36 @@
/**
* Requests the reading of one text through the wired headset or bluetooth device
- * @param text the text to read
+ * @param sms the text to read
*/
- protected void requestReading(String text) {
- requestReading(Collections.singletonList(text));
+ 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 texts the texts to read
+ * @param smsList the texts to read
*/
- protected void requestReading(List<String> texts) {
+ protected void requestReading(List<SMS> smsList) {
if (bluetoothDevices.isEmpty()) {
- readText(texts, false);
+ readText(smsList, false);
} else {
- requestReadingOverBt(texts);
+ requestReadingOverBt(smsList);
}
}
/**
* Starts the connection with the bluetooth device and requests the reading
- * @param texts the texts to read
+ * @param smsList the texts to read
*/
- protected void requestReadingOverBt(final List<String> texts) {
+ protected void requestReadingOverBt(final List<SMS> smsList) {
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(texts, true);
+ readText(smsList, true);
}
}
}, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
@@ -264,10 +264,10 @@
/**
* Reads the texts out loud
- * @param texts the texts to read
+ * @param smsList the texts to read
* @param btConnected if true, adds the utterance id for the bluetooth device
*/
- protected void readText(List<String> texts, boolean btConnected) {
+ 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);
@@ -276,7 +276,8 @@
String heisendroidModeEnabledKey = getString(R.string.preference_enable_heisendroid_mode_key);
boolean heisendroidModeEnabled = sharedPref.getBoolean(heisendroidModeEnabledKey, true);
- for (String text : texts) {
+ for (SMS sms : smsList) {
+ waiting = true;
if (heisendroidModeEnabled) {
textToSpeech.setLanguage(Locale.US);
textToSpeech.setSpeechRate(0.3f);
@@ -287,6 +288,7 @@
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) {
@@ -295,35 +297,92 @@
textToSpeech.setPitch(0.1f);
textToSpeech.speak("You're goddamn right.", TextToSpeech.QUEUE_ADD, params);
}
+
+ while (waiting) {
+ }
+ waiting = true;
+ recognizeVoice(sms);
+ while (waiting) {
+ }
}
}
- /**
- * Finds the contact name in the contact book
- * @param number the number of the contact
- * @return the name if the contact is known, the number otherwise
- */
- protected String getContactDisplayNameByNumber(String number) {
- Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
- String name = number;
+ 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);
- ContentResolver contentResolver = getContentResolver();
- Cursor contactLookup = contentResolver.query(uri,
- new String[] { BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME },
- null, null, null);
+ speechRecognizer.setRecognitionListener(new RecognitionListener() {
+ @Override
+ public void onReadyForSpeech(Bundle params) {
+ }
- try {
- if (contactLookup != null && contactLookup.getCount() > 0) {
- contactLookup.moveToNext();
- name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
+ @Override
+ public void onBeginningOfSpeech() {
}
- } finally {
- if (contactLookup != null) {
- contactLookup.close();
+
+ @Override
+ public void onRmsChanged(float rmsdB) {
}
- }
- return name;
+ @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;
+
}
Modified: trunk/src/org/chorem/android/saymytexts/SettingsActivity.java
===================================================================
--- trunk/src/org/chorem/android/saymytexts/SettingsActivity.java 2014-03-31 08:54:08 UTC (rev 39)
+++ trunk/src/org/chorem/android/saymytexts/SettingsActivity.java 2014-04-02 11:59:25 UTC (rev 40)
@@ -162,6 +162,8 @@
PendingIntent pi = PendingIntent.getActivity(context, -1, new Intent(context, SettingsActivity.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, pi, null);
+
}
+
}
}
1
0