In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 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 text-to-voice 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 text-to-voice function in C#" can help you solve the problem.
The advantage of this approach is that it will not be restricted by browsers. In js's text-to-voice function, Google's higher version of the browser will block automatic playback through simulated clicks, while ie will not.
one。 Confirm the R & D environment
Operating system: win10 or win7 (I use win10 myself. It is said that some castrated versions of win7 will report errors)
IDE:VS2012 (can be higher than this version)
.net framework 4.0 (can be higher than this version)
two。 The system has its own speech recognition function
1.There is Speech under the C:\ Windows folder
two。 Voice recognition on the control panel
III. DLL reference
1. Right-click the program you want to use this feature and select "add reference"
two。 Select "Assembly"-- System.Speech under "frame"
four。 Code
It is important to note that:
1. The page needs to be set to asynchronous
two。 Call through the principal-agent way to prevent the page from becoming unresponsive
3. The page code is as follows:
Aspx:
Text to speech test
Aspx.cs:
Using System;using System.Collections.Generic;using System.Globalization;using System.Linq;using System.Speech.Synthesis;using System.Threading.Tasks;using System.Web;using System.Web.UI;using System.Web.UI.WebControls; public partial class yy: System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {} / text to voice / voice content delegate void MyDelegate (string content) String content = "if there is a new order, please process it in time"; SpeechSynthesizer synthesizer = new SpeechSynthesizer (); / / Click the start button / / start reading private void speakParagh (string text) {synthesizer.Speak (text);} / / release the resource private void Completed (IAsyncResult result) {synthesizer.SpeakAsyncCancelAll () after reading. } protected void Button1_Click (object sender, EventArgs e) {try {MyDelegate myDelegate = new MyDelegate (speakParagh); / / Asynchronous call delegate myDelegate.BeginInvoke (content, new AsyncCallback (Completed), null) / / after starting the asynchronous thread, the main thread can continue to work without waiting for} catch (Exception ex) {Console.WriteLine ("error:" + ex.Message);} this is the end of the introduction about "how to realize the text-to-voice 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.