JAVA using google speech recognition API - java

I'm trying to use google speech recognition API. Here's the code i've written:
http://pastebin.com/zJEhnJ74
It works. I get an answer from the server:
{"status":5,"id":"8803471b14a2310dfcf917754e8bd4a7-1","hypotheses":[]}
Now the problem is "status:5". Infact, here's status code:
status: 0 – correct
, status: 4 – missing audio file, 
status: 5 – incorrect audio file.
My problem is "incorrect audio file". I don't understand if it is a .flac file error (you can download my test .flac file here: http://www21.zippyshare.com/v/61888405/file.html) or how i read the file (in a byte array then convert it into string)
Thanks for help! and sorry for my bad english

You must use wr.write(data); instead of wr.writeBytes(new String(data));
Google answer:
{"status":0,"id":"e0f4ced346ad18bbb81756ed4d639164-1","hypotheses":[{"utterance":"hello how are you","confidence":0.94028234},{"utterance":"hello how r you"},{"utterance":"hello how are u"},{"utterance":"hello how are you in"}]}

Related

Passing buffer from SuperpoweredAndroidIO to Java InputStream / Android NDK

I am using the amazing Superpowered library (SuperpoweredAndroidAudioIO) for low-latency recording of audio. While the basic concepts are clear to me, I want to pass the recorded audio (which arrives in a buffer) back to an InputStream in Java (without recording to a file), from which I can then read the recorded audio and process it.
I guess this question could also be more generally asked - how to feed an InputStream in Java from a periodically updated buffer in C++?
Well, the suggestion I received in a comment turned out to be a simple and working solution:
Creation of pipe in C++:
if (pipe(pipefd) == -1) {
__android_log_print(ANDROID_LOG_VERBOSE, "C++", "Error creating pipe");
}
...
Passing file descriptor to Java:
...
return pipefd[0];
...
Then in Java/Android:
private ParcelFileDescriptor.AutoCloseInputStream underlyingStream;
ParcelFileDescriptor pfd = ParcelFileDescriptor.adoptFd(getFD());
underlyingStream = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
Worked well for me, but of course I'm still happy to receive other suggestions.

apache commons imaging writing image error

Below is the sample code that is giving error with the microsoft sample pictures (tulips.jpg) image
bufferedImage = Imaging.getBufferedImage(new file("Tulips.jpg"));
File imageFile = new File("outputfile.jpg");
final Map<String, Object> optionalParams = new HashMap<String, Object>();
Imaging.writeImage(bufferedImage, imageFile, ImageFormats.JPEG, optionalParams);
This code is giving "This image format (Jpeg-Custom) cannot be written." Any pointers would be of great help. I have searched stackoverflow, google - no help so far.
When I read the documentation it states that if the bufferedImage.getType()== TYPE_UNKNOWN, it gives this message but dont have a clue why it is giving UNKNOWN.
Thanks so much for your help.
Write to JPEG files is not supported by Apache Commons Imaging. You can see supported format information here: http://commons.apache.org/proper/commons-imaging/formatsupport.html (even JPEG read is not fully supported). However write to some other formats supported (e.g. you can change image format to PNG in your writeImage function call and it will work).
Moreover Apache Commons Imaging is not released yet, so I wouldn't recommend using it in a critical code.
As alternative you can take a look into JDK javax.imageio.ImageIO class (some examples: https://docs.oracle.com/javase/tutorial/2d/images/saveimage.html).
What exactly are you trying to achieve in your code?

PHP webservice file upload & download logic with Android client

First, this is my first time building both of webservice and android client at the same time, so please kindly help me. My goal is to be able to upload a file from android apps and download it from the webservice.
This is what i did for upload (working, but im not sure this is a best way) :
Convert the image to base64 String in android apps
Send that converted string (form image) to the webservice.
Decode that string with base64_decode function in the webservice.
Save the image from the decoded string, using file_put_contents.
Input the decoded string to the BLOB field in my database.
What make me confuse is, if i already saved the image file (step 4), do i still need to save it to the BLOB column (step 5)?
Now, i got confuse with the download part. This is what im planning to do :
Get the image file from step 4 in upload using file_get_contents (return string)
Send the result (string) to my android apps
Get the string and convert it to the image (how?)
Is it all i need to download?
Do i need to use base64_decode or base64_encode in download? When do i use it?
Sorry if my question sounds silly, i still dont get the logic.
Thanks a lot for your time, all help is appreciated.
What make me confuse is, if i already saved the image file (step 4), do i still need to save it to the BLOB column (step 5)?
No you don't. You can store in DB just a reference to that file, like filename or full path.
Now, i got confuse with the download part. This is what im planning to do :
Get the image file from step 4 in upload using file_get_contents (return string)
and base64_encode it
Get the string and convert it to the image (how?)
You need to base64 decode it, because you encode it before sending it from the server. (step 1)

How to get thumbnail from Dropboxapi using JAVA SDK?

I am working with Dropbox API using JAVA SDK. I try to get the thumbnail for each image in my dropbox account via API. Honestly, after I read the class and they just provided the description which is not useful enough for the beginner. I begin my code like this
public void getThumbnails() throws DropboxException{
DropboxInputStream dis = api.getThumbnailStream("/Koala.jpg", ThumbSize.ICON_256x256, ThumbFormat.JPEG);
}
What I don't understand is:
I should return something to client side in order to show the thumbnail I got from DropboxAPI but I don't know what I should return. Maybe DropboxInputStream?
How do I get the thumbnail from API? I try to find the example or guide for a day but I can't find any guide...
please someone guide me how to get the thumbnail via dropbox API
DropboxInputStream is just a FilterInputStream so after you get the input stream like you wrote you can just iterate the input stream and read it.
Then it's only a question of the way you need to present it.
Is it a Swing application you are writing? how do you need to show that image?
You should be able to read the Image with ImageIO.read
Image image = ImageIO.read(dis);
http://docs.oracle.com/javase/6/docs/api/javax/imageio/ImageIO.html

Android get 1st result and copy from google search(automatic)

I want a code to search to google engine for songs via zippyshare . For example the keyword will be "inna sun is up zippyshare" and the first result is this url www32.zippyshare.com/v/55151563/file.html . i want to retrieve the code 55151563 from the the 1st result of google.
Thank you in advance
I will not write the code for you, but I can tip you to the right approach.
Get the url using String search = "http://www.google.com/search?hl=en&q=" + string_to_search;
Download the webpage using URL, InputStream and OutputStream. Check this post here.
Read the file and find the first instance of zippyshare.
Here you can read about xml parsing

Categories

Resources