有没有关于从麦克风获取声音的库(c++、Win32、开源)的建议?
谢谢
PortAudio 提供了一个非常简单的 API,用于使用简单的回调函数录制和/或播放声音。
尝试查看 OpenAL[1] 可能有点过头了,但应该能够根据需要从麦克风录制。Gamedev.net[2] 上有一些非常好的文章,但恐怕没有一篇告诉你如何用麦克风录音。但是,您应该能够在文档中找到答案。:) 祝你好运,
[1] http://connect.creativelabs.com/openal/default.aspx
[2] http://www.gamedev.net/reference/articles/article2008.asp
我在CodeProject找到了一些代码(标准警告:请仔细检查您从 CodeProject 获取的每一段代码!它很有用,但我经常在我得到的示例中发现可怕的错误!)。这应该为您提供有关 API 以及如何开始使用它们的良好线索。从那里你可以谷歌参考和相关主题。
如果您不需要跨平台,DirectShow效果很好。虽然它不是开源的,但我相信您可以分发需要 DirectShow 库的开源项目。
你没有说你需要跨平台支持,如果不需要跨平台支持,我会使用 Wave API 或 DirectSound - 两者都相当简单易用。
我过去曾使用 mci 功能进行记录。抱歉,这并没有显示确保选择麦克风作为录音输入,但是一旦手动选择它,它将保持不变,除非有人更改它。这是在一个对话框中,所以这就是 Windows 句柄的来源。
#define ALIAS "mci_alias"
char mci_command[100];
char ReturnString[300];
int mci_error;
// open the device
sprintf(mci_command, "open new type waveaudio alias %s", ALIAS);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
// set the time format
sprintf(mci_command,"set %s time format ms", ALIAS); // just set time format
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
// start the record. specify notifications with a MM_MCINOTIFY message)
sprintf(mci_command, "record %s notify", ALIAS);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
// wait for a stop button, or an error to occur
sprintf(mci_command,"stop %s", ALIAS);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
// save the file
sprintf(mci_command, "save %s %s", ALIAS, m_filename);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
sprintf(mci_command,"stop %s", ALIAS);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);
// close the device
sprintf(mci_command,"close %s", ALIAS);
mci_err = mciSendString(mci_command, ReturnString, sizeof(ReturnString), m_hWnd);