Change the culture of voice to other languages
Asked Answered
I

1

6

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);
}
Interview answered 24/11, 2017 at 10:5 Comment(5)
So, if I understood your question correctly - you are asking for a language detection based on the inputed string?Assortment
Yes. Based upon languages the culture need to be changedInterview
@Pandi: Refer this question https://mcmap.net/q/376011/-how-to-detect-the-language-of-a-string/5395773Fatback
@venkat: This Link will be used for detect the language.But my requirement is need to convert that text into speech.Interview
Guess that might help you, #29164494Biggs
M
1

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.

Metempirics answered 28/1, 2019 at 8:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.