Microsoft Speech Platform case

Source: Internet
Author: User

In the previous blog, I talked about some knowledge points of Microsoft Speech Platform. This blog uses an example to illustrate how to use it.

The example is to read a piece of text. when the text is read, the text turns red. That's simple.

First look at the form layout.

650) this. width = 650; "title =" aa.png "src =" http://www.bkjia.com/uploads/allimg/131228/1606344338-0.png "/>

Implementation Code:

Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. threading. tasks; using System. windows. forms; using Microsoft. speech. synthesis; using System. threading; namespace SpeechPro {public partial class PlayForm: Form {public PlayForm () {InitializeComponent ();} /// <summary> /// TTS object /// </summary> Speech Synthesizer speech; /// <summary> /// separate the text content into an array /// </summary> /// <param name = "content"> text content </param> // /<returns> character array </returns> string [] GetArr (string content) {char [] charArr = new char [] {'. ','; '}; // Delimiter string [] arr = content. split (charArr, StringSplitOptions. removeEmptyEntries); // separate int sumcount = 0; // variable of the total number of characters for (int I = 0; I <arr. length; I ++) {sumcount + = arr [I]. length; // The total number of accumulated variables. arr [I] + = content. substring (sumcount, 1); // get the separator sumcount + = 1; // length of the punctuation} return arr;} string [] arr; /// <summary> /// playback content /// </summary> void Play () {arr = GetArr (Play_TB.Text); // design the TTS object, and set the object speech = new SpeechSynthesizer (); speech. setoutputtodefaauaudiodevice (); speech. volume = 100; speech. rate = 0; speech. speakStarted + = speech_SpeakStarted; // asynchronous speech reading for (int I = 0; I <arr. length; I ++) {PromptBuilder pb = new PromptBuilder (); pb. appendText (arr [I], PromptRate. medium); Prompt p = new Prompt (pb); speech. speakAsync (p) ;}} int index = 0; // read the index value int sum = 0; // read the total length /// <summary> /// read the current event from Prompt /// </summary> /// <param name = "sender"> </param >/// <param name = "e"> </param> void speech_SpeakStarted (object sender, speakStartedEventArgs e) {if (index> 0) {// restore the previous record to the original style Play_TB.Select (sum-arr [index-1]. length, arr [index-1]. length); Play_TB.SelectionColor = Color. black;} // set the style Play_TB.Select (sum, arr [index]. length); Play_TB.SelectionColor = Color. red; // Add length and read index sum + = arr [index]. length; index ++; this. text = "reading the sentence" + index + ";} /// <summary> /// read button /// </summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> private void Play_But_Click (object sender, eventArgs e) {Play ();}}}

 

This article is from "Gui Su Wei" blog, please be sure to keep this source http://axzxs.blog.51cto.com/730810/1247881

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.