使用 C#.net 的语音记录 (winmm.dll)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/838190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:36:08  来源:igfitidea点击:

voice record (winmm.dll) using C#.net

c#activex

提问by Muhammad Adnan

My requirement was to build an utility which could record voice (through mic) and save on disk .wav files as desktop and web app. for specific users so i chose activeX technology as i didn't find any other better way (may be you know and can guide me.. would be more than welcome)

我的要求是构建一个可以录制语音(通过麦克风)并将 .wav 文件保存在磁盘上的实用程序作为桌面和网络应用程序。对于特定用户,所以我选择了 activeX 技术,因为我没有找到任何其他更好的方法(也许你知道并可以指导我......会非常受欢迎)

I used winmm.dll (aka Media control interface (MCI)) and it is working perfectly fine but on specific computers like when i run it on vista, it works fine and on win server 2008 but on windows 2003 and xp it's not working .. just working is there any prereq.. which needs to be there or what i should do to make it work on other flavors of windows.

我使用了 winmm.dll(又名媒体控制接口 (MCI)),它运行良好,但在特定计算机上,例如我在 vista 上运行它时,它运行良好,在 win server 2008 上运行良好,但在 windows 2003 和 xp 上却无法运行。 . 只是工作是否有任何先决条件.. 需要在那里或我应该做些什么才能使其在其他风格的窗户上工作。

I don't mind in using DirectSound if some1 recommends with some sample code to record/save/play sample :)

如果 some1 建议使用一些示例代码来录制/保存/播放示例,我不介意使用 DirectSound :)

采纳答案by Jeff Youel

I would use DirectShow to capture the audio. Since you added a C# tag to the question, I recommend using the DirectShow.NET library. Make sure you also download the samplesand look at the PlayCap and CapWMV samples in the Capture folder. You may also want to checkout the Audio Capture articleat CodeProject.

我会使用 DirectShow 来捕获音频。由于您在问题中添加了 C# 标记,因此我建议使用DirectShow.NET 库。确保您还下载了示例并查看 Capture 文件夹中的 PlayCap 和 CapWMV 示例。您可能还想查看 CodeProject 上的音频捕获文章

As for why some OS versions are working, have you confirmed on those systems that the audio input works with other programs? Are you allowing the user to select an audio device or just using the default audio device? Are you getting an error message or just not audio? Per this forum, make sure you wrap your filename in double quotes.

至于为什么某些操作系统版本可以工作,您是否在这些系统上确认音频输入可以与其他程序一起使用?您是允许用户选择音频设备还是仅使用默认音频设备?您是否收到错误消息或只是没有音频?根据本论坛,请确保将文件名用双引号括起来。

回答by Muhammad Adnan

Actually no error, no exception and not even output wav files i am creating, whereas it works fine on vista and 2k8 but not prior versions.

实际上没有错误,没有例外,甚至没有输出我正在创建的 wav 文件,而它在 vista 和 2k8 上工作正常,但在以前的版本上却没有。

m using default sound card not setting any explicitly

m 使用默认声卡没有明确设置

using following code

使用以下代码

[DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);

to record

记录

mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
mciSendString("record recsound", "", 0, 0);

to stop and save

停止并保存

mciSendString(@"save recsound " + OuputFolderName + FileName + ".wav", "", 0, 0);
mciSendString("close recsound ", "", 0, 0);

回答by Padu Merloti

If you are still looking for a .net library, look here:

如果您仍在寻找 .net 库,请看这里:

http://windowsmedianet.sourceforge.net/index.html

http://windowsmedianet.sourceforge.net/index.html

and here

和这里

http://www.tapiex.com/ToneDecoder.Net.htm

http://www.tapiex.com/ToneDecoder.Net.htm

The first one is under LGPL licensing, the second one is a commercial component suite.

第一个是在 LGPL 许可下,第二个是商业组件套件。