C # has its own definition of the voice of the class speak, but many times we need to play their own recorded sound files, such as the use of C # sounder SoundPlayer, first need to put their own sound files in the bin directory debug, in this case the sound folder name is music, The name of the sound file under music is 0 to 9, as follows:
Specific code:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Media;usingSystem.IO;namespacemusic{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidForm1_Load (Objectsender, EventArgs e) { } PrivateSoundPlayer player;//Define a sounder stringZhuZhu = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//gets and sets the name of the directory that contains the application. Private voidSpeak_click (Objectsender, EventArgs e) { stringSound ="";//Sound is the name of the file for(inti =0; I <Ten; i++) { sound=i.tostring (); Player=NewSystem.Media.SoundPlayer (); Player. Soundlocation= ZhuZhu +"music\\"+ Sound +". wav";//Locate file LocationPlayer. LoadAsync ();//load A. wav file from a resourcePlayer. Playsync ();//play a. wav file } } }}
If you need to use the system's own sound to voice:
1. Add Reference: Using System.Speech.Synthesis;
2.SpeechSynthesizer speak = new SpeechSynthesizer (); Define a class for pronunciation
3. Speak. Speak ("What you want him to read");
How C # plays its own recorded sound basic usage of speak and SoundPlayer