用于在Windows上捕获声音的API
API for capturing sound on Windows
我需要一个c++ API来枚举输入设备并捕获Windows Vista, Windows 7和Windows 8的声音。如果没有通用的API,我可以为不同版本的Windows使用特定于操作系统的API。
我在微软网站上找到了一些参考资料,但我不知道该选什么。你有什么建议吗?
对于waveIn API使用waveInGetNumDevs()和waveInGetDevCaps()。对于核心音频API使用IMMDeviceEnumerator。对于DirectShow,请阅读:http://msdn.microsoft.com/en-us/library/windows/desktop/dd377566(v=vs.85).aspx
这完全取决于架构的其余部分。你必须对捕获的PCM做些什么你可能知道该怎么做。这应该有助于你决定使用什么技术。
看一下BASS库
:
- 跨平台;
- 有据可查的,
- 有很大的支持;
- 易于使用;
- 有很多插件;
- 免费供非商业用途。
获取当前存在的记录设备总数:
int a, count=0;
BASS_DEVICEINFO info;
for (a=0; BASS_RecordGetDeviceInfo(a, &info); a++)
if (info.flags&BASS_DEVICE_ENABLED) // device is enabled
count++; // count it
以44100hz 16位立体声开始录音:
FILE *file;
...
// the recording callback
BOOL CALLBACK MyRecordingWriter(HRECORD handle, void *buf, DWORD len, void *user)
{
fwrite(buf, 1, len, file); // write the buffer to the file
return TRUE; // continue recording
}
...
HRECORD record=BASS_RecordStart(44100, 2, 0, MyRecordingWriter, 0); // start recording
下面的代码使用winapi录制声音并将其保存为。wav文件
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <Mmsystem.h>
#define ALIAS "random_str"
int main(int argc,char *argv[])
{
printf("|-----------------------|n"
"|Simple Winapi Recorder |n"
"|By @systheron |n"
"|-----------------------|n");
char mci_command[100];
char ReturnString[300];
int mci_error;
sprintf(mci_command, "open new type waveaudio alias %s", ALIAS);
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
// set the time format
sprintf(mci_command,"set %s time format ms", ALIAS); // just set time format
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
// start recording
sprintf(mci_command, "record %s notify", ALIAS);
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
printf("Now recording, get key input to stop...n");
char c= getc(stdin);
//stop recording
sprintf(mci_command,"stop %s", ALIAS);
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
// save the file
sprintf(mci_command, "save %s %s", ALIAS, "random.wav");
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
// close the device
sprintf(mci_command,"close %s", ALIAS);
mci_error = mciSendString(mci_command, ReturnString, sizeof(ReturnString), NULL);
printf("Recording stopped. Congrat, your file is save as: random.wav. n");
return 0;
}
使用g++:
g++ index.cpp -o index.exe -lWinmm
注意:使用-lWinmm手动链接Mmsystem.h
相关文章:
- 用于访问容器<T>数据成员的正确 API
- 如何使用Luacneneneba API正确读取字符串和表参数
- C++MySQL C api用户输入行
- 如何使用 AWS Transcribe C++ API 中的'StartTranscriptionJobRequest'?
- 将std::string传递给WriteConsole API
- Xaudio2在更改缓冲区或循环时弹出声音
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 在gtest.中使用fff.h模拟系统API
- 有没有任务栏API可以立即应用注册表更改
- C++win32 API创建多个类似视口的窗口
- 如何更改'a'声音?
- 使用libcurl提交批量url的正确BING Api POST url是什么
- 如何将真正的字符串从python c-api转换为python脚本
- 如何使用 ALSA API 在应用程序中在单声道和立体声之间切换声音输出?
- C/C++声音操作系统API
- 跨平台声音 API
- 如何使用 WaveOutwaveIn API 录制和播放声音
- 简单的C++声音API
- 用于在Windows上捕获声音的API
- 将波形加载到内存中,然后使用Win32 API异步播放声音