Build a Voice-Enabled Documentation Reader
说明与用途
构建语音驱动的文档阅读器:从 GitHub 获取 Markdown,使用 ElevenLabs 合成语音,并通过 Flask 流式传输。
问题
Reading API docs and wikis drains eyes and time; need hands‑free listening while coding or commuting.
结果
A minimal, extensible voice‑enabled documentation reader that fetches markdown from GitHub, synthesizes it with ElevenLabs, and streams audio to the browser.
工作流
- 1. Obtain ElevenLabs API key via affiliate link and store in ELEVENLABS_API_KEY env variable.
- 2. Fetch markdown from a GitHub raw URL using requests.
- 3. Send markdown text to ElevenLabs /v1/text-to-speech endpoint with desired voice settings to receive MP3 bytes.
- 4. Run a Flask server exposing /read that fetches markdown, synthesizes audio, and returns it as an audio/mpeg response.
- 5. Serve a simple HTML page with an
<audio>element that fetches /read to play the audio.
证据
Reading through API docs, onboarding guides, or internal wikis is essential, but it can also be a drain on our eyes and time.
ElevenLabs ticks all these boxes. Their API delivers near‑human prosody and supports voice cloning with just a few seconds of sample audio.
export ELEVENLABS_API_KEY="sk_XXXXXXXXXXXXXXXXXXXXXXXX"
def fetch_markdown(): resp = requests.get(GITHUB_RAW_URL) resp.raise_for_status() return resp.text
def synthesize(text: str) -> bytes: ... return resp.content # MP3 bytes
@app.route("/read", methods=["GET"]) def read_doc(): markdown = fetch_markdown() audio_bytes = synthesize(markdown) return send_file(BytesIO(audio_bytes), mimetype="audio/mpeg", as_attachment=False, download_name="doc.mp3")
- 记录日期: 2026-10-05T21:41:08.978Z