【代码片段】播放声音

using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using System.Runtime.InteropServices;
using System.Speech.Synthesis;
using System.Text;

namespace QuickEAS.CoreLib
{
    public class LibSoundPlayer
    {
        public static void PlayWav(string fileName)
        {
            SoundPlayer player = new SoundPlayer();
            player.SoundLocation = fileName;
            player.Load(); //同步加载声音  
            player.Play(); //启用新线程播放  
            //player.PlayLooping(); //循环播放模式  
            //player.PlaySync(); //UI线程同步播放  
        }
        /// <summary>朗读播放文本</summary>
        /// <param name="text"></param>
        public static void PlayText(string text)
        {
            SpeechSynthesizer synth = new SpeechSynthesizer();
            synth.SpeakAsync(text);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/michelsn/article/details/80297893
今日推荐