用于录制麦克风的免费 C++ lib (Win32) [关闭]
-
06-07-2019 - |
题
有没有推荐的库(c++、Win32、开源)来从麦克风获取声音?
谢谢
解决方案
试着看看OpenAL [1]它可能有些过分,但应该可以根据需要从麦克风录制。在Gamedev.net [2]上有一些关于它的相当不错的文章,虽然我担心它们都不会告诉你如何用麦克风录音。但是,您应该能够在文档中找到答案。祝你好运,
[1] http://connect.creativelabs.com/openal/default.aspx
[2] http://www.gamedev.net/reference/articles/ article2008.asp
其他提示
PortAudio提供了一个非常简单的API 用于录制和/或播放声音 使用简单的回调函数。
我在 CodeProject 上找到了一些代码(标准警告:请仔细检查你从CodeProject获取的每一段代码!它很有用,但我经常在样本中找到可怕的错误!)。这应该为您提供关于API以及如何开始使用它们的良好线索。从那里你可以谷歌参考和相关主题。
- WaveInOpen - 这是一个打开波形输入设备的函数。
- WaveInPrepareHeader - 使用此函数准备记录缓冲区。
- WaveInAddBuffer - 添加要记录的缓冲区。
- WaveStart-用于开始录制。
- WaveInClose - 关闭波形输入设备。
如果您不需要跨平台,请 DirectShow 运作良好。虽然它不是开源的,但我相信您可以分发需要DirectShow库的开源项目。
您没有说您需要跨平台支持,如果不需要跨平台支持,我会使用wave API或DirectSound - 两者都非常直接使用。
我过去曾使用mci函数进行记录。 抱歉,这并未显示确保麦克风被选为录制输入,但一旦手动选择,它将保留,除非有人更改它。这是在一个对话框中,因此窗口处理来自。
#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);
不隶属于 StackOverflow