Edge-TTS 是 Microsoft Edge 文本转语音 (TTS) 服务的 Swift 实现。该库提供了一个简单易用的 API 接口,允许开发者将高质量的文本转语音功能无缝集成到 Apple 平台应用程序中。
将以下依赖项添加到您的 Package.swift 文件中
dependencies: [
.package(url: "https://github.com/brewusinc/edge-tts.git", from: "1.0.0")
]
import EdgeTTS
// Create TTS instance
let tts = EdgeTTS(config: Configure(
voice: "en-US-JennyNeural",
rate: "+0%",
pitch: "+0Hz",
volume: "+0%",
saveJSON: true, // Enable JSON metadata export
saveSRT: true, // Enable SRT subtitle export
boundaryType: .sentence // Use sentence boundary (.word for word boundary)
))
// Async conversion
Task {
do {
try await tts.ttsPromise(text: "Hello, World!", audioPath: "output.mp3")
print("Conversion completed")
} catch {
print("Conversion failed: \(error)")
}
}
CLI 工具提供两个主要命令:list
和 speak
。
# List all available voices
edge-tts-cli list
# List voices with proxy
edge-tts-cli list --proxy http://host:port
# Basic usage with text
edge-tts-cli speak --text "Hello, World!" --output hello.mp3
# Read text from file
edge-tts-cli speak --file input.txt --output hello.mp3
# Specify voice and language
edge-tts-cli speak --text "Hello, World!" --voice en-US-JennyNeural --lang en-US --output hello.mp3
# Adjust speech parameters
edge-tts-cli speak --text "Hello, World!" --rate +50% --pitch +10Hz --volume +20% --output hello.mp3
# Enable JSON and SRT export
edge-tts-cli speak --text "Hello, World!" --save-json --save-srt --output hello.mp3
# Set boundary type
edge-tts-cli speak --text "Hello, World!" --boundary word --output hello.mp3
# Use proxy
edge-tts-cli speak --text "Hello, World!" --proxy http://host:port --output hello.mp3
speak
命令的可用选项
--text
: 要说的文本--file
: 输入文本文件路径--voice
: 要使用的声音(默认:en-US-JennyNeural)--lang
: 要使用的语言(默认:en-US)--rate
: 语速(例如,+0%,-10%)--pitch
: 音调(例如,+0Hz,-10Hz)--volume
: 音量(例如,+0%,-10%)--boundary
: 边界类型(句子或单词,默认:句子)--save-json
: 将时间信息保存为 JSON--save-srt
: 将时间信息保存为 SRT--proxy
: 代理 URL(例如,http://host:port)--output
: 输出文件名(默认:output.mp3)您可以使用以下命令获取支持的声音列表
let voices = try await tts.fetchVoices()
流行的英语声音包括
我们欢迎所有形式的贡献,包括但不限于
本项目根据 MIT 许可证授权 - 详情请参阅 LICENSE.txt 文件。