Communitygithub.com

graniet/kheish

OpenAI 的通用語音辨識模型,支援 99 種語言,提供轉錄、翻譯為英文、語言識別等功能。適用於語音轉文字、播客轉錄或多語言音訊處理。

kheish 是什麼?

這個技能整合了 OpenAI 的 Whisper 語音辨識模型,提供強大的多語言自動語音辨識 (ASR) 功能。Whisper 支援 99 種語言的轉錄、將音訊翻譯為英文,以及語言識別。共有六種模型大小可供選擇,從 tiny (3900 萬參數) 到 large (15.5 億參數),以及最新的 turbo 模型,能在速度與品質之間取得最佳平衡。Kheish 技能主要與 GitHub 上的 graniet/kheish 儲存庫相關,作為一個可整合的開發工具。建議在需要高品質、多語言語音轉文字應用的場景中使用,例如播客轉錄、會議記錄自動化、以及多語言音訊處理。但若需即時串流、說話者分離或雲端 API 管理等進階功能,則應考慮 AssemblyAI、Deepgram 或 Google Speech-to-Text 等替代方案。

相容平台~Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/graniet/kheish/tree/HEAD/skills/mlops/models/whisper

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Kheish 相容性

此技能為儲存庫本地 (repo-local) 使用,需明確啟用才會生效。

當原始指令提到舊版工具名稱時,請使用以下 Kheish 對應:

  • terminal => bash
  • web_extract => web_fetch,加上 web_search (需要探索時)
  • search_files => grep_search 和 glob_search
  • browser_* 工具需要一個支援瀏覽器的工具或 MCP;如果沒有,請使用最接近的可用工具並明確說明

當指令提到本地輔助檔案時,請從 ${KHEISH_SKILL_DIR} 解析它們的路徑。

Whisper - 穩健的語音辨識

OpenAI 的多語言語音辨識模型。

何時使用 Whisper

使用時機:

  • 語音轉文字轉錄 (99 種語言)
  • 播客/影片轉錄
  • 會議記錄自動化
  • 翻譯為英文
  • 雜訊音訊轉錄
  • 多語言音訊處理

指標:

  • 72,900+ GitHub 星數
  • 支援 99 種語言
  • 使用 680,000 小時音訊訓練
  • MIT 授權

替代方案(當這些更適合時使用):

  • AssemblyAI:托管 API,支援說話者分離
  • Deepgram:即時串流 ASR
  • Google Speech-to-Text:雲端解決方案

快速開始

安裝

# 需要 Python 3.8-3.11
pip install -U openai-whisper

# 需要 ffmpeg
# macOS: brew install ffmpeg
# Ubuntu: sudo apt install ffmpeg
# Windows: choco install ffmpeg

基本轉錄

import whisper

# 載入模型
model = whisper.load_model("base")

# 轉錄
result = model.transcribe("audio.mp3")

# 列印文字
print(result["text"])

# 存取片段
for segment in result["segments"]:
    print(f"[{segment['start']:.2f}s - {segment['end']:.2f}s] {segment['text']}")

模型大小

# 可用的模型
models = ["tiny", "base", "small", "medium", "large", "turbo"]

# 載入特定模型
model = whisper.load_model("turbo")  # 最快,品質良好
模型參數量僅英文多語言速度VRAM
tiny39M✓✓~32x~1 GB
base74M✓✓~16x~1 GB
small244M✓✓~6x~2 GB
medium769M✓✓~2x~5 GB
large1550M✗✓1x~10 GB
turbo809M✗✓~8x~6 GB

建議:使用 turbo 獲得最佳速度/品質,使用 base 進行原型開發

轉錄選項

語言指定

# 自動偵測語言
result = model.transcribe("audio.mp3")

# 指定語言(更快)
result = model.transcribe("audio.mp3", language="en")

# 支援:en, es, fr, de, it, pt, ru, ja, ko, zh, 以及另外 89 種語言

任務選擇

# 轉錄(預設)
result = model.transcribe("audio.mp3", task="transcribe")

# 翻譯為英文
result = model.transcribe("spanish.mp3", task="translate")
# 輸入:西班牙文音訊 → 輸出:英文文字

初始提示

# 透過上下文提升準確度
result = model.transcribe(
    "audio.mp3",
    initial_prompt="這是一個關於機器學習和AI的技術性播客。"
)

