提供一个.net的讯飞在线语音合成SDK
使用方法:
1.nuget搜索下载安装
2.demo源码
public partial class Form1 : Form { XunFeiTTS xunFeiNetSdk; public Form1() { InitializeComponent(); string appId = ConfigurationSettings.AppSettings["appId"]; string apiKey = ConfigurationSettings.AppSettings["apiKey"]; string apiSecret = ConfigurationSettings.AppSettings["apiSecret"]; xunFeiNetSdk = new XunFeiTTS(appId, apiKey, apiSecret); xunFeiNetSdk.MessageUpdate_Event += XunFeiNetSdk_messageUpdate_Event; } private void Form1_Load(object sender, EventArgs e) { } /// <summary> /// 缓存返回数据 /// </summary> byte[] data = new byte[0]; private void XunFeiNetSdk_messageUpdate_Event(TTS_Data_Model message, string error) { if (error != null) { MessageBox.Show(error); return; } try { //合成结束 if (message.status == 2) { data = data.Concat(message.audioStream).ToArray(); var mWavWriter = new WaveFileWriter("test.wav", new WaveFormat(16000, 1)); mWavWriter.Write(data, 0, data.Length); mWavWriter.Close(); MessageBox.Show("合成成功"); data = new byte[0]; } else { data = data.Concat(message.audioStream).ToArray(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button1_Click(object sender, EventArgs e) { xunFeiNetSdk.SendData("积极参与全球卫生治理,为世界公共卫生事业作贡献,是责任也是义务,符合人类共同利益。只有团结协作,人类才能获取制胜之力,才能共享生命安全"); } }
文章评论