Difference between ACTION_WEB_SEARCH and EXTRA_WEB_SEARCH_ONLY - android

I'm implementing speech recognition in my app and have some questions the API doc couldn't solve. I wonder what's the difference between using
Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
and
Intent recognizerIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
?
I also recognized that I have to put the EXTRA_LANGUAGE_MODEL also when using ACTION_WEB_SEARCH? Why is that?
And what means EXTRA_WEB_SEARCH_ONLY? I thought that it is always web search with the web search action.

Related

Persian speech to text in android

i want to improve my knowledge and work with sound reorganization (speech to text). i find good samples from google but i don't know how can i do so with Persian-Farsi language? i do it with English but how about Farsi? is it need some setting in my mobile android phone? is there anyone who do so?
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, REQUEST_CODE);
just put new extra in your intent as below
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "fa");

How to automatically play Playlist in Spotify Android app

I'm trying to play a known playlist in the Spotify app. The best I've got is to load the playlist, but not play it.
Two things I've tried. Firstly to play from search:
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setComponent(new ComponentName("com.spotify.music",
"com.spotify.music.MainActivity"));
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS,
MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE);
intent.putExtra(MediaStore.EXTRA_MEDIA_PLAYLIST, <PLAYLIST>);
intent.putExtra(SearchManager.QUERY, <PLAYLIST>);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
I've tried replacing PLAYLIST with the name of a known playlist. Also tried things like "4Rj0zQ0Ux47upeqVSIuBx9", "spotify:user:11158272501:playlist:4Rj0zQ0Ux47upeqVSIuBx9" etc. All these do is a failed search for these strings.
Second attempt is the View intent:
String uri = "https://play.spotify.com/user/11158272501/playlist/4Rj0zQ0Ux47upeqVSIuBx9";
Intent intent= new Intent( Intent.ACTION_VIEW, Uri.parse(uri) );
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
This loads the playlist, but does not play. If I then use one of the many ways to send a KEYCODE_MEDIA_PLAY key, it just resumes the currently playing list, not this newly loaded list.
Any help from anyone (including Spotify devs)?
BTW I don't want to use the Spotify SDK to implement my own Spotify Player - it seems a shame to have to do this when a perfectly good player is already installed on a user's device.
I found the answer from this blog. What I was missing was the playlist URI as a data Uri in the intent. So not using the proper Android way of Play from search.
So, using the first method from the question, you end up with this:
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setData(Uri.parse(
"spotify:user:11158272501:playlist:4Rj0zQ0Ux47upeqVSIuBx9"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
3 things to note:
the Uri can't be the https://play.spotify... but has to be the colon seperated type.
the Spotify account must be premium, otherwise the playlist opens but does not play.
this does not work if the screen is off, or lock screen is showing. The spotify activity needs to display on the screen before it loads and plays!
This final point means it isn't actually usable for me... so not accepting answer yet.
Just add :play to Spotify Intent URI
spotify:album:3avifwTCXoRzRxxGM1O0eN:play

Non-default language for voice recognition in Android TV

I'm unable to force custom Android TV application to recognise non-default language from voice-input. Same problem are in built-in YouTube application (and other). However it works in built-in Google Search app (Katniss).
There are my code which works well on Nexus phone, but on Nexus Player setting custom language doesn't give any results in selected language.
SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(this);
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
String loc = "ru-RU";
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, loc);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, loc);
intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, loc);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);
sr.startListening(intent);
Looks like it was fixed in one of Google Search app updates

Send messages through Voice Recognition?

I used the following code to send a message "hello" when I say send.
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, metTextHint.getText().toString());
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
In onActivityResult() :
if(textMatchList.get(0).contains("send")) {
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.putExtra("sms_body", "Hello");
smsIntent.putExtra("address", "0123456789");
smsIntent.setType("vnd.android-dir/mms-sms");
startActivity(smsIntent);
}
How can I make the app be more flexible. I mean for example if I say "Send this message to mike, Hey man, you want to go to the movie." How can I make the app use only the important information like Send, Mike, and the message itself. And then send the message as usual. Also how make this all possible without hard-coding it.
Are there any tutorials which do this on the net, if so please give me a link, I would really appreciate that.
Thank You
Maybe you might get the text of the recognized speech and use
if(text.contains("Mike")){
//send message to Mike (which i dont know how to do it,i am searching for this )
}

Speech recognition , unknown error issue in android

I am trying to do a browser control appication with voice in android. I am using RecognizerIntent.ACTION_RECOGNIZE_SPEECH intent to recognize voice. It usually works but sometimes when voice recognition pop up opens and comes with "unknown problem" and my WebView don't load my URL, stays with old URL.
Here is my code:
//Load web view to default search screen
webView.loadUrl(Constant.DEFAULT_VOICE_BG);
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.ACTION_RECOGNIZE_SPEECH, getClass()
.getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
GeneralConstants.TEXT_VOICE);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
startActivityForResult(intent,
GeneralConstants.VOICE_RECOGNITION_REQUEST_CODE);
Thanks for any idea.
Best Regards.

Categories

Resources