Skip to content

bobbyreader/voice-input

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VoiceInput - 本地语音输入应用

基于本地 Ollama 的语音识别输入工具,在 Mac mini 上通过语音进行输入。

功能特性

  • 🎤 按住录音 - 通过菜单栏操作开始/停止录音
  • 🔊 本地识别 - 使用 whisper.cpp 本地语音识别,完全离线
  • 智能标点 - 自动添加标点符号
  • 📋 自动粘贴 - 自动将识别结果粘贴到焦点输入框
  • 🍎 macOS 原生 - 菜单栏应用,轻量高效

技术架构

┌─────────────────────────────────────────┐
│              菜单栏 UI (rumps)           │
└─────────────────┬───────────────────────┘
                  │
┌─────────────────▼───────────────────────┐
│           音频录制 (sox)                │
└─────────────────┬───────────────────────┘
                  │
┌─────────────────▼───────────────────────┐
│        语音识别 (whisper.cpp)         │
└─────────────────┬───────────────────────┘
                  │
┌─────────────────▼───────────────────────┐
│         标点优化 (简单规则)            │
└─────────────────┬───────────────────────┘
                  │
┌─────────────────▼───────────────────────┐
│        全局输入 (pyperclip + osascript) │
└─────────────────────────────────────────┘

系统要求

  • macOS
  • Python 3.11+
  • Ollama
  • sox (音频录制)
  • whisper.cpp 模型

安装

1. 克隆项目

cd ~/Projects
git clone <your-repo-url> voice-input
cd voice-input

2. 安装依赖

pip install -r requirements.txt
brew install sox

3. 下载 whisper 模型

mkdir -p ~/.voice-input/models
# 下载 medium 中文模型 (约 1.5GB)
curl -L -o ~/.voice-input/models/ggml-medium.bin \
  "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.bin"

4. 启动 Ollama

ollama serve

使用方法

启动应用

python3 main_menu.py

操作流程

  1. 点击菜单栏的 🎤 图标
  2. 选择 "🎤 开始录音"
  3. 对着麦克风说话
  4. 选择 "⏹ 停止录音"
  5. 自动识别并粘贴到当前焦点输入框

状态说明

图标 状态
🎤 就绪
🔴 录音中
⚙️ 识别中
📝 粘贴中
完成
错误

配置

配置文件位于 ~/.voice-input/config.yaml:

whisper_model: "medium"        # whisper 模型
ollama_host: "http://localhost:11434"
preview_timeout: 30            # 预览超时(秒)
audio_temp_dir: "~/.voice-input"

项目结构

voice-input/
├── main_menu.py          # 菜单栏版本(推荐)
├── main_simple.py         # 窗口版本
├── main.py               # 完整版(需要全局热键权限)
├── audio/
│   └── recorder.py       # 音频录制
├── recognition/
│   └── whisper_client.py # whisper.cpp 调用
├── nlp/
│   └── ollama_client.py  # 标点优化
├── input/
│   └── global_input.py   # 全局输入
├── ui/
│   ├── status_window.py  # 悬浮状态窗口
│   ├── preview_window.py # 预览确认窗口
│   └── ui_manager.py    # UI 管理器
└── utils/
    └── hotkey.py        # 全局快捷键

已知问题

  • 全局热键 Option+S 需要 macOS 辅助功能权限
  • 标点优化使用简单规则,大模型调用较慢

License

MIT

About

本地语音输入应用 - 基于 whisper.cpp 和 Ollama 的 macOS 语音识别工具

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages