@capacitor-community/text-to-speech 0.2.3 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorCommunityTextToSpeech.podspec +1 -1
- package/LICENSE +1 -1
- package/README.md +169 -113
- package/android/build.gradle +14 -8
- package/android/src/main/AndroidManifest.xml +3 -5
- package/android/src/main/java/com/getcapacitor/community/tts/SpeakResultCallback.java +6 -0
- package/android/src/main/java/com/getcapacitor/community/tts/TextToSpeech.java +98 -180
- package/android/src/main/java/com/getcapacitor/community/tts/TextToSpeechPlugin.java +130 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +194 -0
- package/dist/esm/definitions.d.ts +70 -17
- package/dist/esm/definitions.js +1 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +9 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +7 -9
- package/dist/esm/web.js +48 -76
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +57 -75
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +59 -75
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Info.plist +1 -1
- package/ios/Plugin/TextToSpeech.swift +81 -0
- package/ios/Plugin/{Plugin.h → TextToSpeechPlugin.h} +0 -0
- package/ios/Plugin/{Plugin.m → TextToSpeechPlugin.m} +2 -3
- package/ios/Plugin/TextToSpeechPlugin.swift +64 -0
- package/package.json +36 -21
- package/CHANGELOG.md +0 -46
- package/android/src/main/java/com/getcapacitor/community/tts/Constant.java +0 -8
- package/android/src/main/res/layout/bridge_layout_main.xml +0 -15
- package/android/src/main/res/values/colors.xml +0 -3
- package/android/src/main/res/values/strings.xml +0 -3
- package/android/src/main/res/values/styles.xml +0 -3
- package/ios/Plugin/Plugin.swift +0 -119
package/ios/Plugin/Plugin.swift
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import AVFoundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
|
|
4
|
-
@objc(TextToSpeech)
|
|
5
|
-
public class TextToSpeech: CAPPlugin, AVSpeechSynthesizerDelegate {
|
|
6
|
-
|
|
7
|
-
var ttsSynthesizer: AVSpeechSynthesizer?
|
|
8
|
-
var hasInitialized: Bool = false
|
|
9
|
-
var supportedLangs: [String] = Array(AVSpeechSynthesisVoice.speechVoices().map{
|
|
10
|
-
return $0.language
|
|
11
|
-
})
|
|
12
|
-
var ttsUtterance: AVSpeechUtterance?
|
|
13
|
-
|
|
14
|
-
public func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) {
|
|
15
|
-
do {
|
|
16
|
-
try AVAudioSession.sharedInstance().setActive(false)
|
|
17
|
-
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.ambient)
|
|
18
|
-
try AVAudioSession.sharedInstance().setActive(true)
|
|
19
|
-
} catch {}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public override func load() {
|
|
23
|
-
if (!self.hasInitialized) {
|
|
24
|
-
self.ttsSynthesizer = AVSpeechSynthesizer()
|
|
25
|
-
self.ttsSynthesizer?.delegate = self
|
|
26
|
-
self.hasInitialized = true
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@objc func speak(_ call: CAPPluginCall) {
|
|
31
|
-
let text = call.getString("text") ?? ""
|
|
32
|
-
let locale = call.getString("locale") ?? "en-US"
|
|
33
|
-
let speechRate = call.getFloat("speechRate") ?? 1.0
|
|
34
|
-
let pitchRate = call.getFloat("pitchRate") ?? 1.0
|
|
35
|
-
let category = call.getString("category") ?? "ambient"
|
|
36
|
-
let volume = call.getFloat("volume") ?? 1.0
|
|
37
|
-
|
|
38
|
-
var avAudioSessionCategory = AVAudioSession.Category.ambient
|
|
39
|
-
if category != "ambient" {
|
|
40
|
-
avAudioSessionCategory = AVAudioSession.Category.playback
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
do {
|
|
44
|
-
try AVAudioSession.sharedInstance().setActive(false)
|
|
45
|
-
try AVAudioSession.sharedInstance().setCategory(avAudioSessionCategory, mode:.default, options: AVAudioSession.CategoryOptions.duckOthers)
|
|
46
|
-
try AVAudioSession.sharedInstance().setActive(true)
|
|
47
|
-
} catch {
|
|
48
|
-
call.reject(error.localizedDescription)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
self.ttsSynthesizer?.stopSpeaking(at: .immediate)
|
|
52
|
-
|
|
53
|
-
self.ttsUtterance = type(of: AVSpeechUtterance()).init(string: text)
|
|
54
|
-
self.ttsUtterance?.voice = AVSpeechSynthesisVoice(language: locale)
|
|
55
|
-
self.ttsUtterance?.rate = adjustRate(speechRate);
|
|
56
|
-
self.ttsUtterance?.pitchMultiplier = pitchRate
|
|
57
|
-
self.ttsUtterance?.volume = volume
|
|
58
|
-
self.ttsSynthesizer?.speak(self.ttsUtterance!)
|
|
59
|
-
|
|
60
|
-
call.success()
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@objc func stop(_ call: CAPPluginCall) {
|
|
64
|
-
if self.ttsSynthesizer != nil {
|
|
65
|
-
self.ttsSynthesizer?.pauseSpeaking(at: .immediate)
|
|
66
|
-
self.ttsSynthesizer?.stopSpeaking(at: .immediate)
|
|
67
|
-
|
|
68
|
-
call.success()
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@objc func openInstall(_ call: CAPPluginCall) {
|
|
73
|
-
call.success()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@objc func setSpeechRate(_ call: CAPPluginCall) {
|
|
77
|
-
if call.hasOption("speechRate") {
|
|
78
|
-
let speechRate = call.getFloat("speechRate")
|
|
79
|
-
|
|
80
|
-
if speechRate != nil {
|
|
81
|
-
self.ttsUtterance?.rate = speechRate!
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
@objc func setPitchRate(_ call: CAPPluginCall) {
|
|
87
|
-
if call.hasOption("pitchRate") {
|
|
88
|
-
let pitchRate = call.getFloat("pitchRate")
|
|
89
|
-
|
|
90
|
-
if pitchRate != nil {
|
|
91
|
-
self.ttsUtterance?.pitchMultiplier = pitchRate!
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@objc func getSupportedLanguages(_ call: CAPPluginCall) {
|
|
97
|
-
call.success([
|
|
98
|
-
"languages": supportedLangs
|
|
99
|
-
])
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
@objc func getSupportedVoices(_ call: CAPPluginCall) {
|
|
103
|
-
call.success([
|
|
104
|
-
"voices": []
|
|
105
|
-
])
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Adjust rate for a closer match to other platform.
|
|
109
|
-
@objc func adjustRate(_ rate: Float) -> Float {
|
|
110
|
-
let baseRate = AVSpeechUtteranceDefaultSpeechRate
|
|
111
|
-
if rate == 1 {
|
|
112
|
-
return baseRate
|
|
113
|
-
}
|
|
114
|
-
if rate > baseRate {
|
|
115
|
-
return baseRate + (rate * 0.025)
|
|
116
|
-
}
|
|
117
|
-
return rate / 2
|
|
118
|
-
}
|
|
119
|
-
}
|