Monday, 4 November 2013

How to use CHARTS in your C# Application

Open your application via visual studio. Open ToolBox, from ToolBox under data section, You will notice Chart. drag and drop it into your Form.cs[Design].


And also drag the button into form and name it Load.
Now click on chart to open its properties window and select series.


Now Series Collection Editor will open. Under Data .. Name the Text as Age. As we want to draw the chart of Age VS Name. You can customize your chart by Appearance Properties.You can also chose what type of chart you want to use.   


Double click the Load button to open Load event. We are using Chart class and its series property. It takes collection as a parameter. Points is a property of series class. AddXY is a method of DataPointCollection class.
Copy the following code into button event .

\
Now after saving it click on start button to run it, Click the load button to load the chart.






Saturday, 2 November 2013

Text to speech application in Android

Text to speech in Android
Hi friends, Today we are going to develop an Android application - Text to speech converter.
Lets start, Open your ADT Bundle(Eclipse), 
Go to File -- New -- Android Application Project . Name the project TextToSpeech. Go on clicking until finish button comes. 

Open activity_main.xml and MainActivity.java
In activity_main.xml. Copy the following code.



Graphical Layout of activity_main.xml will look like this 


Now we will open MainActivity.java file.
Import some packages into .java file. 

If you refer http://developer.android.com/reference/android/speech/tts/TextToSpeech.html . i.e TextToSpeech class in developer.android documentation, they told two things. 


So, first of all implement TextToSpeech.OnInitListener interface and import following packages. If you visit  TextToSpeech.OnInitListener. in developers.android. You will notice one abstract method. Short meaning of abstract method is it have to define/implement in subclass. So we will also implement onInit() method in MainActivity.java 


Before that just import following packages:
import java.util.Locale;
import android.speech.tts.TextToSpeech;

Implementing TextToSpeech.OnInitListener.


Now we will create references of 3 classes
  1. Button class
  2. EditText class
  3. TextToSpeech class

Now we will write few sentences,
  1. We will initialize tts reference by coping its own object.
  2. call method findViewById for button and EditText and we will set their id's.(Refer R.java and .xml)
  3. We will call setOnClickListener method for b object. setOnClickListener method needs View.OnClickListener  Object which is an interface hence we cant directly create object and pass, We will use anonymous class concept . If we visit View.OnClickListener then we will find one absstract method onClick().



          We have nothing to do with view object, hence we won't go in details of view. Whatever action we have to take after clicking button will be written in onClick() method. hence we just call user defined start() method. We will define it later.

Now we will write init() method.
Local is a class of java.util.Local and US feild is static hence we access it directly by class name. setEnabled() is button class method which requires Boolean value  





Now we will write start() method.

getText() method is of EditText class and it returns string value. hence we call toString() method to get output in String format. speak() method is of TextToSpeech class. it returns int value but we have nothing to do with that value. hence we are not taking it. speak() has 3 parameters.

  1. String (Which we have stored in text in previous line)
  2. integer queueMode (Constant integer value provided by TextToSpeech class)
  3. Hashmap (NULL)






Now our next step is to call shutdown() method. 
Now we will write onDestroy method().





Now our project is ready. Its time to run it. Open your AVD . Go in Windows--Android Virtual Device Manager-- Start AVD.(If created otherwise you have to create it by going Windows--Android Virtual Device Manager)
Now right click on your project and run as Android Application. In emulator type the input in EditText and click start to listen the output



***** Thank You *****

















 







Friday, 1 November 2013

Text To Speech in C#

Text to speech converter in C#
Hi friends, today I am writing blog about how to make Text to speech C# application. 
Open your visual studio. I am using Visual studio 2012. Go to File -> New Project -> Windows Form Application, Select Visual C#. Name the project TextToSpeech.

Now, for text to speech application we need to add references.
Procedure to add references is
1. Open your solution explorer (Menu bar -> View - > Solution Explorer OR Ctrl+w,s ).

2. Right click on TextToSpeech , Add references . Now here is Reference Manager.

3. Search System.speech and add it

Now , To design a form, We will require a Tool box. Open Tool box just as you opened Solution Explorer.
Or just press Ctrl+w, x  to open Tool box.

Now we will make design part of an application. We will need four buttons and one RichTextBox. We will drag and drop that into our form.

Now we will rename button texts, So we are going to rename them as start, pause, resume and stop by using properties. Properties will open by clicking button only once. Just go to Text and rename it.
and save it.
Repeat the process for all four buttons.


Now we will add some namespaces to Form1.cs. Please note that Form1.cs and Form1.cs [Design] are two different files.

These Two namespaces are (Which we have to write on the top section):
using System. Speech;
using System.Speech.Synthesis;


Now declare the object of SpeechSynthesizer, we will name it reader. In Partial class Form1.
Object declaration: 



And copy the following code.


Here is the explanation of above code.

SpeekSyn
thesizer is a sealed class. And its method SpeakAsync is taking String as an argument. And that string is the string that we want to convert into a speech.
Refer the document provided by msdn.
Just Google SpeekSynthesizer and go to msdn link


Type of richTextBox1.Text
is string. So, you can take this in string variable and use it.
Now we will look at pause button event AND button resume event:

Explanation :
if reader is not null that is there is something in reader object(text in string format). Then go in inner if.
1       1.  Pause - If state of reader is speaking then pause it.
2       2. Resume - If state of reader is paused then resume it.

     Now the obvious question is how am I able to write those statements?
1.       State is a property which we have used in inner if. Again Google SynthesizerState  class, visit msdn link. Under property section, you will get state property.

If we check State property then we will get its syntax:   

        But it gets the SynthesizerState object. Lets check SynthesizerState.


       We came to know that SyntheSizerState is an enum and its members are 

1               1.  Paused
2               2. Ready
3               3. Speaking.
Hence,


Same in the case of Resume.
Now we will check stop event.

Explanation of above code:
If there is something in reader object, Dispose it. Dispose() method is public and of SpeechSynthesizer class. Which releases all recourses, that is it stops the process.


  Now we are ready to run it.

  Click the start button to run it.
1.      Type whatever you want text to be converted into speech into RichTextBox. Use buttons to    control 
.

******* Thank You *******