C#WPF Voice Development Tutorial source code Download CSDN TTS (text to sound) step by step teach you to make voice software drawings and source code

Source: Internet
Author: User

C#WPF Voice Development Tutorials teach you how to make voice software in one step

Drawings and source code

Effect Show

A project preparation

1.vs2012 Development Platform

2. Microsoft's Voice software library

Download: http://download.csdn.net/detail/wyx100/8431269 (with instance project source code)

Two. Development Goals

Make a speech software, can read aloud text;

Multiple Voice libraries: male and female, support English and Chinese reading;

Support for selecting playback devices

Support Speech Speed selection

Support Volume selection

Three development process

1. New Wpfspeechdemo Project

File (vs Dev Platform upper left corner)----new (shortcut ctrl+shift+new)

2. Import Microsoft Voice Library

3. Create a software interface

See start Effect show

4. Software function Development

Support for voice library selection

Support for selecting playback devices

Support Speech Speed selection

Support Volume selection

Four software code

1. Interface code

<window x:class= "Wpfspeechdemo.mainwindow" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml" title= "Wpfspeechdemo" height= "width=" "525" > &L T grid> <combobox x:name= "cmbvoices" horizontalalignment= "left" margin= "86,23,0,0" verticalalignment= "Top" Wid Th= "222" selectionchanged= "cmbvoices_selectionchanged"/> <combobox x:name= "Cmbaudioout" HorizontalAlignment=        "Left" margin= "86,69,0,0" verticalalignment= "Top" width= "222" selectionchanged= "cmbaudioout_selectionchanged"/>        <label content= "Voice Library (Engine):" horizontalalignment= "left" margin= "0,23,0,0" verticalalignment= "Top" width= "Bayi"/>        <label content= "Voice output mode:" Horizontalalignment= "left" margin= "0,65,0,0" verticalalignment= "Top" width= "Bayi"/> <button content= "read aloud | Speek "horizontalalignment=" left "margin=" 33,119,0,0 "verticalalignment=" Top "width=" 104 "click=" Bt_speek_click "/     >   <button content= "Stop | Stop "horizontalalignment=" left "margin=" 170,119,0,0 "verticalalignment=" Top "width=" "rendertransformorigin=" 2.042,0.064 "click=" Bt_stop_click "/> <textbox name=" Tbspeech "horizontalalignment=" left "Height=" a "Margin = "20,172,0,0" textwrapping= "Wrap" verticalalignment= "Top" width= "484" borderthickness= "3" text= "WPF voice, hello world!  "> <TextBox.BorderBrush> <lineargradientbrush endpoint=" 0,20 "mappingmode=" Absolute " Startpoint= "0,0" > <gradientstop color= "#FFABADB3" offset= "0.05"/> <grad                Ientstop color= "#FFE2E3EA" offset= "0.07"/> <gradientstop color= "#FF1A72C9" offset= "1"/> </LinearGradientBrush> </TextBox.BorderBrush> </TextBox> <slider x: Name= "Tbarrate" orientation= "Vertical" minimum= "0" maximum= "ten" Ismovetopoi Ntenabled= "True"                autotooltipprecision= "2" autotooltipplacement= "BottomRight" tickplacement= "BottomRight" Ticks= "1, 2, 3, 4, 5, 6, 7, 8, 9,10" isselectionrangeenabled= "true" Selectionst art= "1" selectionend= "9" horizontalalignment= "left" margin= "357,51,0,0" verticalalignment= "Top" height= "10 3 "valuechanged=" tbarrate_valuechanged "background=" #FFEFEBF0 "/> <slider x:name=" Trbvolume "Orientation=" Vert                ical "minimum=" 0 "maximum=" ismovetopointenabled= "True"                autotooltipprecision= "2" autotooltipplacement= "BottomRight" tickplacement= "BottomRight" Ticks= "1, 2, 3, 4, 5, 6, 7, 8, 9,10" isselectionrangeenabled= "true" Selectionsta rt= "1" selectionend= "9" horizontalalignment= "left" margin= "426,51,0,0" verticalalignment= "Top" height= "103 "Valuechanged=" TrbvolumE_valuechanged "background=" #FFF2EFF3 "/> <label content=" Speed "horizontalalignment=" left "margin=" 350,19,0,0 "V Erticalalignment= "Top" width= "/> <label content=" volume "horizontalalignment=" left "margin=" 418,19,0,0 "Verti Calalignment= "Top" width= "/>" </Grid></Window>

2. Function code

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 Dotnetspeech;//cs file introduced in library namespace WpfSpeechDemo{//        <summary>//MainWindow.xaml interactive logic///</summary> public partial class Mainwindow:window {        SpVoice speech = new SpVoice ();        int speechrate = 0;        int volume = 70;            Public MainWindow () {InitializeComponent ();        Init (); } private void Init () {//Initialize speech engine list foreach (Ispeechobjecttoken Token in speech. Getvoices (String. Empty, String.            Empty) {CmbVoices.Items.Add (Token.getdescription (49));   }//Get audio output list         foreach (Ispeechobjecttoken audioout in speech. Getaudiooutputs (String. Empty, String.            Empty) {CmbAudioOut.Items.Add (Audioout.getdescription (49));            } cmbvoices.selectedindex = 0;            Cmbaudioout.selectedindex = 0;            Tbarrate.value = speechrate;        Trbvolume.value = volume; The private void Tbarrate_scroll (object sender, EventArgs e) {speech.        rate = (int) tbarrate.value; The private void Trbvolume_scroll (object sender, EventArgs e) {speech.        Volume = (int) trbvolume.value; The private void Cmbvoices_selectionchanged (object sender, SelectionChangedEventArgs e) {speech. Voice = speech. Getvoices (String. Empty, String. Empty).        Item (Cmbvoices.selectedindex); The private void Cmbaudioout_selectionchanged (object sender, SelectionChangedEventArgs e) {speech. Audiooutput = speech. Getaudiooutputs (String. EmpTy, String. Empty).        Item (Cmbaudioout.selectedindex); } private void Bt_speek_click (object sender, EventArgs e) {//terminates the previous read aloud if there is a speech.            Speak ("", Speechvoicespeakflags.svsflagsasync); Speech. Speak (Tbspeech.        Text, Speechvoicespeakflags.svsflagsasync); The private void Bt_stop_click (object sender, EventArgs e) {speech.        Speak ("", Speechvoicespeakflags.svsflagsasync);            private void Tbarrate_valuechanged (object sender, Routedpropertychangedeventargs<double> e) { Speech.        rate = (int) e.newvalue;            private void Trbvolume_valuechanged (object sender, Routedpropertychangedeventargs<double> e) { Speech.        Volume = (int) e.newvalue; }    }}
Five compile and run

C#WPF Voice Development Tutorial source code Download CSDN TTS (text to sound) step by step teach you to make voice software drawings and source code

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.