Skip to content

Commit 47ee706

Browse files
author
Chris Bellew
committed
Try to match on up to 5 voice results; use a better error message when no matches are found.
1 parent c2229ff commit 47ee706

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

Voice Control For Plex/src/main/java/com/atomjack/vcfp/ListenerWidget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] ap
3333
Intent listenerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
3434
listenerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
3535
listenerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "voice.recognition.test");
36-
listenerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
36+
listenerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
3737
listenerIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, resultsPendingIntent);
3838
listenerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, context.getResources().getString(R.string.voice_prompt));
3939

Voice Control For Plex/src/main/java/com/atomjack/vcfp/PlexSearch.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class PlexSearch extends Service {
5454
public int onStartCommand(Intent intent, int flags, int startId) {
5555
Logger.d("PlexSearch: onStartCommand");
5656

57+
queryText = null;
5758
BugSenseHandler.initAndStartSession(PlexSearch.this, MainActivity.BUGSENSE_APIKEY);
5859

5960
String from = intent.getStringExtra("FROM");
@@ -65,11 +66,14 @@ public int onStartCommand(Intent intent, int flags, int startId) {
6566
} else {
6667
if (intent.getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS) != null) {
6768
ArrayList<String> voiceResults = intent.getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
68-
if (voiceResults.size() > 0) {
69-
queryText = voiceResults.get(0);
70-
} else {
71-
feedback.e(getResources().getString(R.string.nothing_to_play));
69+
for(String q : voiceResults) {
70+
if(q.matches(VoiceControlForPlexApplication.recognition_regex)) {
71+
queryText = q;
72+
break;
73+
}
7274
}
75+
if(queryText == null)
76+
feedback.e(getResources().getString(R.string.didnt_understand));
7377
} else
7478
queryText = intent.getStringExtra("queryText");
7579
if (queryText != null)
@@ -396,11 +400,11 @@ else if(matcher.group(3).startsWith("second"))
396400
searchForSong(artist, track);
397401
}
398402
} else {
399-
feedback.e(getResources().getString(R.string.nothing_to_play));
403+
feedback.e(getResources().getString(R.string.didnt_understand));
400404
return;
401405
}
402406
} else {
403-
feedback.e(getResources().getString(R.string.nothing_to_play));
407+
feedback.e(getResources().getString(R.string.didnt_understand));
404408
return;
405409
}
406410
}

Voice Control For Plex/src/main/java/com/atomjack/vcfp/ShortcutActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected void onCreate(Bundle savedInstanceState) {
2222
Intent listenerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
2323
listenerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
2424
listenerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "voice.recognition.test");
25-
listenerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
25+
listenerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
2626
listenerIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, resultsPendingIntent);
2727
listenerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, getResources().getString(R.string.voice_prompt));
2828

Voice Control For Plex/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@
6565
<string name="no_wifi_connection_message">A WiFi connection is required. Please check your WiFi settings and try again.</string>
6666
<string name="voice_prompt">Voice Control for Plex is listening</string>
6767
<string name="searching_for_plex_servers">Searching for Plex Servers</string>
68+
<string name="didnt_understand">Sorry, I didn\'t understand that.</string>
6869
</resources>

0 commit comments

Comments
 (0)