Skip to content

Commit 6b7bb00

Browse files
committedMar 2, 2024
Recreate SpeechRecognizer every time the mic button is pressed (fixes #115)
+ Update dependencies
1 parent 4b294cd commit 6b7bb00

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed
 

‎app/src/main/java/ee/ioc/phon/android/speak/ServiceLanguageChooser.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public class ServiceLanguageChooser {
3333
private final String mAppId;
3434
private final int mKeyCurrentCombo;
3535
private int mIndex;
36-
private SpeechRecognizer mSpeechRecognizer;
3736
private Intent mIntent;
3837
private String mLanguage = null;
3938
private ComponentName mRecognizerComponentName = null;
@@ -87,9 +86,16 @@ public ServiceLanguageChooser(Context context, SharedPreferences prefs, int keys
8786
update();
8887
}
8988

90-
89+
/**
90+
* If the stored recognizer component name does not refer to an existing service on the device then we use
91+
* the default service. This can happen if services get removed or renamed.
92+
* TODO: improve
93+
*/
9194
public SpeechRecognizer getSpeechRecognizer() {
92-
return mSpeechRecognizer;
95+
if (mRecognizerComponentName == null || !IntentUtils.isRecognitionAvailable(mContext, mRecognizerComponentName)) {
96+
return SpeechRecognizer.createSpeechRecognizer(mContext);
97+
}
98+
return SpeechRecognizer.createSpeechRecognizer(mContext, mRecognizerComponentName);
9399
}
94100

95101
public int size() {
@@ -139,10 +145,12 @@ public String getCombo() {
139145
return mCombosAsList.get(mIndex);
140146
}
141147

148+
// TODO: can return null, but some callers expect non-null
142149
public String getLanguage() {
143150
return mLanguage;
144151
}
145152

153+
// TODO: can return null, but some callers expect non-null
146154
public ComponentName getService() {
147155
return mRecognizerComponentName;
148156
}
@@ -156,14 +164,6 @@ private void update() {
156164
language = splits[1];
157165
}
158166

159-
// If the stored combo name does not refer to an existing service on the device then we use
160-
// the default service. This can happen if services get removed or renamed.
161-
if (mRecognizerComponentName == null || !IntentUtils.isRecognitionAvailable(mContext, mRecognizerComponentName)) {
162-
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(mContext);
163-
} else {
164-
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(mContext, mRecognizerComponentName);
165-
}
166-
167167
// TODO: support other actions
168168
mIntent = Utils.getRecognizerIntent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH, mCallerInfo, language);
169169
mLanguage = language;

‎app/src/main/java/ee/ioc/phon/android/speak/view/SpeechInputView.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ private void showMessageArrow(int numOfChars, String dash) {
757757
}
758758

759759
private static String selectFirstResult(List<String> results) {
760-
if (results == null || results.size() < 1) {
760+
if (results == null || results.isEmpty()) {
761761
return null;
762762
}
763763
return results.get(0);

‎build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
mavenCentral()
55
}
66
dependencies {
7-
classpath 'com.android.tools.build:gradle:8.2.2'
7+
classpath 'com.android.tools.build:gradle:8.3.0'
88
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0'
99
}
1010
}

‎gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip

0 commit comments

Comments
 (0)
Failed to load comments.