English | 简体中文 | Get a gemini key
Transcribe audio to text with Google Gen AI. You can authenticate either with a Gemini API key or with a Vertex AI service account JSON. YouTube links are sent directly to Gemini without downloading the video first. Support direct video URL download with automatic proxy detection. Support Douyin short-link/share-text via Tiksave to fetch MP3 direct link and then transcribe. Default model is gemini-2.5-flash.
- Reference: Gemini video understanding
- Reference: Gemini media resolution
Tested in this project with YouTube (built-in --youtube, public videos only). Use in compliance with sites' ToS and local laws.
pip install -r requirements.txtIf you want to run the Telegram bot, create .env from .env.example and fill in:
cp .env.example .envOr install manually:
pip install google-genai
pip install google-auth
pip install yt-dlp
pip install requestsOptional: install ffmpeg for more robust audio extraction. Without it, the script falls back to the original audio format.
- Option A: Gemini API key
- Environment variable
GOOGLE_API_KEY(orGEMINI_API_KEY) - Windows CMD:
set GOOGLE_API_KEY=YOUR_KEY - PowerShell:
$env:GOOGLE_API_KEY="YOUR_KEY" - macOS/Linux:
export GOOGLE_API_KEY="YOUR_KEY"
- Environment variable
- Option B: Vertex AI service account JSON
- CLI:
--auth-mode vertex_ai_json --vertex-json /path/to/service-account.json --vertex-project YOUR_PROJECT --vertex-location us-central1 - Web UI: select
Vertex AI service account JSON, upload the JSON file, and fill project/location if needed - Environment fallback:
GOOGLE_APPLICATION_CREDENTIALSorVERTEX_SERVICE_ACCOUNT_FILE
- CLI:
--auth-modedefaults togemini_api_key
The program automatically uses proxy settings from system environment variables. Supported environment variables:
HTTP_PROXY/http_proxy: HTTP proxyHTTPS_PROXY/https_proxy: HTTPS proxy
You can also override system proxy settings via command line arguments:
python main.py --video-url URL --proxy http://127.0.0.1:7890-
Local audio:
python main.py --audio ./path/to/audio.m4a --lang en --api-key YOUR_KEY
-
Telegram bot:
python telegram_bot.py
- Required in
.env:ENV_BOT_TOKEN,ENV_BOT_SECRET - If you start
python fastapi/run.pywith the same.env, the FastAPI process will also start Telegram polling automatically - First use in Telegram: send
/start, enter the password, then use Telegram's left command menu to trigger/setauthand/setsource /setauthand/setsourceno longer show chat buttons; after triggering them, just reply withgemini/vertexoraudio/youtube/video_url/douyin- Gemini mode: use
/setkey <Gemini API Key>or trigger/setkeyfrom the left command menu - Vertex mode: use
/setvertexjson//setvertexproject//setvertexlocation, or trigger them from the left command menu - The bot persists each Telegram user's auth settings, model, prompt, and source type
- Transcript output is streamed in Telegram by incremental message updates, and the final
.txtfile is sent after completion
- Required in
-
YouTube (Gemini reads the public YouTube URL directly, no local download):
python main.py --youtube https://www.youtube.com/watch?v=VIDEO_ID --lang en --api-key YOUR_KEY -
Video direct link (auto download video, extract audio to
./dataand transcribe):python main.py --video-url https://example.com/video.mp4 --lang en --api-key YOUR_KEY
-
Douyin short link or share text (via Tiksave: extract MP3 direct link, download to
./dataand transcribe):python main.py --douyin "复制这条口令 https://v.douyin.com/xlaEmh_fVPg/ 打开Dou音..." --lang en --api-key YOUR_KEY- The program posts to
downcats.comwith your share text, parses returned HTML for the “Download MP3” link, downloads MP3 as./data/douyin_{TikTokId}.mp3(or timestamped if missing), then transcribes.
- The program posts to
-
Proxy:
python main.py --youtube URL --api-key YOUR_KEY --proxy http://127.0.0.1:7890
-
Model selection:
python main.py --audio ./a.mp3 --model gemini-2.5-flash --api-key YOUR_KEY python main.py --audio ./a.mp3 --auth-mode vertex_ai_json --vertex-json ./service-account.json --vertex-project YOUR_PROJECT
- Streams incremental transcript to stdout
- Saves the full text to a
.txtfile- Local audio: same basename as the input
- YouTube/Douyin:
./data/<basename>.txt
--audio,--youtube,--model,--lang,--out--proxy,--proxy-http,--proxy-https--auth-mode,--api-key--vertex-json,--vertex-project,--vertex-location- env vars:
GOOGLE_API_KEY/GEMINI_API_KEY,GOOGLE_APPLICATION_CREDENTIALS,VERTEX_SERVICE_ACCOUNT_FILE,VERTEX_PROJECT,VERTEX_LOCATION
- 本地音频转写(WAV/MP3/M4A 等常见格式)
- 直接通过 Gemini 读取 YouTube 链接并转写(仅支持公开视频,无需先下载)
- 视频直链下载和音频提取(自动使用系统代理)
- 抖音分享口令/短链通过 Tiksave 提取 MP3 直链后下载并转写
- 流式输出到标准输出,同时将完整文本保存为
.txt - 提供
--lang语言提示与--model模型选择 - 支持代理:
--proxy/--proxy-http/--proxy-https - 自动使用系统环境变量中的代理设置
- 当前已在本项目中亲测站点:
- YouTube(命令行内置
--youtube,通过 Gemini 直连转写)
- YouTube(命令行内置
请在遵守各网站服务条款与当地法律的前提下合规使用。
- 安装依赖(建议使用虚拟环境):
pip install -r requirements.txt或者手动安装:
pip install google-genai
pip install google-auth
pip install yt-dlp
pip install requests2)(可选)安装 ffmpeg:用于更稳定的音频提取与转码。未安装时,程序会自动回退为原始音频格式。
- 如需启用 Telegram 机器人,先复制环境变量示例并填写:
cp .env.example .env至少需要:
ENV_BOT_TOKEN: Telegram BotFather 创建的机器人 tokenENV_BOT_SECRET: 首次/start时用户需要输入的密码
- 方式一:Gemini API Key
- 设置环境变量
GOOGLE_API_KEY(或GEMINI_API_KEY) - Windows CMD:
set GOOGLE_API_KEY=你的密钥
- PowerShell:
$env:GOOGLE_API_KEY="你的密钥"
- macOS/Linux:
export GOOGLE_API_KEY="你的密钥"
- 设置环境变量
- 方式二:Vertex AI service account JSON
- 命令行:
python main.py --audio ./path/to/audio.m4a --auth-mode vertex_ai_json --vertex-json ./service-account.json --vertex-project YOUR_PROJECT --vertex-location us-central1
- Web UI:在“API 配置”里选择
Vertex AI service account JSON,上传 JSON 文件并填写项目/地域 - 环境变量兜底:
GOOGLE_APPLICATION_CREDENTIALS或VERTEX_SERVICE_ACCOUNT_FILE
- 命令行:
程序会自动使用系统环境变量中的代理设置,支持以下环境变量:
HTTP_PROXY/http_proxy: HTTP代理HTTPS_PROXY/https_proxy: HTTPS代理
设置示例:
- Windows CMD:
set HTTP_PROXY=http://127.0.0.1:7890 set HTTPS_PROXY=http://127.0.0.1:7890
- PowerShell:
$env:HTTP_PROXY="http://127.0.0.1:7890" $env:HTTPS_PROXY="http://127.0.0.1:7890"
- macOS/Linux:
export HTTP_PROXY="http://127.0.0.1:7890" export HTTPS_PROXY="http://127.0.0.1:7890"
也可以通过命令行参数覆盖系统代理设置:
python main.py --video-url URL --proxy http://127.0.0.1:7890-
本地音频转写:
python main.py --audio ./path/to/audio.m4a --lang zh --api-key YOUR_KEY python main.py --audio ./path/to/audio.m4a --auth-mode vertex_ai_json --vertex-json ./service-account.json --vertex-project YOUR_PROJECT
-
Telegram 机器人:
python telegram_bot.py
- 如果你是用
python fastapi/run.py启动 Web 服务,只要同一个.env里配置了ENV_BOT_TOKEN和ENV_BOT_SECRET,FastAPI 进程也会自动启动 Telegram polling - 首次使用:在 Telegram 中发送
/start,按提示先输入ENV_BOT_SECRET - 验证通过后,使用 Telegram 左下角命令菜单完成配置,不再显示常驻底部键盘
/setauth与/setsource不再弹按钮,触发后直接按提示回复参数即可- 常用命令包括
/settings、/setauth、/setkey、/setvertexjson、/setvertexproject、/setvertexlocation、/setmodel、/setsource、/setprompt、/resetprompt、/cancel - 也支持直接发送
/setauth gemini、/setsource audio这类带参数命令 - 机器人会按 Telegram 用户分别保存这些配置
- 转写过程会流式输出,完成后会附带
.txt文件
- 如果你是用
-
直接处理 YouTube 链接(通过 Gemini 直连转写,不先下载视频):
python main.py --youtube https://www.youtube.com/watch?v=VIDEO_ID --lang zh --api-key YOUR_KEY -
处理视频直链(自动下载视频,提取音频到
./data后转写):python main.py --video-url https://example.com/video.mp4 --lang zh --api-key YOUR_KEY
-
处理抖音分享口令或短链(通过 Tiksave 提取 MP3 直链,下载到
./data并转写):python main.py --douyin "0.25 aNJ:/ ... https://v.douyin.com/xlaEmh_fVPg/ 复制此链接,打开Dou音搜索,直接观看视频!" --lang zh --api-key YOUR_KEY- 程序会向
downcats.com提交你的分享文案/短链,解析返回的 HTML,提取“下载 MP3”按钮的直链,将音频保存为./data/douyin_{TikTokId}.mp3(若缺失则用时间戳),随后进行转写。
- 程序会向
-
使用代理(如本地 HTTP 代理 127.0.0.1:7890):
python main.py --youtube URL --api-key YOUR_KEY --proxy http://127.0.0.1:7890
-
指定模型:
python main.py --audio ./a.mp3 --model gemini-2.5-flash --api-key YOUR_KEY
- 转写时会将增量结果流式打印到标准输出
- 若使用
--out指定文件路径则保存到对应位置;未指定时:- 处理本地音频:保存为与音频同名的
.txt - 处理 YouTube/抖音:保存到
./data/同名.txt
- 处理本地音频:保存为与音频同名的
- 该功能依赖第三方服务 Tiksave 的可用性,若接口或页面结构变化,可能导致解析失败。
- 若访问 Tiksave 较慢或失败,请确认你的网络或代理设置是否可访问境外站点。
--audio: 本地音频文件路径--youtube: YouTube 视频链接(Gemini 直连转写,仅支持公开视频)--video-url: 视频直链URL(自动下载视频并提取音频)--douyin: 抖音分享口令或短链(自动解析并下载音频)--model: 模型名称(默认gemini-2.5-flash)--lang: 语言提示(如zh/en/ja)--out: 输出文本路径(可选)--media-resolution: YouTube 直连时传给 Gemini 的媒体分辨率,默认low--proxy/--proxy-http/--proxy-https: 代理设置--auth-mode:gemini_api_key或vertex_ai_json--api-key: Gemini API Key(或使用环境变量)--vertex-json: Vertex AI service account JSON 文件路径--vertex-project/--vertex-location: Vertex AI 认证参数