【问题标题】:how fix Failed to open wav device LumiSoft.Net?如何修复无法打开 wav 设备 LumiSoft.Net?
【发布时间】:2013-01-20 01:15:06
【问题描述】:

我将此代码用于打开 wave 设备,并得到“无法打开 wave 设备”的异常。当我重置计算机时,它没有给出异常,我第一次运行该程序就可以了,但之后每次运行以异常结束。

public WaveOut(WavOutDevice outputDevice,int samplesPerSec,int bitsPerSample,int channels)
        {
            if(outputDevice == null){
                throw new ArgumentNullException("outputDevice");
            }
            if(samplesPerSec < 8000){
                throw new ArgumentException("Argument 'samplesPerSec' value must be >= 8000.");
            }
            if(bitsPerSample < 8){
                throw new ArgumentException("Argument 'bitsPerSample' value must be >= 8.");
            }
            if(channels < 1){
                throw new ArgumentException("Argument 'channels' value must be >= 1.");
            }

            m_pOutDevice    = outputDevice;
            m_SamplesPerSec = samplesPerSec;
            m_BitsPerSample = bitsPerSample;
            m_Channels      = channels;
            m_BlockSize     = m_Channels * (m_BitsPerSample / 8);
            m_pPlayItems    = new List<PlayItem>();

            // Try to open wav device.            
            WAVEFORMATEX format = new WAVEFORMATEX();
            format.wFormatTag      = WavFormat.PCM;
            format.nChannels       = (ushort)m_Channels;
            format.nSamplesPerSec  = (uint)samplesPerSec;                        
            format.nAvgBytesPerSec = (uint)(m_SamplesPerSec * m_Channels * (m_BitsPerSample / 8));
            format.nBlockAlign     = (ushort)m_BlockSize;
            format.wBitsPerSample  = (ushort)m_BitsPerSample;
            format.cbSize          = 0; 
            // We must delegate reference, otherwise GC will collect it.
            m_pWaveOutProc = new waveOutProc(this.OnWaveOutProc);
            int result = WavMethods.waveOutOpen(out m_pWavDevHandle,m_pOutDevice.Index,format,m_pWaveOutProc,0,WavConstants.CALLBACK_FUNCTION);



            if(result != MMSYSERR.NOERROR){
                throw new Exception("Failed to open wav device, error: " + result.ToString() + ".");
            }
        }

【问题讨论】:

    标签: c# .net voice lumisoft


    【解决方案1】:

    虽然我对 c# 中的 wav 设备几乎没有经验,但我认为您的问题与程序关闭时未关闭设备有关。

    你需要这样的电话

    WavMethods.waveOutClose(m_pWavDevHandle);
    

    在您的应用程序退出之前的某个地方(如果 waveOutoOpen 调用失败,显然不需要它)

    【讨论】:

      猜你喜欢
      • 2019-09-17
      • 2014-12-31
      • 2021-11-15
      • 2014-06-18
      • 1970-01-01
      • 2019-10-07
      • 2014-08-04
      • 2019-12-18
      相关资源
      最近更新 更多