C#实现语音播报功能
作者:jackletter 时间:2023-06-26 20:35:26
本文实例为大家分享了C#实现语音播报功能的具体代码,供大家参考,具体内容如下
环境:
window10
vs2019 16.5.5
.netframework4.5
一、关于语音播报
语音播报的功能属于操作系统自带的。win7和win10都自带,部分win7 * 版系统没有这项功能会导致运行报错:
检索 COM 类工厂中 CLSID 为 {D9F6EE60-58C9-458B-88E1-2F908FD7F87C} 的组件失败,原因是出现以下错误: 80040154 没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))。
查看自己电脑是否支持语音播报功能,可以参考如下:
二、C#代码
直接新建个控制台程序,添加System.Speech.dll引用:
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp9
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer speech = new SpeechSynthesizer();
Console.Write("请输入文字:");
string str = Console.ReadLine();
try
{
if (string.IsNullOrEmpty(str))
{
speech.Speak("请输入文字");
}
else
{
speech.Speak(str);
}
}
catch (Exception ex)
{
Console.WriteLine($"报错:{ex?.Message}");
}
Console.WriteLine("ok");
Console.ReadLine();
}
}
}
运行后,带好耳机,查看效果:
来源:https://blog.csdn.net/u010476739/article/details/106192826
标签:C#,语音播报
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
springboot 正确的在异步线程中使用request的示例代码
2023-11-24 22:36:13
![](https://img.aspxhome.com/file/2023/6/59386_0s.jpg)
Java非法字符: ‘\\ufeff‘问题及说明
2023-02-01 09:06:07
![](https://img.aspxhome.com/file/2023/3/83033_0s.png)
Java中常用时间的一些相关方法
2022-02-06 11:33:38
HashMap红黑树入门(实现一个简单的红黑树)
2022-10-18 13:52:35
![](https://img.aspxhome.com/file/2023/2/79292_0s.png)
SpringBoot2.0解决Long型数据转换成json格式时丢失精度问题
2022-10-31 16:56:24
![](https://img.aspxhome.com/file/2023/1/61521_0s.png)
C#跨PC远程调用程序并显示UI界面
2022-06-22 13:42:38
C#实现Base64处理的加密解密,编码解码示例
2023-07-15 12:11:31
SpringBoot上传临时文件被删除引起报错的解决
2022-05-28 23:46:24
![](https://img.aspxhome.com/file/2023/6/74886_0s.jpg)
Spring Boot Gradle发布war到tomcat的方法示例
2021-09-24 11:36:57
![](https://img.aspxhome.com/file/2023/3/90023_0s.png)
Java 8 中 Map 骚操作之 merge() 的使用方法
2022-03-31 01:19:27
maven报错:Failed to execute goal on project问题及解决
2021-09-30 09:58:36
![](https://img.aspxhome.com/file/2023/7/122197_0s.png)
C#计算字符串相似性的方法
2022-08-18 11:32:15
Android简单实现启动画面的方法
2022-08-25 17:54:55
APK程序获取system权限的方法
2023-09-05 06:41:49
基于Spring的RPC通讯模型的使用与比较
2022-04-22 01:18:18
![](https://img.aspxhome.com/file/2023/5/94325_0s.png)
C#调用CMD命令实例
2021-06-17 10:08:12
Android实现记事本功能(26)
2023-02-17 22:30:23
![](https://img.aspxhome.com/file/2023/0/137780_0s.png)
解决@Transactional注解事务不回滚不起作用的问题
2022-10-29 09:18:51
Android实现仿通讯录侧边栏滑动SiderBar效果代码
2021-08-03 21:07:45
![](https://img.aspxhome.com/file/2023/6/118966_0s.png)
详谈springboot过滤器和拦截器的实现及区别
2022-07-22 04:44:24