Skip to content

jingitong/MicRecorder

Repository files navigation

MicRecorder

English | 中文


English

A microphone recording DLL library based on Windows Core Audio API (WASAPI).

Features

  • 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

System Requirements

  • Windows 10 or later
  • Visual Studio 2022 (or any version supporting v143 platform toolset)
  • Windows SDK 10.0

Build Instructions

  1. Clone the repository:
git clone https://github.com/jingitong/MicRecorder.git
cd MicRecorder
  1. Open the solution in Visual Studio:

    • Double-click the MicRecorder.sln file
  2. Select build configuration:

    • Platform: x64 or x86
    • Configuration: Debug or Release
  3. Build the project:

    • Menu: Build -> Build Solution
    • Or press Ctrl+Shift+B
  4. After successful build, the DLL file will be located at:

    • x64/Release/MicRecorder.dll (Release x64)
    • x64/Debug/MicRecorder.dll (Debug x64)

Usage

API Functions

// 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();

Python Example

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.py

After running:

  • Recording starts automatically
  • Press S or s to stop recording
  • The recording will be saved as recorded.wav

C/C++ Example

#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;
}

Audio Format

  • Sample Rate: 16000 Hz
  • Channels: 1 (Mono)
  • Bit Depth: 16 bit
  • Format: PCM

License

This project is licensed under the MIT License.

Contributing

Issues and Pull Requests are welcome!

Author

jingitong


中文

一个基于 Windows Core Audio API (WASAPI) 的麦克风录音 DLL 库。

功能特性

  • 实时麦克风音频捕获
  • 输出格式:单声道、16kHz、16位 PCM
  • 提供 C 风格导出函数,方便其他语言调用
  • 支持录音控制:开始、暂停、恢复、停止
  • 线程安全的音频数据缓冲

系统要求

  • Windows 10 或更高版本
  • Visual Studio 2022(或支持 v143 平台工具集的版本)
  • Windows SDK 10.0

编译步骤

  1. 克隆仓库:
git clone https://github.com/jingitong/MicRecorder.git
cd MicRecorder
  1. 使用 Visual Studio 打开解决方案:

    • 双击 MicRecorder.sln 文件
  2. 选择编译配置:

    • 平台:x64x86
    • 配置:DebugRelease
  3. 编译项目:

    • 菜单:生成 -> 生成解决方案
    • 或按快捷键 Ctrl+Shift+B
  4. 编译成功后,DLL 文件位于:

    • x64/Release/MicRecorder.dll (Release x64)
    • x64/Debug/MicRecorder.dll (Debug x64)

使用方法

API 函数

// 初始化录音器
int InitializeMicRecorder();

// 开始录音
void StartMicRecording();

// 暂停录音
void PauseMicRecording();

// 恢复录音
void ResumeMicRecording();

// 停止录音
void StopMicRecording();

// 获取音频数据
int GetMicAudioData(short* buffer, int bufferSize);

// 清理资源
void CleanupMicRecorder();

Python 示例

项目包含一个 Python 测试脚本 test.py,演示如何使用 DLL:

# 将 MicRecorder.dll 和 test.py 放在同一目录
python test.py

运行后:

  • 录音自动开始
  • Ss 停止录音
  • 录音将保存为 recorded.wav 文件

C/C++ 示例

#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

About

采集声卡

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published