C#怎么样向声卡传输一个指令,让它发出某些声音?比如钢琴键音?

解决方案 »

  1.   


    using System;
    using System.Runtime.InteropServices;
    namespace Beep
    {
        class Class1
        {
            [DllImport("kernel32.dll")]
            public static extern bool Beep(int frequency, int duration);
            static void Main(string[] args)
            {
                Random random = new Random();
                for (int i = 0; i < 10000; i++)
                {
                    Beep(random.Next(10000), 100);
                }
            }
        }
    }
      

  2.   

    Multimedia Functions
      

  3.   

    自己准备各种声音文件吧,估计windows也不会带这么多声音来给用户调用吧
      

  4.   

    [DllImport("winmm.dll",   SetLastError=true,   CallingConvention=CallingConvention.Winapi)]   
      public   static   extern   int   waveOutSetVolume(int   uDeviceID,   int   dwVolume);   
        
     [DllImport("winmm")]
        public static extern bool PlaySound(string szSound, IntPtr hMod, PlaySoundFlags flags);
    System.Media.SystemSounds.Asterisk.Play(); using Microsoft.DirectX;
    using Microsoft.DirectX.DirectSound;Microsoft speech object Library