Syntax:
delegate() { //some code }
PROGRAM OF ANONYMOUS METHOD
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace AnonymousMethodsDemo { class ThreadingDemo { public void Display(string name) { Thread th1 = new Thread(delegate() { while (true) { Console.WriteLine("Welcome to " + name); Thread.Sleep(500); } }); th1.Start(); } } class Program { static void Main(string[] args) { string name; Console.WriteLine("Enter your name:"); name = Console.ReadLine(); ThreadingDemo td = new ThreadingDemo(); td.Display(name); Console.Read(); } } }
SPEECH TRANSLATION
- This is to translate the text as speech.
- This makes us to listen a voice from the speakers that reads some specified text.
- Library: System.Speech.Synthesis.SpeechSynthesizer
- This class used to speak the required text through the speakers.
Implementation:
- Create the object of SpeechSynthesizer class: SpeechSynthesizer ss = new SpeechSynthesizer();
- Set the volume (1 to 100): ss.Volume = n;
- Set the speed of speaking (-10 to +10): ss.Rate = n;
- Change the voice gender and age: ss.SelectVoiceByHints(VoiceGender.xxxx, VoiceAge.xxxx);
- Speak the text: ss.SpeakAsync(―message‖);
PROGRAM OF SPEECH TRANSLATOR
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Speech.Synthesis; namespace SpeechTranslationDemo { class Program { static void Main(string[] args) { Console.WriteLine("Enter text to speak:"); string TextToSpeak = Console.ReadLine(); SpeechSynthesizer ss = new SpeechSynthesizer(); ss.Volume = 100; //1 to 100 ss.Rate = -3; // -10 to +10 ss.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Child); ss.SpeakAsync(TextToSpeak); Console.Read(); } } }
Can you post the source code of this prgram ? thanks
ReplyDeletedownload source code here https://drive.google.com/file/d/0B0lhSRkgZAQdNlFHcGRXc1hIaVU/edit?usp=sharing
Delete