I searched a lot on StackOverFlow for this Problem but the Threads are older than 3 years old.
I implemented the Google Voice Recognition which requires a Internet Connection. Searching how i can use the Offline Voice Recognition brought no success.
Is it now available to use the Voice Recognition when you're offline?
My code until yet:
speechStartButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
promtSpeechInput();
}
});
private void promtSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
"Recording...");
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "Language not supported", Toast.LENGTH_SHORT).show();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case CAMERA_PIC_REQUEST: {
try {
Bitmap image = (Bitmap) data.getExtras().get("data");
ImageView imageView = (ImageView) findViewById(R.id.taskPhotoImage);
imageView.setImageBitmap(image);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
case REQ_CODE_SPEECH_INPUT: {
if(resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
speechToTextField.setText(speechToTextField.getText()+" " +result.get(0));
}
break;
}
}
}
King Regards
Not with Google.
You have to use another solution like CMU Sphinx.
Check here : Android: Speech Recognition without using google server
Actually you can use SpeechRecognizer offline.
Go to Setting -> “Language and Input”
Choose the keyboard from “Keyboard & Input methods” section and enable “Google Voice Typing“
Go back to the previous screen “Language & input“, you will see the “Google voice typing” enabled.
Tap on “Offline speech recognition“.
Download the languages.
Now you should be able to use Speech To Text in offline mode.
The problem with this is it is not continuous without using a loop and using a loop with SpeechRecognizer is absolutely annoying due to the constant beeping sound. There are ways around the beeping sound but most of them mute the beeping sound and everything on the same audio stream as it.
Also mentioned in the steps, you also have to download "Google Voice Typing" and a language for it taking up a lot more storage space. Overall you can use SpeechRecognizer offline but it's a major hassle.
Related
Google Speech-to-Text API supports Marathi as per their documentation here. However I have not been able to get it working on my Android phone. I have already added 'Marathi' in languages for my Android device (Moto G6, running android 7.1.1). However, I am not yet able to get a simple SMS converted from speech-to-text with this. Marathi typing works fine though.
Do I need to modify any other setting? What else is required? Any pointers for this would be highly appreciated.
Have you configured your intent to detect marathi languages as below?
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,"mr-IN");
You can checkout other languages codes here.
You can use following code for your reference:
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.RecordBtn:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// Use Off line Recognition Engine only...
intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, false);
// Use Marathi Speech Recognition Model...
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "mr-IN");
try {
startActivityForResult(intent, SST_REQUEST_CODE);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.error),
Toast.LENGTH_SHORT).show();
}
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case SST_REQUEST_CODE:
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> getResult = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
Original.setText(getResult.get(0));
conversionTable = new ConversionTable();
String Transformed_String = conversionTable.transform(getResult.get(0));
result.setText(Transformed_String);
}
break;
}
}
I'm using androids default camera capture and then a crop library to take a photo then crop it to a square to be displayed on the next layout, the picture stored on the device and a record created on a database.
Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image_file));
startActivityForResult(camera_intent, CAM_REQUEST);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==2 || requestCode == 6709) {
if (resultCode == RESULT_CANCELED) {
} else if (resultCode == RESULT_OK) {
//Crop.pickImage(this);
if (requestCode == Crop.REQUEST_CROP && resultCode == RESULT_OK) {
//doSomethingWithCroppedImage(outputUri);
setResult(resultCode);
} else {
File cropme = new File(tempPicture[4]);
if (Build.VERSION.SDK_INT >= 24) {
try {
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
} catch (Exception e) {
e.printStackTrace();
}
}
new Crop(Uri.fromFile(cropme)).output(Uri.fromFile(cropme)).asSquare().start(this);
}
}
}
The problem is there is a picture confirmation page as shown below that's redundant and will save the user a lot of time if I'm able to remove it.
How can I go about either editing the default camera capture activity or using another camera template online?
I'd like to make process as efficient as possible so if there's a better way of doing this let me know.
The problem is there is a picture confirmation page as shown below that's redundant and will save the user a lot of time if I'm able to remove it.
Do not use ACTION_IMAGE_CAPTURE. Use the camera APIs directly (e.g., android.hardware.Camera, android.hardware.camera2.*) or via a library that wraps them (e.g., CameraKit-Android, Fotoapparat).
How can I go about either editing the default camera capture activity
There are ~10,000 Android device models. These ship with dozens, if not hundreds, of different camera apps. Plus, users install their own. Any of those can respond to ACTION_IMAGE_CAPTURE. Whether any of them have a confirmation screen is up to the developers of those apps, not you. If you want complete control over the camera experience, do not delegate photo-taking to ACTION_IMAGE_CAPTURE, but write your own camera code.
I have implemented search view using Leanback Search Fragment in Android TV App.
It works fine for the keyboard input text. But the voice search returns RESULT_CLIENT_ERROR 99%. However the text appears in the edit text on the screen but does not return in onActivityResult. Once in a bluemoon I get RESULT_OK with correct data in the intent.
Device: Nexus Player
Even the default search works the same way most of the items. Hardly do i get the results via voice. (Search in home screen of nexus player i mean)
I try to get the text using the reference of the SearchEditText no luck but.
The following is the code:
setSpeechRecognitionCallback(new SpeechRecognitionCallback() {
#Override
public void recognizeSpeech() {
try {
startActivityForResult(getRecognizerIntent(), REQUEST_SPEECH);
} catch (final ActivityNotFoundException e) {
Log.d("ActivityNotFoundException",e.toString());
}
}
});
onActivityResult
#Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
switch (requestCode) {
case REQUEST_SPEECH:
switch (resultCode) {
case Activity.RESULT_OK:
setSearchQuery(data, true);
break;
case RecognizerIntent.RESULT_CLIENT_ERROR:
Log.d("RESULT_CLIENT_ERROR", String.valueOf(requestCode));
break;
}
}
}
How do i make it work 100% Is there anything I can change in the intent provided?
This is a problem with Nexus player as even the default search operation of the Nexus Player behaves the same way.
However the same piece of code works 100% fine on Sony Bravia and other Android TVs.
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.
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.