将文本转换为语音文件,支持中文和多语言朗读
使用 Python 将文本转换为语音音频文件。
生成一条 python -c '...' 命令,使用系统自带 TTS 或 edge-tts 生成语音。
Windows 自带 SAPI 语音引擎,无需安装额外依赖:
python -c "
import subprocess,os,tempfile
text='要朗读的文本内容'
output=os.path.join(tempfile.gettempdir(),'tts_output.wav')
ps_script=f'''
Add-Type -AssemblyName System.Speech
\$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
\$synth.SetOutputToWaveFile(\"{output}\")
\$synth.Speak(\"{text}\")
\$synth.Dispose()
'''
subprocess.run(['powershell','-Command',ps_script],capture_output=True,timeout=30)
if os.path.exists(output):
size=os.path.getsize(output)
print(f'✅ 语音文件已生成: {output} ({size} bytes)')
else:
print('❌ 生成失败')
"
需要先安装 edge-tts: pip install edge-tts
python -c "
import asyncio,tempfile,os
async def tts():
import edge_tts
text='要朗读的中文文本'
voice='zh-CN-XiaoxiaoNeural'
output=os.path.join(tempfile.gettempdir(),'tts_output.mp3')
communicate=edge_tts.Communicate(text,voice)
await communicate.save(output)
size=os.path.getsize(output)
print(f'✅ 语音已生成: {output} ({size} bytes)')
print(f'语音: {voice}')
asyncio.run(tts())
"
| 语音名称 | 说明 | |----------|------| | zh-CN-XiaoxiaoNeural | 晓晓(女声,推荐) | | zh-CN-YunxiNeural | 云希(男声,推荐) | | zh-CN-YunyangNeural | 云扬(男声,新闻播报风格) | | zh-CN-XiaoyiNeural | 晓依(女声,温柔) | | zh-CN-YunjianNeural | 云健(男声,运动解说风格) | | zh-TW-HsiaoChenNeural | 曉臻(台湾女声) | | zh-TW-YunJheNeural | 雲哲(台湾男声) |
python -c "
import asyncio
async def list_voices():
import edge_tts
voices=await edge_tts.list_voices()
zh=[v for v in voices if v['Locale'].startswith('zh')]
print('可用中文语音:\n')
for v in zh:
print(f' {v[\"ShortName\"]:30} {v[\"Gender\"]:8} {v[\"Locale\"]}')
asyncio.run(list_voices())
"
pip install edge-tts 安装Generate or edit images via Gemini 3 Pro Image (Nano Banana Pro).
Batch-generate images via OpenAI Images API. Random prompt sampler + `index.html` gallery.
Generate spectrograms and feature-panel visualizations from audio with the songsee CLI.
Extract frames or short clips from videos using ffmpeg.
Search GIF providers with CLI/TUI, download results, and extract stills/sheets.
Category:media-generate