If you’ve seen the iPhone 3GS or the iPod touch 3G, or even the new iPod Shuffle, you might have heard it talk to you. Whether it told you the name of the song that is playing or it asking you who you want to call. Want to implement this in your app? It’s easy! Very, very easy.
WARNING: This only works on iPod touch 3G’s and the iPhone 3GS and this is a private framework, so if you submit this to the App Store, don’t expect it to be accepted.
First, start off with making a new view-based app called “TextTalker”

Navigate to “TextTalkerViewController.h” and add to your interface:
@interface TextTalkerViewController : UIViewController {
IBOutlet UITextView *stuff;
}
@property (nonatomic, retain) IBOutlet UITextView *stuff;
-(IBAction)speak;
This is adding a TextView where the user can type stuff in and then a button, which we will later have it say out loud what the user typed in the UITextView (stuff)
Now open “TextTalkerViewController.xib” and add a UITextView from the library and then hook it up to “stuff”

Add a UIButton and hook it up to “speak” and then quit Interface Builder.
Go to your “Frameworks” folder and add a new framework. You need to navigate to PrivateFrameworks in the 3.1 SDK and find VoiceServices.framework. Add it and then open TextTalkerViewController.m. Add an IBAction method with the name you put in the .h file (stuff) and then add:
NSString *_string = [stuff text];
NSObject *talk = [[NSClassFromString(@”VSSpeechSynthesizer”) alloc]init];
[talk startSpeakingString:[NSString stringWithFormat:@”%@”, _string]];
What we are doing here is making a string that gets whatever the user typed in and then in startSpeakingString, the %@ in stringWithFormat:@”%@” is being replaced with whatever the string named “_string” is holding.
Compile and install it on an iPod touch 3G or iPhone 3GS and press the button. It should say whatever is entered in your UITextView.
You can download the source code for this application here. If you have any questions, you can email me at jonah [AT] jonahgrant [DOT] com or on twitter as @jonahgrant
©2010. Postage by Greg Cooper. Icons by P.J. Onori. Thanks to Jamie Cassidy & Panic.
*Unlikely to find your lost post using this but you can try...
Comments