你可以将原始代码改为以下样式:

public string GenerateTextToSpeech(string lang, string name, string style, int styleDegree, string text)
{
    string xml = string.Format(@'<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis'
        xmlns:mstts='https://www.w3.org/2001/mstts' xml:lang='{0}'>
        <voice name='{1}'>
            <mstts:express-as style='{2}' styledegree='{3}'>
                {4}
            </mstts:express-as>
        </voice>
    </speak>', lang, name, style, styleDegree, text);

    return xml;
}

请注意,在修改后的代码中,参数的名称和顺序已经改变。现在,你需要提供语言(lang)、名称(name)、样式(style)、样式程度(styleDegree)和文本(text)作为输入参数,并返回一个 XML 字符串。

C# Text-to-Speech 代码优化:使用 XML 格式生成语音

原文地址: https://www.cveoy.top/t/topic/jEhP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录