Skip to content

Commit 4ddd805

Browse files
committed
docs(README): add Usage and Installation
* Fix #1
1 parent 332f385 commit 4ddd805

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
11
# SwiftTTSCombine
22

33
A very straightforward Combine wrapper around TTS part of AVFoundation/AVSpeechSynthesizer to allow you using Text to Speech with ease.
4+
5+
## Usage
6+
7+
You can instantiate/inject `TTSEngine` object, it has this behavior
8+
9+
* `func speak(string: String)`: call this method when you simply want to use the TTS with a simple String
10+
* subscribe to `isSpeakingPublisher` to know when the utterance starts to be heard, and when it's stopped
11+
* subscribe to `speakingProgressPublisher` to know the progress, from 0 to 1
12+
* `var rateRatio: Float`: set the rate to slow down or accelerate the TTS engine
13+
* `var voice: AVSpeechSynthesisVoice?`: set the voice of the TTS engine, by default, it's the voice for `en-GB`
14+
15+
Example
16+
17+
```swift
18+
import Combine
19+
import SwiftTTSCombine
20+
21+
let engine: TTSEngine = SwiftTTSCombine.Engine()
22+
var cancellables = Set<AnyCancellable>()
23+
24+
engine.speak(string: "Hello World!")
25+
26+
engine.isSpeakingPublisher
27+
.sink { isSpeaking in
28+
print("TTS is currently \(isSpeaking ? "speaking" : "not speaking")")
29+
}
30+
.store(in: &cancellables)
31+
32+
engine.speakingProgressPublisher
33+
.sink { progress in
34+
print("Progress: \(Int(progress * 100))%")
35+
}
36+
.store(in: &cancellables)
37+
38+
engine.rateRatio = 3/4
39+
40+
engine.speak(string: "Hello World! But slower")
41+
```
42+
43+
## Installation
44+
45+
### Xcode
46+
47+
You can add SwiftTTSCombine to an Xcode project by adding it as a package dependency.
48+
49+
1. From the **File** menu, select **Swift Packages › Add Package Dependency...**
50+
2. Enter "https://github.com/renaudjenny/SwiftTTSCombine" into the package repository URL test field
51+
52+
### As package dependency
53+
54+
Edit your `Package.swift` to add this library.
55+
56+
```swift
57+
let package = Package(
58+
...
59+
dependencies: [
60+
.package(url: "https://github.com/renaudjenny/SwiftTTSCombine", from: "1.0.0"),
61+
...
62+
],
63+
targets: [
64+
.target(
65+
name: "<Your project name>",
66+
dependencies: ["SwiftTTSCombine"]),
67+
...
68+
]
69+
)
70+
```
71+
72+
## App using this library
73+
74+
* [📲 Tell Time UK](https://apps.apple.com/gb/app/tell-time-uk/id1496541173): https://github.com/renaudjenny/telltime

0 commit comments

Comments
 (0)