【问题标题】:Change the culture of voice to other languages将语音文化更改为其他语言
【发布时间】:2018-05-08 07:46:50
【问题描述】:

我有一些英语文化以外的文本。 例如:泰米尔文化。

如果我不提及文化,将采用默认英语。

如何将文字转成语音(英文除外)?

代码sn-p:

英语语言:

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

对于其他语言:

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);
}

【问题讨论】:

标签: c# text-to-speech culture speech-synthesis


【解决方案1】:

默认情况下,可能会使用操作系统的语言、区域设置,这就是为什么它适用于 en-US 文化而无需您明确设置文化的原因。

因此,如果您希望您的程序在不同的机器上读取不同语言的文本,那么可能不需要额外的设置。每台机器都应该有相同的区域/语言设置来阅读文本。

如果没有,那么您有两个选择。

选项 1:您可以在 PromptBuilder 上为每个段落或每个句子设置文化​​,就像您在泰米尔语代码示例中所做的那样。

选项 2:您可以使用 SSML

MSDN documentation at this link 中所述,您可以生成 SSML,您可以在其中使用 lang 指定语言。然后您可以使用 SpeakSsml 或 SpeakSsmlAsync API 来读取内容。

  // 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);  

希望这对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    • 1970-01-01
    相关资源
    最近更新 更多