Edge-TTS

Edge-TTS

Edge-TTS 是 Microsoft Edge 文本转语音 (TTS) 服务的 Swift 实现。该库提供了一个简单易用的 API 接口,允许开发者将高质量的文本转语音功能无缝集成到 Apple 平台应用程序中。

日本語ドキュメント | 中文文档 | 한국어 문서

特性

多种声音和语言

灵活的声音控制

丰富的输出选项

开发工具

跨平台兼容性

安装

Swift Package Manager

将以下依赖项添加到您的 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 工具提供两个主要命令:listspeak

列出可用声音

# 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 命令的可用选项

GUI 应用程序用法

  1. 下载并安装最新版本的 Edge TTS Demo
  2. 打开应用程序并输入要转换的文本
  3. 选择所需的声音和参数设置(语速、音调、音量)
  4. 如果需要,启用 JSON/SRT 导出
  5. 选择边界类型(句子或单词)
  6. 单击“转换并播放”按钮以收听合成语音
  7. 使用导出按钮保存文件
    • 在 iOS 上:使用系统共享表进行灵活的文件处理
    • 在 macOS 上:使用保存对话框选择保存位置

导出功能

文件类型

平台特定导出

常用声音

您可以使用以下命令获取支持的声音列表

let voices = try await tts.fetchVoices()

流行的英语声音包括

贡献

我们欢迎所有形式的贡献,包括但不限于

许可证

本项目根据 MIT 许可证授权 - 详情请参阅 LICENSE.txt 文件。