Search This Blog

Friday, November 19, 2010

iOS SDK Text To Speech in one line

Peace be upon you

How are you guys? I am so glade that I am writing to you, todays post will be short and hopefully useful.

While I was digging in iOS's private frameworks one library caught my attention, "VoiceServices" after some playing around it I found that there is away to use the "VoiceOver" capabilities out of its context, Here is video explaining the whole thing.


Here is the code for it.

[[[NSClassFromString(@"VSSpeechSynthesizer") new]autorelease] startSpeakingString:@"I like to speak everywhere"];


As you can see, with this line u can make the iOS speak whatever to you, just find useful use for it, something to read the twits or RSS feeds.


Enjoy :)


BR

Ahmed Essam

Thursday, November 04, 2010

Extending TBXML

Peace be upon you

How are you my beloved reader :)? I hope things is going Ok with you.

today I have added something to the library "TBXML" to extend the functionality to help reading XML in easier way.
Here is link for the library http://tbxml.co.uk/

the functions that I have wrote simply reads the XML and turn it into "Dictionary (Hash table)" the functions that I have wrote neglects the attributes, such code will help transforming the complex hierarchy of XML into dictionary that has key value (the value code be string, array or another dictionary )

Here is the code that I have added to the library (Add this code to the class "TBXML")


+ (NSMutableDictionary*) getXMLNodeInDictionary:(TBXMLElement *)element {

NSMutableDictionary* retDict = [NSMutableDictionary new];

do {

if (element->firstChild) {

if ([retDict valueForKey:[TBXML elementName:element]]==nil) {

[retDict setObject:[self getXMLNodeInDictionary:element->firstChild] forKey:[TBXML elementName:element]];

}else if ([[retDict valueForKey:[TBXML elementName:element]] isKindOfClass:[NSMutableArray class]]) {

[[retDict valueForKey:[TBXML elementName:element]] addObject:[self getXMLNodeInDictionary:element->firstChild]];

}else {

NSMutableArray* arr = [NSMutableArray new];

[arr addObject:[retDict valueForKey:[TBXML elementName:element]]];

[arr addObject:[self getXMLNodeInDictionary:element->firstChild]];

[retDict setObject:[arr autorelease] forKey:[TBXML elementName:element]];

}

}else {

[retDict setObject:[TBXML textForElement:element] forKey:[TBXML elementName:element]];

}

} while ((element = element->nextSibling));

return [retDict autorelease];

}


+ (NSMutableDictionary*)getXMLFileInDictionary:(NSString*)filenameWithFullPath{

NSString* str = [[NSString alloc]initWithContentsOfFile:filenameWithFullPath];

TBXML * tbxml = [TBXML tbxmlWithXMLString:str];

if (!tbxml.rootXMLElement) {

return nil;

}

return [self getXMLNodeInDictionary:tbxml.rootXMLElement];

}




Thanks for your time :)


BR

Ahmed Essam