【问题标题】:Not being able to create wave file through mciSendString无法通过 mciSendString 创建波形文件
【发布时间】:2014-03-18 14:27:30
【问题描述】:

我正在尝试捕获一个 Skype 通话并将其保存在我的 PC 中并使用波形扩展名,但每次我尝试 mciSendString 时它都无法创建声音文件。

这是我的代码

public void Skype_CallStatus(Call call, TCallStatus status)
{
    int result = 0;
     Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
    if (status == TCallStatus.clsInProgress)
    {
        mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
        mciSendString("record recsound", "", 0, 0);

    }
    //else if (status == TCallStatus.clsFinished)
    else if (status == TCallStatus.clsFinished)
    {
        DateTime currdate = DateTime.Now;
        //string datetime = currdate.Day + currdate.Month + currdate.Year + "_" + currdate.Hour + currdate.Minute + currdate.Second;
        string datetime = string.Format("{0:yyyyMMddhhmmss}.wav", DateTime.Now);

        string wavfilename = "";
        if (config.AppSettings.Settings["VoiceRecordsPath"].Value != null)
        {
            //wavfilename = config.AppSettings.Settings["VoiceRecordsPath"].Value.Replace(",","") + "_" + CSRBusiness.User.Country + "_" + datetime + @".wav";
            wavfilename = CSRBusiness.User.Country + "_" + datetime;
        }
        Directory.SetCurrentDirectory(config.AppSettings.Settings["VoiceRecordsPath"].Value.Replace(",", ""));

        result = mciSendString("save recsound " + wavfilename, "", 0, 0);
        //result = mciSendString("save recsound d://test.wav", "", 0, 0);
        mciSendString("close recsound ", "", 0, 0);
        MessageBox.Show(result.ToString());
    }
   // MessageBox.Show(result.ToString());
}

路径是我需要保存文件的地方:

C:\\Users\\tridip.BBAKOLKATA\\Documents\\Visual Studio 2010\\Projects\\CSRAssistant\\CSRAssistant\\bin\\Debug\\VoiceRecords

我的代码有什么错误?

但是当我在mciSendString 中硬编码路径和文件名时,就像result = mciSendString("save recsound d://test.wav", "", 0, 0); 一样,然后创建了一个文件,但是当我播放那个波形文件时,Skype 通话没有被记录。

我的路径规范有什么问题?

第二件事是,当生成波形文件时,没有录制声音。为什么?

【问题讨论】:

    标签: c# skype4com mcisendstring


    【解决方案1】:

    如果命令字符串中的路径或文件名包含空格,则 API 调用可能会失败。因此将路径包含在双引号中:

    result = mciSendString("save recsound \"" + wavfilename + "\"", "", 0, 0);
    

    或者,从 C# 6.0 开始:

    result = mciSendString($"save recsound \"{wavfilename}\"", "", 0, 0);
    

    见 KB191089 PRB: Multimedia API Calls May Fail with Long File Names

    【讨论】:

    • 好的会试试。你能告诉我为什么 mciSendString 不能捕获 Skype 对话吗?它只是捕捉到了我的声音,但其他人从另一端说的话却没有被捕捉到。
    • 如果路径很长,那么 mciSendString 会失败?
    • 如果您将其包含在引号中,则不会,如我在代码示例中所示。问题可能不是长度,而是嵌入的空间。 (长文件名通常包含空格)。
    【解决方案2】:

    在调用“save recsound”之前,您应该在所需路径创建文件夹“VoiceRecords”。

    【讨论】:

      猜你喜欢
      • 2021-10-01
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      • 2012-01-17
      • 1970-01-01
      • 1970-01-01
      • 2017-07-14
      • 1970-01-01
      相关资源
      最近更新 更多