Sinhala Text To Speech in C#



This is a simple c# sharp program that speaks the sinhala Unicode characters. Normaly known as "text to speak". This can be used to further development of your software.

Step 01

First you have to install these software.

Sinhala Text to Speak Developed by the University Of Colombo School Of Computing.Download


or

Windows version of the "eSpeak" Text to Speak Download (Compiled for Windows. SAPI5 and command-line versions.)

You can install both of them if you like. By doing that you can two sinhala voice.

Step 02

How to install "eSpeak".

You just have to click on the .exe install it. But there is one more thing you have to concern. When installing you have to give the language as "si" instead of "en en+f2".


change above one to below one


"eSpeak" contains several other languages. You just have to find the language code (ex: "si" for sinhala ) and input it when you install eSpeak.
for more info go to http://espeak.sourceforge.net/

Step 03

Before you compile the code you have add reference to Visual Studio 2010.

Right click on "reference" on the solution explorer and right click on it and click "add".



And then click ".NET" tab and select "System.speech". Then press ok.


Source :: code explained with comments


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.IO;
using System.Speech.Synthesis;
using System.Speech.AudioFormat;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;
using System.Speech.Synthesis.TtsEngine;

// before compiling, add references -> System.Speech

namespace ConsoleApplication4
{
    class Program
    {
        
        
        static void Main(string[] args)
        {
            //string that is to be read
            string TextProperty = "";
            
            //stores the voices that are installed on your computer 
            List<VoiceInfo> lst = new List<VoiceInfo>();

            // Initialize a new instance of the SpeechSynthesizer.
            using (SpeechSynthesizer synth = new SpeechSynthesizer())
            {

                // Output information about all of the installed voices. 
                Console.WriteLine("Installed voices -");

                foreach (InstalledVoice voice in synth.GetInstalledVoices())
                {
                    VoiceInfo info = voice.VoiceInfo;
                    string AudioFormats = "";
                    foreach (SpeechAudioFormatInfo fmt in info.SupportedAudioFormats)
                    {
                        AudioFormats += String.Format("{0}\n",
                        fmt.EncodingFormat.ToString());
                    }

                    Console.WriteLine(" Name:          " + info.Name);
                    Console.WriteLine(" Culture:       " + info.Culture);
                    Console.WriteLine(" Age:           " + info.Age);
                    Console.WriteLine(" Gender:        " + info.Gender);
                    Console.WriteLine(" Description:   " + info.Description);
                    Console.WriteLine(" ID:            " + info.Id);
                    Console.WriteLine(" Enabled:       " + voice.Enabled);
                    if (info.SupportedAudioFormats.Count != 0)
                    {
                        Console.WriteLine(" Audio formats: " + AudioFormats);
                    }
                    else
                    {
                        Console.WriteLine(" No supported audio formats found");
                    }

                    string AdditionalInfo = "";
                    foreach (string key in info.AdditionalInfo.Keys)
                    {
                        AdditionalInfo += String.Format("  {0}: {1}\n", key, info.AdditionalInfo[key]);
                    }

                    Console.WriteLine(" Additional Info - " + AdditionalInfo);
                    Console.WriteLine();
                }

                foreach (InstalledVoice voice in synth.GetInstalledVoices())
                {
                    //add the voice to the list
                    lst.Add(voice.VoiceInfo);
                }
            }



            // Initialize a new instance of the SpeechSynthesizer.

            using (SpeechSynthesizer synth1 = new SpeechSynthesizer())
            {

                //select the voice you want to speak
                //to read sinhala unicode you must input the the index of a sinhala voice.
                //sinhala voices
                //  * Festival Sinhala Dephone
                //  * eSpeak-si
                //or input the index of the voice that you would like to hear.
                synth1.SelectVoice(lst[5].Name);

                //change the speed of speaking
                synth1.Rate = -3;

                //creat a folder called "speak" in your "c" drive
                //and create a "abc.txt" with sinhala unicode
                // try puting these "කොළොඹ විශ්වවිද්‍යාලයිය පරිගණක  අධ්‍යනායතනය "
                PromptBuilder speakText = new PromptBuilder();
                using (StreamReader reader = new StreamReader(@"C:\speak\abc.txt"))
                {
                    // read all content file to the string property on your form.
                   TextProperty = reader.ReadToEnd();
                }

                // Speak the contents of the prompt.
                synth1.Speak(TextProperty);
            }
        }
    }
}


This program has been tested with "win 7" and "win 8" with "Visual Studio 2010"

Download the complete project and compile and run it.
please leave a comment.
SHARE

Harsha Jayamanna

    Blogger Comment
    Facebook Comment

9 comments:

  1. its vry use ful amzn

    ReplyDelete
  2. To Tharindu Lakmal:
    Did you try it with windows 8? before 8.1? Did you install "eSpeak"?

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Install "eSpeak". Use the spteps in this post.and then run the program..

      And also, this is the line that takes the name of the input voice
      synth1.SelectVoice(lst[5].Name);

      lst[5].Name=name of the voice.


      Delete
    4. Thank you very much for your help. Now, It's working properly. It's nice... (y)
      Dear friend, Can't I find the source code of eSpeak.
      If you can please send it to me "Tharindu.mypro@gmail.com"
      Thank you very much...

      Delete
    5. My pleasure brother. Yes definitly.I ll mail it if i could find it. Keep and touch. Cheers..!!!

      Delete