Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the culture of voice to other languages

I have an some text other than English culture. Ex: Tamil culture.

If I don't mention culture, default English will be taken.

How to convert the text into voice (other than English)?

Code snippet:

For English Language:

public static void ConvertTextToVoice()
    {
        SpeechSynthesizer speech = new SpeechSynthesizer();
        speech.Volume = 100;
        speech.Rate = 0;            
        speech.Speak("Welcome to india");
    }

For other language:

public static void ConvertTextToVoice()
{
    SpeechSynthesizer speech = new SpeechSynthesizer();
    speech.Volume = 100;
    speech.Rate = 0;

    //Tamil Text
    string text = "பெயர்ச் சொல் சகோதரன் பிரதி பெயர்கள் வினைச் சொல் வினை அடை";

    PromptBuilder builder = new PromptBuilder(new System.Globalization.CultureInfo("ta-IN"));
    builder.AppendText(text);           
    speech.SpeakAsync(builder);
}
like image 576
Pandi Avatar asked Nov 24 '17 10:11

Pandi


1 Answers

By default, probably, Operating system's language, region settings are getting used and that's why it works for en-US culture without you explicitly setting the culture.

So, if you want your program to read the text in different languages on different machines, then probably no extra settings are required. Every machine should have the same region /language settings in which the text should be read.

If not, then you have two options.

Option 1: You can set the culture on PromptBuilder for every paragraph or for every sentence as you already have done in your code sample of Tamil.

Option 2: You can use SSML

As explained in MSDN documentation at this link, you can generate SSML where you can specify the language using the lang. Then you can use SpeakSsml or SpeakSsmlAsync APIs to read the contents.

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

  // Configure the audio output.   
  synth.SetOutputToDefaultAudioDevice();  

  // Build an SSML prompt in a string.  
  string str = "<speak version=\"1.0\"";  
  str += " xmlns=\"http://www.w3.org/2001/10/synthesis\"";  
  str += " xml:lang=\"en-US\">";  
  str += "<say-as type=\"date:mdy\"> 1/29/2009 </say-as>";  
  str += "</speak>";  

  // Speak the contents of the prompt asynchronously.  
  synth.SpeakSsmlAsync(str);  

Hope this helps you.

like image 71
Manoj Choudhari Avatar answered Sep 18 '22 19:09

Manoj Choudhari