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

Friday, August 06, 2010

Right To Left iPhone UI

Peace be upon you.

I have been working on Arabic Apps for iPhone, sometimes I need to do things quickly rather than making the whole UI components from the beginning, I came up with good trick to enable me doing Right To Left UIs with minimum effort, it is not perfect but it is working just fine.

There is something in Core Graphics called Affine transformations , this set of function all you doing anything related to image manipulation, as the UI elements turned to be image at the end, the property "transform", it has the typical 2d Array of image manipulation

based on that fact I started playing with the UI controls here is what I have got playing with the tab bar controller and Table view controller


Normal view, no changes , as u can see the tabs aren't arrange in the Arabic Logic

I started by "rotating" the whole bar 180º

I did loop through the buttons and rotate them 180º so it end up with correct view for the view, flipping flipped image makes it look correct

I have added more than 5 tabs and I have got the same thing with the more button, the items are viewed from left to right


I did loop through the cell of the table and I did rotation for the whole cell, then correcting the text by rotating it 180º .

The thing is little bit UI buggy but with some time it can be fixed to look Ok,
here is the code for this thing, All U have to do is replacing the code for the function "didFinishLaunchingWithOptions"




UIViewController* cont1 = [[UIViewController alloc]init];

UIViewController* cont2 = [[UIViewController alloc]init];

UIViewController* cont3 = [[UIViewController alloc]init];

UIViewController* cont4 = [[UIViewController alloc]init];

UIViewController* cont5 = [[UIViewController alloc]init];

UIViewController* cont6 = [[UIViewController alloc]init];

UINavigationController* contBar = [[UINavigationController alloc] initWithRootViewController:cont1];

contBar.tabBarItem.title = @"واحد";

cont2.tabBarItem.title = @"أثنين";

cont3.tabBarItem.title = @"ثلاث";

cont4.tabBarItem.title = @"أربع";

cont5.tabBarItem.title = @"خمس";

cont6.tabBarItem.title = @"سته";

cont1.view.backgroundColor = [UIColor redColor];

cont2.view.backgroundColor = [UIColor blueColor];

cont3.view.backgroundColor = [UIColor grayColor];

cont4.view.backgroundColor = [UIColor purpleColor];

cont5.view.backgroundColor = [UIColor yellowColor];

const id objs[6] = { contBar,cont2,cont3,cont4,cont5,cont6};

NSArray* vuCont = [NSArray arrayWithObjects:objs count:6];

tabBarController.viewControllers = vuCont;

tabBarController.tabBar.transform = CGAffineTransformMakeRotation(3.142857142857143);


for (id d in tabBarController.tabBar.items) {

UIView* vu = [d valueForKey:@"_view"];

vu.transform = CGAffineTransformMakeRotation(3.142857142857143);

}

UITableView* tbl = [tabBarController.moreNavigationController.topViewController view];

tbl.separatorColor = [UIColor clearColor];

for (UITableViewCell* cl in [[tabBarController.moreNavigationController.topViewController view] visibleCells]) {

cl.transform = CGAffineTransformMakeRotation(180*0.0174532925);

cl.textLabel.transform = CGAffineTransformMakeRotation(180*0.0174532925);

cl.textLabel.textAlignment = UITextAlignmentRight;


}


[window addSubview:tabBarController.view];

[window makeKeyAndVisible];


return YES;




Thanks for your time :)


Ahmed Essam

Wednesday, March 03, 2010

My Session Resource (Cairo Code Camp 2010)

Peace be upon you
How are you guys? First of all I would like to thank everyone at Cairo Code Camp, I really enjoyed ever minute there.
Here is the most amazing part, I gave a session at Cairo Code camp about iPhone development using C#, I thought that few people will be interested in such thing and the amazing thing is, the hall was full of people + there was some people setting on the ground (not a lot but it happen :D ), I have got amazing feed backs, I really can't believe that such thing happen :D, I would agree if 10 people attend the session :D but I got about 150 which is great, Now I am officially a technical speaker :).
anyways, Here is the source code and the presentation, I hope you like it.

Here is the path for the folder
MonoTwit fitch the timeline and post twits
MonoFlick Search for keyword and view the photos


I hope you like the slides, thanks for your time :)

BR
Ahmed Essam

VB script that speak ( something to read for you )

Peace be upon you

As sometimes I lose the focus and ability to read from the screen, sometimes I prefer listening to what I want to read, I use Mac most of the time and I really like the TTS support on it, it really feels very much like human, anyways, I liked to do so on Windows, I collected some code that can speak what's on the clipboard, so all you have to do, is put this code in file and put extension to file "VBS" , after that copy any text u like to hear and double click the vbs file, it will say the contents of the clipboard



Option Explicit

Const SVSFlagsAsync = 1
const SVSFPurgeBeforeSpeak = 2

Dim Speech
Dim FSO

CreateObjects
Main
DestroyObjects
Quit

Sub Main
Dim sText
Dim oIE
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.navigate "about:blank"
sText = oIE.document.parentWindow.clipboarddata.getData("text")
Set oIE = Nothing
'sText = InputBox("text", "Text2Speech")
sText = Trim(sText)
If sText <> "" Then
SpeakText sText
End If
End Sub

Sub SpeakText(sText)
On Error Resume Next
Speech.Speak sText, SVSFlagsAsync + SVSFPurgeBeforeSpeak
Do
Sleep 100
Loop Until Speech.WaitUntilDone(10)
End Sub

Sub StopSpeaking()
On Error Resume Next
Speech.Speak vbNullString, SVSFPurgeBeforeSpeak
Set Speech = Nothing
End Sub

Sub CreateObjects
Set Speech = CreateObject("SAPI.SpVoice")
Set FSO = CreateObject("Scripting.FileSystemObject")
End Sub

Sub DestroyObjects
Set Speech = Nothing
Set FSO = Nothing
End Sub

Sub Sleep(nTimeout)
WScript.Sleep nTimeout
End Sub

Sub Quit
WScript.Quit
End Sub


thanks for your time and I hope this trick is useful to you

BR
Ahmed Essam
There was an error in this gadget