# 有助於:
# - 技術術語
# - 專有名詞
# - 特定領域詞彙

時間戳記

# 字詞層級時間戳記
result = model.transcribe("audio.mp3", word_timestamps=True)

for segment in result["segments"]:
    for word in segment["words"]:
        print(f"{word['word']} ({word['start']:.2f}s - {word['end']:.2f}s)")

溫度回退

# 如果信心度低,使用不同溫度重試
result = model.transcribe(
    "audio.mp3",
    temperature=(0.0, 0.2, 0.4, 0.6, 0.8, 1.0)
)

命令列使用

# 基本轉錄
whisper audio.mp3

# 指定模型
whisper audio.mp3 --model turbo

# 輸出格式
whisper audio.mp3 --output_format txt     # 純文字
whisper audio.mp3 --output_format srt     # 字幕
whisper audio.mp3 --output_format vtt     # WebVTT
whisper audio.mp3 --output_format json    # JSON 格式(含時間戳記)

# 語言
whisper audio.mp3 --language Spanish

# 翻譯
whisper spanish.mp3 --task translate

批次處理

import os

audio_files = ["file1.mp3", "file2.mp3", "file3.mp3"]

for audio_file in audio_files:
    print(f"正在轉錄 {audio_file}...")
    result = model.transcribe(audio_file)

    # 儲存到檔案
    output_file = audio_file.replace(".mp3", ".txt")
    with open(output_file, "w") as f:
        f.write(result["text"])

即時轉錄

# 對於串流音訊,請使用 faster-whisper
# pip install faster-whisper

from faster_whisper import WhisperModel

model = WhisperModel("base", device="cuda", compute_type="float16")

# 使用串流方式轉錄
segments, info = model.transcribe("audio.mp3", beam_size=5)

for segment in segments:
    print(f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}")

GPU 加速

import whisper

# 自動使用 GPU(如果可用)
model = whisper.load_model("turbo")

# 強制使用 CPU
model = whisper.load_model("turbo", device="cpu")

# 強制使用 GPU
model = whisper.load_model("turbo", device="cuda")

# 使用 GPU 可快 10-20 倍

與其他工具整合

字幕生成

# 生成 SRT 字幕
whisper video.mp4 --output_format srt --language English

# 輸出:video.srt

與 LangChain 整合

from langchain.document_loaders import WhisperTranscriptionLoader

loader = WhisperTranscriptionLoader(file_path="audio.mp3")
docs = loader.load()

# 在 RAG 中使用轉錄結果
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings

vectorstore = Chroma.from_documents(docs, OpenAIEmbeddings())

從影片中擷取音訊

# 使用 ffmpeg 擷取音訊
ffmpeg -i video.mp4 -vn -acodec pcm_s16le audio.wav

# 然後進行轉錄
whisper audio.wav

最佳實踐

  1. 使用 turbo 模型 - 英文的最佳速度/品質
  2. 指定語言 - 比自動偵測更快
  3. 添加初始提示 - 改善技術術語的準確度
  4. 使用 GPU - 可快 10-20 倍
  5. 批次處理 - 效率更高
  6. 轉換為 WAV 格式 - 相容性更好
  7. 分割長音訊 - 每個區塊小於 30 分鐘
  8. 檢查語言支援 - 不同語言的品質有所差異
  9. 使用 faster-whisper - 比 openai-whisper 快 4 倍
  10. 監控 VRAM - 根據硬體調整模型大小

效能

模型即時係數 (CPU)即時係數 (GPU)
tiny~0.32~0.01
base~0.16~0.01
turbo~0.08~0.01
large~1.0~0.05

即時係數:0.1 表示比即時快 10 倍

語言支援

最支援的語言:

  • 英文 (en)
  • 西班牙文 (es)
  • 法文 (fr)
  • 德文 (de)
  • 義大利文 (it)
  • 葡萄牙文 (pt)
  • 俄文 (ru)
  • 日文 (ja)
  • 韓文 (ko)
  • 中文 (zh)

完整列表:總共 99 種語言

限制

  1. 幻覺 - 可能重複或發明文字
  2. 長篇幅準確度 - 超過 30 分鐘的音訊效果會下降
  3. 說話者識別 - 不支援說話者分離
  4. 口音 - 品質會因口音而異
  5. 背景噪音 - 可能影響準確度
  6. 即時延遲 - 不適合即時字幕

資源

相關技能