How C # plays its own recorded sound basic usage of speak and SoundPlayer

Source: Internet
Author: User

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

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.