English | 简体中文 | Get a gemini key
Transcribe audio to text with Google Generative AI (Gemini). Optionally fetch audio from video sites via yt-dlp and then transcribe. 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:
yt-dlpREADME - Supported sites:
yt-dlpSupported Sites
Tested in this project with YouTube (built-in --youtube) and Bilibili (download via yt-dlp first, then pass --audio). Use in compliance with sites' ToS and local laws.
pip install -r requirements.txtOr install manually:
pip install google-generativeai
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: 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"
- Windows CMD:
- Option B:
--api-key YOUR_KEYCLI flag
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
-
YouTube (auto download to
./dataand transcribe, In theory, all websites in the yt-dlp list support):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
https://tiksave.io/api/ajaxSearchwith your share text, parses returned HTML for the “Download MP3” link (e.g.https://dl.snapcdn.app/get?...), 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
- 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--api-key(or env varGOOGLE_API_KEY/GEMINI_API_KEY)
- 本地音频转写(WAV/MP3/M4A 等常见格式)
- 一键下载 YouTube 音频并转写(需
yt-dlp,可选安装ffmpeg以获得更高质量/更好兼容的音频) - 视频直链下载和音频提取(自动使用系统代理)
- 抖音分享口令/短链通过 Tiksave 提取 MP3 直链后下载并转写
- 流式输出到标准输出,同时将完整文本保存为
.txt - 提供
--lang语言提示与--model模型选择 - 支持代理:
--proxy/--proxy-http/--proxy-https - 自动使用系统环境变量中的代理设置
- 完整站点列表请见:
yt-dlp的支持网站页面 - 当前已在本项目中亲测站点:
- YouTube(命令行内置
--youtube直连下载与转写) - Bilibili(通过
yt-dlp先下载音频,再使用--audio转写)
- YouTube(命令行内置
请在遵守各网站服务条款与当地法律的前提下合规使用。
- 安装依赖(建议使用虚拟环境):
pip install -r requirements.txt或者手动安装:
pip install google-generativeai
pip install yt-dlp
pip install requests2)(可选)安装 ffmpeg:用于更稳定的音频提取与转码。未安装时,程序会自动回退为原始音频格式。
- 方式一(推荐):设置环境变量
GOOGLE_API_KEY(或GEMINI_API_KEY)- Windows CMD:
set GOOGLE_API_KEY=你的密钥
- PowerShell:
$env:GOOGLE_API_KEY="你的密钥"
- macOS/Linux:
export GOOGLE_API_KEY="你的密钥"
- Windows CMD:
- 方式二:运行时通过
--api-key参数传入
程序会自动使用系统环境变量中的代理设置,支持以下环境变量:
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
-
直接处理 YouTube 链接(自动下载到
./data后转写,理论上 yt-dlp 列表内的网站都支持):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- 程序会向
https://tiksave.io/api/ajaxSearch提交你的分享文案/短链,解析返回的 HTML,提取“下载 MP3”按钮的直链(如https://dl.snapcdn.app/get?...),将音频保存为./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 视频链接(自动下载音频)--video-url: 视频直链URL(自动下载视频并提取音频)--douyin: 抖音分享口令或短链(自动解析并下载音频)--model: 模型名称(默认gemini-2.5-flash)--lang: 语言提示(如zh/en/ja)--out: 输出文本路径(可选)--proxy/--proxy-http/--proxy-https: 代理设置--api-key: 直接传入 API Key(或使用环境变量)