Highlight and speak text from your Obsidian notes. Converts text to audio using lifelike voices from OpenAI.
tts-interaction-audio.mp4
Just add your OpenAI API key. Choose from 6 voices. OpenAI charges Audio at $0.015 per 1,000 characters. That's around $12 for the ~800,000 character text of A Tale of Two Cities.
Visual Feedback: Active sentence is highlighted and updated as playback progresses.
Listen immediately: Audio is streamed sentence-by-sentence. Jump back and forth by skipping by sentence.
Variable Speeds: On device playback rate adjustor for improved audio quality.
Caching: Audio is cached in your vault to reduce costs, and automatically removed. Cache duration is configurable. Audio may be cached device local or in a vault directory.
<img src="docs/cache-settings.png" width"400" >
Export and Embed Audio: Quickly export to audio files: export audio files from selection, or embed audio by pasting text from your clipboard.
Play text from anywhere: Lots of commands. Play text to speech directly from your clipboard.
OS Integration: Integrates with your mobile phone to play while locked. Pause/Play with OS controls on desktop.
You can also run alternate models if you have OpenAI compatible API server that has an /v1/audio/speech endpoint. For example openedai-speech. Just configure the url in the plugin settings
为了帮助开发者快速熟悉项目代码,以下是项目的主要结构和模块说明:
-
obsidian/ - Obsidian 插件集成层
TTSPlugin.ts- 插件主入口文件,负责初始化插件和注册各种功能ObsidianBridge.ts- 连接 Obsidian 编辑器和音频播放系统的桥梁ObsidianPlayer.ts- Obsidian 特定的音频缓存实现StreamingPlayer.ts- 流式音频播放器实现
-
player/ - 核心音频播放和管理模块
AudioStore.ts- 音频存储和管理核心类AudioSystem.ts- 音频系统协调器ActiveAudioText.ts- 活动音频文本的管理和控制AudioTextChunk.ts- 音频文本块的定义和处理ChunkPlayer.ts- 音频块播放器,负责逐块加载和播放音频ChunkLoader.ts- 音频块加载器TTSModel.ts- TTS 模型接口和实现AudioSink.ts- 音频输出接口AudioCache.ts- 音频缓存管理CancellablePromise.ts- 可取消的 Promise 实现
-
components/ - React 用户界面组件
PlayerView.tsx- 主播放器界面TTSPluginSettingsTab.tsx- 插件设置界面AudioVisualizer.tsx- 音频可视化组件IsPlaying.tsx- 播放状态指示器IconButton.tsx- 图标按钮组件DownloadProgress.tsx- 下载进度显示组件
-
codemirror/ - CodeMirror 编辑器集成
TTSCodemirror.ts- 在 Obsidian 编辑器中高亮当前播放文本的扩展
-
util/ - 工具函数库
cleanMarkdown.ts- 清理 Markdown 格式splitSentences.ts- 文本分割为句子misc.ts- 杂项工具函数Minhash.ts- 文本哈希算法
-
web/ - Web 相关功能
IndexedDBAudioStorage.ts- 基于 IndexedDB 的音频存储实现app.tsx- Web 应用界面
-
types/ - TypeScript 类型定义
- 包含项目中使用的各种类型定义
- 用户在 Obsidian 中选择文本并触发播放
- [TTSPlugin] 接收到指令,通过 [ObsidianBridge] 获取选中的文本
- [AudioStore] 创建 [ActiveAudioText] 对象,将文本分割成多个 [AudioTextChunk]
- [ChunkPlayer]负责按需加载和播放音频块
- [TTSModel] 调用 OpenAI 或兼容 API 生成音频
- 音频通过 [AudioSink]输出到浏览器音频系统
CodeMirror扩展在编辑器中高亮当前播放的文本- 用户界面组件显示播放状态和控制选项
- 克隆项目并安装依赖:
npm install - 构建项目:
npm run build - 在 Obsidian 中加载插件进行测试
- 修改代码后需要重新构建才能看到效果
插件支持多种配置选项:
- TTS 模型选择(OpenAI 或兼容 API)
- 音色选择
- 文本分割方式
- 播放速度控制
- 缓存策略(本地或 vault 存储)
- 缓存时长设置



