目录
1.注册微软云服务,搭建文本转语音标准应用(每月500万字免费好像)
2.Visual studio使用nuget给程序安装Microsoft.CognitiveServices.Speech框架
3.引用命名空间
4.文本转语音参考代码
5.文本转语音下载到本地参考代码
1.注册微软云服务,搭建文本转语音标准应用(每月500万字免费好像)
2.Visual studio使用nuget给程序安装Microsoft.CognitiveServices.Speech框架
3.引用命名空间
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
4.文本转语音参考代码
static string YourSubscriptionKey = "你的应用密匙";
static string YourServiceRegion = "应用密匙下面的区域";
async static Task Main(string[] args)
{
//创建登陆验证的配置文件
var speechConfig = SpeechConfig.FromSubscription(YourSubscriptionKey,YourServiceRegion);
//设置语音合成角色为云溪
speechConfig.SpeechSynthesisVoiceName = "zh-CN-YunxiNeural";
//创建请求对象,填入配置
using (var speechSynthesizer = new SpeechSynthesizer(speechConfig))
{
//创建要转语音的内容
string text = "hello";
//等待响应自动播放声音,注意保持网络流畅,太卡可能不行
await speechSynthesizer.SpeakTextAsync(text);
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
5.文本转语音下载到本地参考代码
static string YourSubscriptionKey = "你的应用密匙";
static string YourServiceRegion = "应用密匙下面的区域";
async static Task Main(string[] args)
{
var speechConfig = SpeechConfig.FromSubscription(YourSubscriptionKey,YourServiceRegion);
//创建保存路径的配置文件
var audioConfig = AudioConfig.FromWavFileOutput("test.mp4");
speechConfig.SpeechSynthesisVoiceName = "zh-CN-YunxiNeural";
//创建请求对象,写入配置
using (var speechSynthesizer = new SpeechSynthesizer(speechConfig, audioConfig))
{
string text = "hello";
//等待响应,不会播放,会直接保存文件到上面指定路径
await speechSynthesizer.SpeakTextAsync(text);
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
————————————————
版权声明:本文为CSDN博主「林传凯」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_46616558/article/details/127109060
本博客Android APP 下载 |
![]() |
支持我们就给我们点打赏 |
![]() |
支付宝打赏 支付宝扫一扫二维码 |
![]() |
微信打赏 微信扫一扫二维码 |
![]() |
如果想下次快速找到我,记得点下面的关注哦!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2016-08-18 【转】C# 中的委托和事件
2016-08-18 你知道C#中的Lambda表达式的演化过程吗