微软的文本转语音服务Microsoft.CognitiveServices.Speech
Posted on 2023-08-19 00:22 WebEnh 阅读(215) 评论(0) 编辑 收藏 举报微软的Edge 浏览器里的大声朗读里-“晓晓” 很接近自然人,比起其它平台的强很多。
在AZURE 可免费体验,每月限额50万字,每个语音转换不超过10分钟长度。
C# 调用:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Microsoft.CognitiveServices.Speech; //nuget 添加 using Microsoft.CognitiveServices.Speech.Audio; namespace MSTextSpeech { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); SynthesizeToSpeaker(); } async static Task SynthesizeToSpeaker() { //Find your key and resource region under the 'Keys and Endpoint' tab in your Speech resource in Azure Portal //Remember to delete the brackets <> when pasting your key and region! var reskey = "142736。。。。。。。。。。" ; //<paste-your-resource-key>" string regon = "southeastasia" ; //< paste-your-region> var config = SpeechConfig.FromSubscription(reskey , regon); config.SpeechSynthesisLanguage = "zh-CN" ; // e.g. "de-DE" // The voice setting will overwrite language setting. // The voice setting will not overwrite the voice element in input SSML. config.SpeechSynthesisVoiceName = "zh-CN-XiaoxiaoNeural" ; // "<your-wanted-voice>"; using var synthesizer = new SpeechSynthesizer(config); await synthesizer.SpeakTextAsync( "周二,这位18岁的女子在大型空中比赛中的金牌表现让她成为了全球关注的焦点,在中国引发了如此大的轰动,以至于社交媒体平台微博在兴趣的重压下崩溃了。但谷歌花了数年时间将自己打造成一名顶级运动员,同时也是一个对亚洲和西方品牌都有吸引力的高额模特。" ); } async void TestSaveMP3() { var reskey = "xxx2736axxxxxxx...." ; //<paste-your-resource-key>" string regon = "southeastasia" ; //< paste-your-region> var config = SpeechConfig.FromSubscription(reskey, regon); var path = AppDomain.CurrentDomain.BaseDirectory + "file.wav" ; using var audioConfig = AudioConfig.FromWavFileOutput(path); using var synthesizer = new SpeechSynthesizer(config, audioConfig); await synthesizer.SpeakTextAsync( "A simple test to write to a file." ); } private void Button_Click( object sender, RoutedEventArgs e) { TestSaveMP3(); } } } |
快速入门: https://docs.microsoft.com/zh-cn/azure/cognitive-services/speech-service/quickstarts/setup-platform?pivots=programming-language-csharp&tabs=browser%2Cdotnet%2Cwindows%2Cjre
本博客Android APP 下载 |
![]() |
支持我们就给我们点打赏 |
![]() |
支付宝打赏 支付宝扫一扫二维码 |
![]() |
微信打赏 微信扫一扫二维码 |
![]() |
如果想下次快速找到我,记得点下面的关注哦!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2017-08-19 分享一个Winform里面的HTML编辑控件Zeta HTML Edit Control,汉化附源码