TTSManager
is a Swift package designed to simplify Text-to-Speech (TTS) functionality across Apple platforms using AVFoundation
. This package supports iOS, macOS, tvOS, and watchOS, offering a clean and flexible API for managing voices, speech rates, and utterances.
- 🔄 Dynamically filter voices by language.
- 🎙 Set and customize the speaking rate and voice.
- 📚 Simple API for managing Text-to-Speech.
- ❌ Error handling for missing voices.
- ✅ Supports iOS, macOS, tvOS, and watchOS.
- iOS: 13.0+
- macOS: 10.15+
- tvOS: 13.0+
- watchOS: 6.0+
To integrate TTSManager
into your project, use Swift Package Manager:
- Open your project in Xcode.
- Go to File > Add Packages.
- Enter the repository URL for
TTSManager
:https://github.com/deg2800/TTSManager.git
- Select the latest version and add the package.
Alternatively, download the source files and include them in your project.
Import TTSManager
into your Swift file:
import TTSManager
Create a TTSController
instance with a specified language and default rate:
let ttsController = TTSController(for: "es", with: 0.5) // Spanish language, rate of 0.5
Speak a string using the default voice and rate:
try? ttsController.speak(text: "Hola, ¿cómo estás?")
Speak with a specific voice and custom rate:
let customVoice = AVSpeechSynthesisVoice(identifier: "com.apple.ttsbundle.Monica-compact")
try? ttsController.speak(text: "Hola, ¿cómo estás?", with: customVoice, at: 0.4)
Set the current voice:
let newVoice = ttsController._availableVoices.first
ttsController.setVoice(newVoice)
Update the available voices for a specific language:
ttsController.setLanguage("en") // Switch to English voices
- TTSManager: The main library target providing TTS functionality.
- Swift 5.0+
AVFoundation
Framework
Contributions are welcome! Feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.