How to convert audio data into NSString in iOS? - iphone

I would like to convert audio data into NSString.
I have audio data and it is not bull. But when i convert audio into NSString that converting string is null. I am using following code.....
NSString *audioStr = [[NSString alloc] initWithData:audioData encoding:NSUTF8StringEncoding];
Where i am wrong i don't understand. Please help me any one.

If you are looking for 'Speech to Text' recognition, you can try
OpenEars
iSpeech
Also, if you just want to dictate to UITextField or UITextView, you can use the built-in option for speech-to-text.

Related

iPhone parsing of XML data, Tags not appearing

I am facing a peculiar problem in parsing some xml data within my iPhone application. When I pass the xml data to NSXMLParser class for parsing, it ignores the part where the actual data starts appearing. It shows all the element names just before the data appears such as Soapenvolopebody etc. Later, I observed that the tags are appearing with '&lt'; and '&gt';symbols which is causing the problem.
I hope this requires a replacement strategy before parsing it to NSXMLParser. My questions is why iPhone is taking XML in that way? I am generating xml dynamically from a php file and comes as an XML when loaded into IE Browser. Hope you can help me to resolve the issue.
Update
I am still looking for a solution. I think the the idea of converting NSString to NSData and then passing it to NSXMLParser could accomplish parsing.
NSString* str= #"teststring";
NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];
I found this mentioned in the following post which I will be trying out. How do I convert an NSString value to NSData?
Update 1
I get the data in NSData format. Converted to NSString and applied replacement code to done away with &lt and &gt stuff. After that, I again converted the replaced NSString to NSData format. But still the xml is not correctly parsing using NSXMLParser.
please replace the unwonted character using this string function. please refer the below code.
NSString *theXML = [[[NSString alloc] initWithBytes: [webdata mutableBytes] length:[webdata length] encoding:NSUTF8StringEncoding]autorelease];
theXML = [theXML stringByReplacingOccurrencesOfString:#"<" withString:#"<"];
theXML = [theXML stringByReplacingOccurrencesOfString:#">" withString:#">"];
theXML = [theXML stringByReplacingOccurrencesOfString:#"&" withString:#"&"];
NSLog(#"%#",theXML);
Thanks

Converting a photo data to nsstring returns nil

I'm allowing the users of my app to either take a pic or select one from their library. When selected I need to get the images' data and convert it to a string so I can send it to a web service.
The problem I'm currently having is that [NSString initWithData:] is returning nil when I have the encoding set to UTF8. I need to set it to UTF8 for the XML message.
NSString *dataString = [[NSString alloc] initWithData:UIImageJPEGRepresentation(theImage, 1.0) encoding:NSUTF8StringEncoding];
Thanks for any advice!
You can't convert an UIImage to NSString by using initWithData:encoding: method. This method is only for converting an string's data to NSString (an Text File for example).
If you are trying to convert any kind of binary data to NSString, there are some kind of encoding available. Base64 is widely used. Also your server should have the ability to decode what you've sent.
In addition, in most cases, send an image to server just need to POST it in binary as it used to be.

Image to Text (iPhone)

How can I get the texts presented on an image ?
Description : "I am developing one application which needs to get the text presented on an Image and show the text in an another view after putting the texts in to some frames."
EDIT : From this I'm getting some Values and also the ".png" but the characters I am getting is like ASCII value or something.
UIImage*img=[UIImage imageNamed:#"btn_reset.png"];
NSData *dataObj = UIImagePNGRepresentation(img);
NSString*str= [[NSString alloc] initWithData:dataObj encoding:NSASCIIStringEncoding];
printf("Image is %s",[str UTF8String]);
Any tutorial/link/solution would be very helpful.
Thank You !
I couldn't understand the question clearly, but I think you are referring to OCR.
One of the main open-source lib for this is: Tesseract
Some one has ported this lib for ios. You can get the code from: https://github.com/rcarlsen/Pocket-OCR/
you might get solution from following link:
Is there any iphone Class that converts images to text format?
If you just want to print the string
UIImage*img=[UIImage imageNamed:#"btn_reset.png"];
NSData *dataObj = UIImagePNGRepresentation(img);
NSString*str= [[NSString alloc] initWithData:dataObj encoding:NSASCIIStringEncoding];
NSLog("Image is %#",str);
If you still dont get it change the encoding

Convert NSData [UIImage] to a NSString

I am aware this question has been asked several times, but I was unable to find a definate answer that would best fit my situation.
I want the ability to have the user select an image from the library, and then that image is converted to an NSData type. I then have a requirement to call a .NET C# webservice via a HTTP get so ideally I need the resulting string to be UTF8 encoded.
This is what I have so far:
NSData *dataObj = UIImageJPEGRepresentation(selectedImage, 1.0);
[picker dismissModalViewControllerAnimated:YES];
NSString *content = [[NSString alloc] initWithData:dataObj encoding:NSUTF8StringEncoding];
NSLog(#"%#", content);
The NSLog statement simply produces output as:
2009-11-29 14:13:33.937 TestUpload2[5735:207] (null)
Obviously this isnt what I hoped to achieve, so any help would be great.
Kind Regards
You can't create a UTF-8 encoded string out of just any arbitrary binary data - the data needs to actually be UTF-8 encoded, and the data for your JPEG image obviously is not. Your binary data doesn't represent a string, so you can't directly create a string from it - -[NSString initWithData:encoding:] fails appropriately in your case.
Assuming you're using NSURLConnection (although a similar statement should be true for other methods), you'll construct your NSMutableURLRequest and use -setHTTPBody: which you need to pass an NSData object to. I don't understand why you would be using a GET method here since it sounds like you're going to be uploading this image data to your web service - you should be using POST.

How do I use comma-separated-values received from a URL query in Objective-c?

How do I use comma-separated-values received from a URL query in Objective-c?
when I query the URL I get csv such as ("OMRUAH=X",20.741,"3/16/2010","1:52pm",20.7226,20.7594).
How do I capture and use this for my application?
You have two options:
Use a CSV parser: http://freshmeat.net/projects/ccsvparse
Or parse the data yourself into an array:
// myString is an NSString object containing your data
NSArray *array = [myString componentsSeparatedByString: #","];
I recently dealt with CSV parsing for Yahoo! Finance as well. I used Ragel to write a parser in C that was good enough for the CSV I was getting. It handled everything but escaped quotes, which are not going to show up much in stock quotes. It was pretty painless and a good learning experience. I'd post the code, but it was work-for-hire, so I don't own it.
Turning a C string into an NSString is easy. If you have it as an NSData, as you likely do at the end of a URL download, just do [[NSString alloc] initWithData:csvData encoding:NSUTF8StringEncoding]. If you have a pointer to a character buffer instead, use [[NSString alloc] initWithBytes:buffer length:buflen encoding:NSUTF8StringEncoding]. buflen could be strlen(buffer) if buffer is a normal, NUL-terminated C string.