A microphone recording DLL library based on Windows Core Audio API (WASAPI).
- Real-time microphone audio capture
- Output format: Mono, 16kHz, 16-bit PCM
- C-style exported functions for easy integration with other languages
- Recording controls: Start, Pause, Resume, Stop
- Thread-safe audio data buffering
- Windows 10 or later
- Visual Studio 2022 (or any version supporting v143 platform toolset)
- Windows SDK 10.0
- Clone the repository:
git clone https://github.com/jingitong/MicRecorder.git
cd MicRecorder-
Open the solution in Visual Studio:
- Double-click the
MicRecorder.slnfile
- Double-click the
-
Select build configuration:
- Platform:
x64orx86 - Configuration:
DebugorRelease
- Platform:
-
Build the project:
- Menu:
Build->Build Solution - Or press
Ctrl+Shift+B
- Menu:
-
After successful build, the DLL file will be located at:
x64/Release/MicRecorder.dll(Release x64)x64/Debug/MicRecorder.dll(Debug x64)
// Initialize the recorder
int InitializeMicRecorder();
// Start recording
void StartMicRecording();
// Pause recording
void PauseMicRecording();
// Resume recording
void ResumeMicRecording();
// Stop recording
void StopMicRecording();
// Get audio data
int GetMicAudioData(short* buffer, int bufferSize);
// Cleanup resources
void CleanupMicRecorder();The project includes a Python test script test.py demonstrating how to use the DLL:
# Place MicRecorder.dll and test.py in the same directory
python test.pyAfter running:
- Recording starts automatically
- Press
Sorsto stop recording - The recording will be saved as
recorded.wav
#include "MicRecorder.h"
int main() {
// Initialize
if (InitializeMicRecorder() != 0) {
return -1;
}
// Start recording
StartMicRecording();
// Get audio data
short buffer[1024];
int samples = GetMicAudioData(buffer, 1024);
// Stop recording
StopMicRecording();
// Cleanup
CleanupMicRecorder();
return 0;
}- Sample Rate: 16000 Hz
- Channels: 1 (Mono)
- Bit Depth: 16 bit
- Format: PCM
This project is licensed under the MIT License.
Issues and Pull Requests are welcome!
jingitong
一个基于 Windows Core Audio API (WASAPI) 的麦克风录音 DLL 库。
- 实时麦克风音频捕获
- 输出格式:单声道、16kHz、16位 PCM
- 提供 C 风格导出函数,方便其他语言调用
- 支持录音控制:开始、暂停、恢复、停止
- 线程安全的音频数据缓冲
- Windows 10 或更高版本
- Visual Studio 2022(或支持 v143 平台工具集的版本)
- Windows SDK 10.0
- 克隆仓库:
git clone https://github.com/jingitong/MicRecorder.git
cd MicRecorder-
使用 Visual Studio 打开解决方案:
- 双击
MicRecorder.sln文件
- 双击
-
选择编译配置:
- 平台:
x64或x86 - 配置:
Debug或Release
- 平台:
-
编译项目:
- 菜单:
生成->生成解决方案 - 或按快捷键
Ctrl+Shift+B
- 菜单:
-
编译成功后,DLL 文件位于:
x64/Release/MicRecorder.dll(Release x64)x64/Debug/MicRecorder.dll(Debug x64)
// 初始化录音器
int InitializeMicRecorder();
// 开始录音
void StartMicRecording();
// 暂停录音
void PauseMicRecording();
// 恢复录音
void ResumeMicRecording();
// 停止录音
void StopMicRecording();
// 获取音频数据
int GetMicAudioData(short* buffer, int bufferSize);
// 清理资源
void CleanupMicRecorder();项目包含一个 Python 测试脚本 test.py,演示如何使用 DLL:
# 将 MicRecorder.dll 和 test.py 放在同一目录
python test.py运行后:
- 录音自动开始
- 按
S或s停止录音 - 录音将保存为
recorded.wav文件
#include "MicRecorder.h"
int main() {
// 初始化
if (InitializeMicRecorder() != 0) {
return -1;
}
// 开始录音
StartMicRecording();
// 获取音频数据
short buffer[1024];
int samples = GetMicAudioData(buffer, 1024);
// 停止录音
StopMicRecording();
// 清理
CleanupMicRecorder();
return 0;
}- 采样率: 16000 Hz
- 声道数: 1 (单声道)
- 位深度: 16 bit
- 格式: PCM
本项目采用 MIT 许可证。
欢迎提交 Issue 和 Pull Request!
jingitong