无法通过mciSendString创建wave文件

时间:2014-03-18 14:27:30

标签: c# skype4com mcisendstring

我正在尝试捕获Skype电话并将其保存在带有wave扩展名的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调用。

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

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

2 个答案:

答案 0 :(得分:2)

如果命令字符串中的路径或文件名具有嵌入空格,则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

答案 1 :(得分:1)

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