Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Voice broadcast function in C #

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to achieve voice broadcasting function in C#". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "how to achieve voice broadcasting function in C#" can help you solve the problem.

Environment:

Window10

Vs2019 16.5.5

.netframework4.5

I. on voice broadcasting

The function of voice broadcasting belongs to the operating system. Both win7 and win10 come with it. Some win7 castrated systems do not have this feature, which will cause an error when running:

Failed to retrieve the component with CLSID {D9F6EE60-58C9-458B-88E1-2F908FD7F87C} in the COM class factory because of the following error: 80040154 does not register the class (the exception comes from HRESULT:0x80040154 (REGDB_E_CLASSNOTREG)).

To check whether your computer supports voice broadcasting, please refer to the following:

II. C # Code

Directly create a new console program and add a System.Speech.dll reference:

The code is as follows:

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 ("enter text:"); string str = Console.ReadLine () Try {if (string.IsNullOrEmpty (str)) {speech.Speak ("Please enter text");} else {speech.Speak (str) }} catch (Exception ex) {Console.WriteLine ($"error: {ex?.Message}");} Console.WriteLine ("ok"); Console.ReadLine ();}

After running, put on your headphones and check the results:

This is the end of the content about "how to achieve voice broadcasting function in C#". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report