I have to develop an android application in which user speaks something and the wav file os send to the server where the googlespeech api shall return some text and i will display it on the android activity screen.
Note : Dont confuse urself with the android Text To Speech library i have to send the wav file
to the client's server.
Problem : I have no idea of howsoever to use this API. I can record the voice from the client and save it in a wav file but don't know how to proceed.
Refer Link : http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
You actually can't record a wav file and use it. At this moment the only way to do it is to get voice from the microphone using android intent:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-EN");
startActivityForResult(intent, CODE);
And then you can recievie the result in onActvityResult function:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
List<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
}
That is the basic idea.
Related
I am using Intent(Intent.ActionOpenDocument) and OnActivityResult() fine in my Android mobile app. (Targeting Android 10, API 29). The user selects an audio file and the app plays the file fine. Ths user is able to select a file from anywhere on their device.
I would like to display the name of the file that is playing in the UI. How do I grab the filename?
In OnActivityResult, this: ReturnedIntent.Data.Path, returns this:
/document/content://com.microsoft.skydrive.content.metadata/Drive/RID/phil%40mydomain.com/Item/RID/DC9388F99D04BA56%21369828/Property/?RefreshOption=AutoRefresh&RefreshTimeOut=15000&CostAttributionKey=11-21-1
which has nothing resembling the file name in it. I have found older stack posts on this, but they don't work for me. I have a feeling that the issue is with Android security and/or permissions that I need to give the app.
How do I grab the file name so I can display it in the UI?
Thanks #CommonsWare, you pointed me in the right direction. With the help of intellisense I noticed that the .Data property of the returned Intent was a Uri. So this is what (C# Xamarin) ended up working.
public override void OnActivityResult(int requestCode, int resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == -1 && requestCode == 42)
{
Intent ReturnedIntent = data;
// the code is in a Fragment here so we use Activity for the Context
DocumentFile df = DocumentFile.fromSingleUri(Activity, ReturnedIntent.Data);
string FileName = df.Name; // that contains the filename
I never would have got this on my own. I love that Android Java and Xamarin C# are so close. Thanks again #CommonsWare.
I am looking for a voice recognition library for Android. I only need it to understand "Yes/No" answers ( in different languages - like English, German, French ).
Any suggestions?
Not sure about V-R libraries because the Play Store max App size is 50megs and those voice packages are about 15 to 20 megs each so it will impossible to include multiple languages directly into the App.
There may be an online service to use but you need to search the net for that.
What most people use is the inbuilt Android voice recognition Intent. For different languages should be ok for the ones you want as they are included. However i'm not sure if for example in France when you buy a phone or a tablet the default V-R language will be French and not English, therefore the user will need to go into Language settings and Download the French V-R package.
To start V-R in Android you do
startVoiceRecognitionActivity();
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
startActivityForResult(intent, 1234);
}
//To get the Voice data back as Text string
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
//pull all of the matches
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String topResult = matches.get(0);
}};
The String topResult is the speech in text
I need my app to read text via Camera. I know there's the Tesseract library which does this, but I'd really prefer if there was an app that can handle Intents to read text via Camera, like Xzing does for reading QR codes.
Is there such an app?
There isn't currently an app on Google Play that does this.
I've thought about making one, but the possible use cases for such an app vary much more than for, say, scanning a QR code. There are different possible scenarios:
License plate recognition
Recognition for LCD 7-segment displays
Korean OCR
OCR for stylized text
OCR with shadows or uneven illumination
The different scenarios present a challenge for how to handle the image. A request to such an app via Intent would probably need to specify at least the type of thresholding to use for pre-processing the image along with the language/traineddata file to use.
I've just created an app that takes a photo using the Camera, crop the photo, and return the recognized text as result.
In your app, you may use the following code:
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo("sunbulmh.ocr", PackageManager.GET_ACTIVITIES);
Intent LaunchIntent = pm.getLaunchIntentForPackage("sunbulmh.ocr");
LaunchIntent.setFlags(0);
startActivityForResult(LaunchIntent,5);
} catch (NameNotFoundException e) {
Uri URLURI = Uri.parse("http://play.google.com/store/apps/details?id=sunbulmh.ocr");
Intent intent = new Intent(Intent.ACTION_VIEW,URLURI);
startActivity(intent);
}
Then, get the result in onActivityResult():
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if(requestCode == 5){
String ocr_txt = data.getStringExtra(Intent.EXTRA_TEXT);
// ocr_txt contains the recognized text.
}
}
}
I'm making an Android app which stores some downloaded pdf files inside the device's SD card.
Everything works fine, but now I want to add a function to just pop up the default android file/folder browser showing the directory where my app stores all the PDF (with subdirectories in it) so that the user sees where his documents are stored and can easily browse them.
I've been throught many other SO questions and forum posts, but it seems this can only be done for music/images/contacts/etc. basically those file types which have a 'dedicated browsing system' but not with general file browsing.
I'm actually using this code:
File file = new File("/sdcard/MySorgenia/Documenti/");
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri data = Uri.fromFile(file);
String type = "*/*";
intent.setDataAndType(data, type);
startActivity(intent);
But this will show me a "Choose the application to complete your action" dialog with many applications such as "Music" "Gallery" etc, but no general purpose one.
Thanks!
Because In android there is no any native application which you can use as a File Explorer and responds to Intent type "*/*"
Implement your own File-Explorer Code for this purpose..
Look at these two Links..
openintents
Android-File-Explore
public void loadfile()
{
private static final int gallery=12;
private static final String type="*/*";
Intent i=new Intent(Intent.ACTION_GET_CONTENT);
i.setType(type);
startActivityForResult(Intent.createChooser(i,"select file"), gallery);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == gallery && resultCode == RESULT_OK && data != null) {
Uri uploadfileuri = data.getData();
File file = new File(uploadfileuri.getPath());
}
}
Since Android 4.4 KitKat (API level 19), there is an Android built-in file picker: your app invokes the ACTION_OPEN_DOCUMENT and/or ACTION_CREATE_DOCUMENT intent and receives the files returned by document providers. More info about that can be found here:
Open files using storage access framework | Android Developers
Depending on where you want to store files, you may need to request permission:
Request App Permissions | Android Developers
Here is a how to:
An Android Storage Access Framework Example - Techtopia.
And a great working example is Ian Lake's Local Storage. Its source can be found on GitHub:
https://github.com/ianhanniballake/LocalStorage
And the app can be downloaded from Google Play:
https://play.google.com/store/apps/details?id=com.ianhanniballake.localstorage
Most android distributions do not come with a default file browser, and the behavior you noticed is the default android behavior. If there's any good third party file browser installed, it will automatically show up in that list. However it is not guaranteed that every end user will have a file browser installed. A general purpose fragment-widget can be created for this (and probably shared with others).
Look at this file picker, it's the best one I found:
I am working on application that will record the voice of the user and save the file on the SD card and then allow the user to listen to the audio again.
I am able to allow the user to record his voice using the RecognizerIntent, but I cant figure out how to save the audio file and allow the user to hear the audio. I would appreciate it if someone could help me out. I have displayed my code below:
// Setting up the onClickListener for Audio Button
attachVoice = (Button) findViewById(R.id.AttachVoice_questionandanswer);
attachVoice.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Please Speak");
startActivityForResult(voiceIntent, VOICE_REQUEST);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == VOICE_REQUEST && resultCode == RESULT_OK){
}
There is an example of how to do audio capture using MediaRecorder in the Android Developer Documentation.
I would recommend saving the files on the SD Card and then have your gallery code check the SD card to see which files to display. You can get the directory of the SD Card using the Environment.getExternalStorageDirectory() method. It would be best to save your files in a subdirectory of the SD Card root directory.
Make sure you give your applications the Permissions it will need. At the very least it will need RECORD_AUDIO and WRITE_EXTERNAL_STORAGE.
Also you have to see these tutorials:
http://www.androiddevblog.net/android/android-audio-recording-part-1
http://www.androiddevblog.net/android/android-audio-recording-part-2
If you really want to record audio via the speech recognition API then you could use the RecognitionService.Callback which has a method
void bufferReceived(byte[] buffer)
This gives you access to the recorded audio buffer as speech is being recorded and recognized. (No information is provided about the sample rate though.) You can then save the obtained buffers into a file for a later playback. I think keyboard apps use this call to display the waveform of the recorded speech. You have to implement the UI yourself.
The bare RecognizerIntent.ACTION_RECOGNIZE_SPEECH just returns a set of words/phrases without any audio.