您可以按照以下方法将参数改为另一种样式:

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: 语言代码,例如 'en-US'。
  • name: 语音合成器名称,例如 'Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)'。
  • style: 语音风格,例如 'casual'、'formal'。
  • styleDegree: 语音风格程度,数值范围为 0 到 100,数值越高,风格越明显。
  • text: 要合成的文本。

旧参数映射到新参数:

  • speaker -> name
  • _msg -> text
  • format -> style
  • length -> styleDegree
  • noise -> 无对应参数,可以使用 style 参数设置噪音风格。
  • noisew -> 无对应参数,可以使用 styleDegree 参数调整噪音程度。
  • sdp_ratio -> 无对应参数。

示例代码:

// 旧参数
string speaker = 'Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)';
string _msg = 'Hello world!';
string format = 'casual';
float length = 50;
float noise = 0.1f;
float noisew = 0.5f;
float sdp_ratio = 1.0f;

// 新参数
string lang = 'en-US';
string name = speaker;
string style = format;
int styleDegree = (int)length;
string text = _msg;

// 使用新参数调用 API
string xml = GenerateTextToSpeech(lang, name, style, styleDegree, text);
C# Text-to-Speech API 参数修改指南

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

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