I've implementing voice-search on my Android-TV app using the following small code
private void displaySpeechRecognizer() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
startActivityForResult(intent, SPEECH_REQUEST_CODE);
}
#Override
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == SPEECH_REQUEST_CODE && resultCode == -1) {
List<String> results = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
String spokenText = results.get(0);
Toast.makeText(getActivity(), spokenText, Toast.LENGTH_LONG).show();
}
super.onActivityResult(requestCode, resultCode, data);
}
This is all working well and I get the result back for further processing.
The problem is that I also want to give the user the possibility to enter the search-string manually with the virtual keyboard.
In Googles own apps you do this be simply pressing RIGHT on the remote to give focus to the textbox after pressing the voice-search icon.
In my example above I can see the "built-in-textbox" when I press the search icon but if I try to navigate to it the search is interrupted and closed.
How do I access the search-textbox? This should cancel voice-input and bring up the keyboard instead, just like Play Store app.
Are you using Leanback support library for your Android TV app design?
I guess "Google Play Store app" and "YouTube app" are using BrowseFragment & SearchFragment for search. These Fragments are providing build-in search UI.
For the implementation, see Google's sample source code or SearchFragment – Android TV app Tutorial 12.
Related
I need to create an android app doing mainly two things.
1) Detect price and barcode
2) Creating AR content around the detected price/barcode
For the detection part, I use google mobile-vision and for the AR part I use ARcore. The problem I have is that Arcore doesnt allow auto focus so I dont have a good enough resolution to read the prices or bar codes.
So I was wondering if there was a standard way to do text recognition and AR in the same app.
Thank you.
You can implement them in the same app, on different activities. if you are using the mobile vision API. you can set the start the intent for detection with startActivityForResult and when the result is returned. you can Implement a transistion in the onActivityResult part. Since the AR depends on the detected data you can pass the information to the AR activity using putExtra. use this as a template
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(DetectActivity.this, ScanActivity.class);
startActivityForResult(i, REQUEST_CODE);
}
});
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
if (data != null) {
final Barcode barcode = data.getParcelableExtra("barcode");
String rslt=barcode.displayValue;
Intent intent =new Intent(DetectActivity.this, ArActivity.class);
intent.putExtra("link", rslt);
startActivity(intent);
finish();
Hope this helps,
ScanActivity is the normal Camera View SurfaceView activity that mobile vision uses
I haven't used ARcore, but have done a reasonable amount of detection. This was mostly done using a surface view extension showing and initialising a camera1 api view with detection interface and callbacks.
It is difficult to tell what might be going wrong without any code available or how you have gone about this, any chance you could provide some?
So I am trying to make a simple to do list app where it has only a mic button and the list. I am very new to android app dev, i have managed to figure out a text input into the list and how to get the text to speech up and put the spoken text in a text field. All this was achieved through a mix of tutorials. I can't seem to figure out how to bring the 2 together.
Any tips?
Here I leave you a great tutorial considering that you didnt post any code.
This tutorial, shows you how to make speech recognition with a button and then it makes a list with the possible spoken text. It works perfectly, I tried once.
Try this code to open the mic on button --> OnClickListener.
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
startActivityForResult(intent, nRESULT_SPEECH);
}
nRESULT_SPEECH is your code which you can give anything as 0, 1, 2,etc;
You will get the word spoken in this callback method onActivityResult
#Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case nRESULT_SPEECH:
if (null != data) {
ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String textCapturedFromVoice=text.get(0);
}
break;
}
}
Once u will get the text in textCapturedFromVoice, you can add this to ur list.
I want to make the users default equalizer work with my app, but I can't seem to get my app audio session to connect with the equalizer even though I am passing it my Audio Session ID etc.
Here is my code:
Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, MusicPlayerService.getMPSessionId());
startActivityForResult(i, 11113);
I am using the code above to launch the user's default Equalizer.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
System.out.println("RESULT_OK");
Equalizer equalizer = new Equalizer(0,MusicPlayerService.getMPSessionId());
equalizer.setEnabled(true);
return;
}
}
And then I am using the code above to apply enable and apply it. What am I doing wrong here? I have a few apps on my phone that use the stock Equalizer and they all work fine.
If somebody could help me out, that would be highly appreciated, thanks.
mAudioSession = mp.getAudioSessionId();
try {
final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
effects.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, this.getPackageName());
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mAudioSession);
startActivityForResult(effects, 0);
} catch (Exception e) {
// ignored. Whee!
}
First add this code, int mAudioSession = 0; , above mAudioSession line, if that makes sense. This code should work, tested it and it works fine. I think what youre missing is, Package name, Also you don't needequalizer.enabled` true, it won't do anything at all, I think that's for making you're own equalizer. Also I think you can use equalizer.setenabled(true) etc.
The Android platform have a number of "ready easy use" dialog such as
ProgressDialog, DatePickerDialog and TimePickerDialog, these are fire and wait
boxes, that is, they handle UI, right data and return something.
Is there a similar dialogbox for the mediastorage ?
I want something like "AudioFilePickerDialog" which shows a UI to the user
where the user pick a audio file and return the path/uri to the audio file.
Do I need to build this dialog box up myself or does it exists somewhere ?
One of the few examples I have found is
Given an Android music playlist name, how can one find the songs in the playlist?
but this handles playlists.
/Stefan
I found a tutorial for something like a FileChooser here. You should be able to make it only show Music-Files (like .mp3).
Also, to browser the SDcard of your Android Device, you can use the standard Java File-class, like in normal Java.
Try this
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, REQUEST_MEDIA);//REQUEST_MEDIA is some const int to operate with in onActivityResult
here you'll be brought a dialog (activity tbh) to choose an audio from mediastore.
Handle the result in onActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_MEDIA && resultCode == RESULT_OK) {
String audioID = data.getDataString();
...
}
}
Is it possible to extend the Voice Search app? I know I can add a button in my own app to launch the voice recognition dialog, but I was wondering if I could extend the voice search app that launches automatically when you long press the physical "search" key.
send text to [contact] [message]
listen to [artist/song/album]
call [business]
call [contact]
send email to [contact] [message]
go to [website]
note to self [note]
navigate to [location/business name]
directions to [location/business name]
map of [location]
I'd basically like to add my own action to the above list.
Is this possible or will I have to create my own?
In a word, no. The app doesn't have the extension points you are looking for. You would have to write your own app entirely, which is something that others have done.
A simple method to Handle Voice Search
Step 1 Call this method on button click
public void startVoiceRecognition() {
Intent intent = new Intent("android.speech.action.RECOGNIZE_SPEECH");
intent.putExtra("android.speech.extra.LANGUAGE_MODEL", "free_form");
intent.putExtra("android.speech.extra.PROMPT", "Speak Now");
this.mContainerActivity.startActivityForResult(intent, 3012);
}
Step 2 Override onActivityResult method
# Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 3012 && resultCode == RESULT_OK) {
ArrayList < String > matches = data.getStringArrayListExtra("android.speech.extra.RESULTS");
String result= matches.get(0);
//Consume result
edittext.setText(result);
}
}
Thats all, DONE