Edge-TTS is a Swift implementation of Microsoft Edge's Text-to-Speech (TTS) service. This library provides a simple and easy-to-use API interface that allows developers to seamlessly integrate high-quality text-to-speech functionality into Apple platform applications.
Edge-TTS is a Swift implementation of Microsoft Edge’s Text-to-Speech (TTS) service. This library provides a simple and easy-to-use API interface that allows developers to seamlessly integrate high-quality text-to-speech functionality into Apple platform applications.
Add the following dependency to your Package.swift file:
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)")
}
}
The CLI tool provides two main commands: list
and 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
Available options for speak
command:
--text
: Text to speak--file
: Input text file path--voice
: Voice to use (default: en-US-JennyNeural)--lang
: Language to use (default: en-US)--rate
: Speech rate (e.g. +0%, -10%)--pitch
: Speech pitch (e.g. +0Hz, -10Hz)--volume
: Speech volume (e.g. +0%, -10%)--boundary
: Boundary type (sentence or word, default: sentence)--save-json
: Save timing info as JSON--save-srt
: Save timing info as SRT--proxy
: Proxy URL (e.g. http://host:port)--output
: Output file name (default: output.mp3)You can get the list of supported voices using:
let voices = try await tts.fetchVoices()
Popular English voices include:
We welcome all forms of contributions, including but not limited to:
This project is licensed under the MIT License - see the LICENSE.txt file for details.