@capacitor-community/text-to-speech 2.0.1 → 2.1.0
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 +17 -17
- package/LICENSE +21 -21
- package/README.md +119 -119
- package/android/build.gradle +57 -57
- package/android/src/main/AndroidManifest.xml +3 -3
- package/android/src/main/java/com/getcapacitor/community/tts/SpeakResultCallback.java +6 -6
- package/android/src/main/java/com/getcapacitor/community/tts/TextToSpeech.java +186 -162
- package/android/src/main/java/com/getcapacitor/community/tts/TextToSpeechPlugin.java +131 -130
- package/dist/docs.json +76 -21
- package/dist/esm/definitions.d.ts +119 -112
- package/dist/esm/definitions.js +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +10 -10
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +25 -25
- package/dist/esm/web.js +91 -91
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +91 -91
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +91 -91
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Info.plist +24 -24
- package/ios/Plugin/TextToSpeech.swift +91 -81
- package/ios/Plugin/TextToSpeechPlugin.h +10 -10
- package/ios/Plugin/TextToSpeechPlugin.m +13 -13
- package/ios/Plugin/TextToSpeechPlugin.swift +80 -64
- package/package.json +81 -81
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst TextToSpeech = registerPlugin('TextToSpeech', {\n web: () => import('./web').then(m => new m.TextToSpeechWeb()),\n});\n// Warm up\nif ('speechSynthesis' in window) {\n window.speechSynthesis;\n}\nexport * from './definitions';\nexport { TextToSpeech };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class TextToSpeechWeb extends WebPlugin {\n constructor() {\n super();\n this.speechSynthesis = null;\n if ('speechSynthesis' in window) {\n this.speechSynthesis = window.speechSynthesis;\n window.addEventListener('beforeunload', () => {\n this.stop();\n });\n }\n }\n async speak(options) {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n await this.stop();\n const speechSynthesis = this.speechSynthesis;\n const utterance = this.createSpeechSynthesisUtterance(options);\n return new Promise((resolve, reject) => {\n utterance.onend = () => {\n resolve();\n };\n utterance.onerror = (event) => {\n reject(event);\n };\n speechSynthesis.speak(utterance);\n });\n }\n async stop() {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n this.speechSynthesis.cancel();\n }\n async getSupportedLanguages() {\n const voices = this.getSpeechSynthesisVoices();\n const languages = voices.map(voice => voice.lang);\n const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i);\n return { languages: filteredLanguages };\n }\n async getSupportedVoices() {\n const voices = this.getSpeechSynthesisVoices();\n return { voices };\n }\n async isLanguageSupported(options) {\n const result = await this.getSupportedLanguages();\n const isLanguageSupported = result.languages.includes(options.lang);\n return { supported: isLanguageSupported };\n }\n async openInstall() {\n this.throwUnimplementedError();\n }\n createSpeechSynthesisUtterance(options) {\n const voices = this.getSpeechSynthesisVoices();\n const utterance = new SpeechSynthesisUtterance();\n const { text, lang, rate, pitch, volume, voice } = options;\n if (voice) {\n utterance.voice = voices[voice];\n }\n if (volume) {\n utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;\n }\n if (rate) {\n utterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;\n }\n if (pitch) {\n utterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;\n }\n if (lang) {\n utterance.lang = lang;\n }\n utterance.text = text;\n return utterance;\n }\n getSpeechSynthesisVoices() {\n if (!this.speechSynthesis) {\n this.throwUnsupportedError();\n }\n if (!this.supportedVoices || this.supportedVoices.length < 1) {\n this.supportedVoices = this.speechSynthesis.getVoices();\n }\n return this.supportedVoices;\n }\n throwUnsupportedError() {\n throw this.unavailable('SpeechSynthesis API not available in this browser.');\n }\n throwUnimplementedError() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACjE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,EAAE,CAAC;IAChB,QAAQ,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IACpC,QAAQ,IAAI,iBAAiB,IAAI,MAAM,EAAE;IACzC,YAAY,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;IAC1D,YAAY,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAC1D,gBAAgB,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,aAAa,CAAC,CAAC;IACf,SAAS;IACT,KAAK;IACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;IACnC,YAAY,IAAI,CAAC,qBAAqB,EAAE,CAAC;IACzC,SAAS;IACT,QAAQ,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IAC1B,QAAQ,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;IACrD,QAAQ,MAAM,SAAS,GAAG,IAAI,CAAC,8BAA8B,CAAC,OAAO,CAAC,CAAC;IACvE,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;IAChD,YA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ACL,IAAI,wBAAwB,GAAG;IAC/B,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;IACnC,YAAY,IAAI,CAAC,qBAAqB,EAAE,CAAC;IACzC,SAAS;IACT,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE;IACtE,YAAY,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;IACpE,SAAS;IACT,QAAQ,OAAO,IAAI,CAAC,eAAe,CAAC;IACpC,KAAK;IACL,IAAI,qBAAqB,GAAG;IAC5B,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,oDAAoD,CAAC,CAAC;IACrF,KAAK;IACL,IAAI,uBAAuB,GAAG;IAC9B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC5D,KAAK;IACL;;;;;;;;;;;;;;;;;"}
|
package/ios/Plugin/Info.plist
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
-
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
-
<key>CFBundleExecutable</key>
|
|
8
|
-
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
-
<key>CFBundleIdentifier</key>
|
|
10
|
-
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
-
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
-
<string>6.0</string>
|
|
13
|
-
<key>CFBundleName</key>
|
|
14
|
-
<string>$(PRODUCT_NAME)</string>
|
|
15
|
-
<key>CFBundlePackageType</key>
|
|
16
|
-
<string>FMWK</string>
|
|
17
|
-
<key>CFBundleShortVersionString</key>
|
|
18
|
-
<string>1.0</string>
|
|
19
|
-
<key>CFBundleVersion</key>
|
|
20
|
-
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
-
<key>NSPrincipalClass</key>
|
|
22
|
-
<string></string>
|
|
23
|
-
</dict>
|
|
24
|
-
</plist>
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|
|
@@ -1,81 +1,91 @@
|
|
|
1
|
-
import AVFoundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
|
|
4
|
-
@objc public class TextToSpeech: NSObject, AVSpeechSynthesizerDelegate {
|
|
5
|
-
let synthesizer = AVSpeechSynthesizer()
|
|
6
|
-
var calls: [CAPPluginCall] = []
|
|
7
|
-
|
|
8
|
-
override init() {
|
|
9
|
-
super.init()
|
|
10
|
-
self.synthesizer.delegate = self
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didCancel utterance: AVSpeechUtterance) {
|
|
14
|
-
self.resolveCurrentCall()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) {
|
|
18
|
-
self.resolveCurrentCall()
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@objc public func speak(_ text: String, _ lang: String, _ rate: Float, _ pitch: Float, _ category: String, _ volume: Float, _ call: CAPPluginCall) throws {
|
|
22
|
-
self.synthesizer.stopSpeaking(at: .immediate)
|
|
23
|
-
|
|
24
|
-
var avAudioSessionCategory = AVAudioSession.Category.ambient
|
|
25
|
-
if category != "ambient" {
|
|
26
|
-
avAudioSessionCategory = AVAudioSession.Category.playback
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
try AVAudioSession.sharedInstance().setCategory(avAudioSessionCategory, mode: .default, options: AVAudioSession.CategoryOptions.duckOthers)
|
|
30
|
-
try AVAudioSession.sharedInstance().setActive(true)
|
|
31
|
-
|
|
32
|
-
self.calls.append(call)
|
|
33
|
-
|
|
34
|
-
let utterance = AVSpeechUtterance(string: text)
|
|
35
|
-
utterance.voice = AVSpeechSynthesisVoice(language: lang)
|
|
36
|
-
utterance.rate = adjustRate(rate)
|
|
37
|
-
utterance.pitchMultiplier = pitch
|
|
38
|
-
utterance.volume = volume
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@objc public func
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
import AVFoundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class TextToSpeech: NSObject, AVSpeechSynthesizerDelegate {
|
|
5
|
+
let synthesizer = AVSpeechSynthesizer()
|
|
6
|
+
var calls: [CAPPluginCall] = []
|
|
7
|
+
|
|
8
|
+
override init() {
|
|
9
|
+
super.init()
|
|
10
|
+
self.synthesizer.delegate = self
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didCancel utterance: AVSpeechUtterance) {
|
|
14
|
+
self.resolveCurrentCall()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) {
|
|
18
|
+
self.resolveCurrentCall()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@objc public func speak(_ text: String, _ lang: String, _ rate: Float, _ pitch: Float, _ category: String, _ volume: Float, _ voice : Int, _ call: CAPPluginCall) throws {
|
|
22
|
+
self.synthesizer.stopSpeaking(at: .immediate)
|
|
23
|
+
|
|
24
|
+
var avAudioSessionCategory = AVAudioSession.Category.ambient
|
|
25
|
+
if category != "ambient" {
|
|
26
|
+
avAudioSessionCategory = AVAudioSession.Category.playback
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try AVAudioSession.sharedInstance().setCategory(avAudioSessionCategory, mode: .default, options: AVAudioSession.CategoryOptions.duckOthers)
|
|
30
|
+
try AVAudioSession.sharedInstance().setActive(true)
|
|
31
|
+
|
|
32
|
+
self.calls.append(call)
|
|
33
|
+
|
|
34
|
+
let utterance = AVSpeechUtterance(string: text)
|
|
35
|
+
utterance.voice = AVSpeechSynthesisVoice(language: lang)
|
|
36
|
+
utterance.rate = adjustRate(rate)
|
|
37
|
+
utterance.pitchMultiplier = pitch
|
|
38
|
+
utterance.volume = volume
|
|
39
|
+
|
|
40
|
+
//Find the voice associated with the voice parameter if a voice specified.
|
|
41
|
+
//If the specified voice is not available we will fall back to default voice rather than raising an error.
|
|
42
|
+
if (voice >= 0) {
|
|
43
|
+
let allVoices = AVSpeechSynthesisVoice.speechVoices()
|
|
44
|
+
if (voice < allVoices.count) {
|
|
45
|
+
utterance.voice = allVoices[voice]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
synthesizer.speak(utterance)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@objc public func stop() {
|
|
53
|
+
synthesizer.stopSpeaking(at: .immediate)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@objc public func getSupportedLanguages() -> [String] {
|
|
57
|
+
return Array(AVSpeechSynthesisVoice.speechVoices().map {
|
|
58
|
+
return $0.language
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@objc public func isLanguageSupported(_ lang: String) -> Bool {
|
|
63
|
+
let voice = AVSpeechSynthesisVoice(language: lang)
|
|
64
|
+
return voice != nil
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Adjust rate for a closer match to other platform.
|
|
68
|
+
@objc private func adjustRate(_ rate: Float) -> Float {
|
|
69
|
+
let baseRate = AVSpeechUtteranceDefaultSpeechRate
|
|
70
|
+
if rate == 1 {
|
|
71
|
+
return baseRate
|
|
72
|
+
}
|
|
73
|
+
if rate > baseRate {
|
|
74
|
+
return baseRate + (rate * 0.025)
|
|
75
|
+
}
|
|
76
|
+
return rate / 2
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@objc private func resolveCurrentCall() {
|
|
80
|
+
do {
|
|
81
|
+
try AVAudioSession.sharedInstance().setActive(false)
|
|
82
|
+
} catch {
|
|
83
|
+
CAPLog.print(error.localizedDescription)
|
|
84
|
+
}
|
|
85
|
+
guard let call = calls.first else {
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
call.resolve()
|
|
89
|
+
calls.removeFirst()
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#import <UIKit/UIKit.h>
|
|
2
|
-
|
|
3
|
-
//! Project version number for Plugin.
|
|
4
|
-
FOUNDATION_EXPORT double PluginVersionNumber;
|
|
5
|
-
|
|
6
|
-
//! Project version string for Plugin.
|
|
7
|
-
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
|
-
|
|
9
|
-
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
|
10
|
-
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
//! Project version number for Plugin.
|
|
4
|
+
FOUNDATION_EXPORT double PluginVersionNumber;
|
|
5
|
+
|
|
6
|
+
//! Project version string for Plugin.
|
|
7
|
+
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
|
+
|
|
9
|
+
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
|
10
|
+
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#import <Capacitor/Capacitor.h>
|
|
3
|
-
|
|
4
|
-
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
-
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
-
CAP_PLUGIN(TextToSpeechPlugin, "TextToSpeech",
|
|
7
|
-
CAP_PLUGIN_METHOD(speak, CAPPluginReturnPromise);
|
|
8
|
-
CAP_PLUGIN_METHOD(stop, CAPPluginReturnPromise);
|
|
9
|
-
CAP_PLUGIN_METHOD(openInstall, CAPPluginReturnPromise);
|
|
10
|
-
CAP_PLUGIN_METHOD(getSupportedLanguages, CAPPluginReturnPromise);
|
|
11
|
-
CAP_PLUGIN_METHOD(getSupportedVoices, CAPPluginReturnPromise);
|
|
12
|
-
CAP_PLUGIN_METHOD(isLanguageSupported, CAPPluginReturnPromise);
|
|
13
|
-
)
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <Capacitor/Capacitor.h>
|
|
3
|
+
|
|
4
|
+
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
+
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
+
CAP_PLUGIN(TextToSpeechPlugin, "TextToSpeech",
|
|
7
|
+
CAP_PLUGIN_METHOD(speak, CAPPluginReturnPromise);
|
|
8
|
+
CAP_PLUGIN_METHOD(stop, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(openInstall, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(getSupportedLanguages, CAPPluginReturnPromise);
|
|
11
|
+
CAP_PLUGIN_METHOD(getSupportedVoices, CAPPluginReturnPromise);
|
|
12
|
+
CAP_PLUGIN_METHOD(isLanguageSupported, CAPPluginReturnPromise);
|
|
13
|
+
)
|
|
@@ -1,64 +1,80 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
let
|
|
17
|
-
let
|
|
18
|
-
let
|
|
19
|
-
let
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import AVFoundation
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
7
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
8
|
+
*/
|
|
9
|
+
@objc(TextToSpeechPlugin)
|
|
10
|
+
public class TextToSpeechPlugin: CAPPlugin {
|
|
11
|
+
private static let errorUnsupportedLanguage = "This language is not supported."
|
|
12
|
+
|
|
13
|
+
private let implementation = TextToSpeech()
|
|
14
|
+
|
|
15
|
+
@objc public func speak(_ call: CAPPluginCall) {
|
|
16
|
+
let text = call.getString("text") ?? ""
|
|
17
|
+
let lang = call.getString("lang") ?? "en-US"
|
|
18
|
+
let rate = call.getFloat("rate") ?? 1.0
|
|
19
|
+
let pitch = call.getFloat("pitch") ?? 1.0
|
|
20
|
+
let volume = call.getFloat("volume") ?? 1.0
|
|
21
|
+
let voice = call.getInt("voice") ?? -1
|
|
22
|
+
let category = call.getString("category") ?? "ambient"
|
|
23
|
+
|
|
24
|
+
let isLanguageSupported = implementation.isLanguageSupported(lang)
|
|
25
|
+
guard isLanguageSupported else {
|
|
26
|
+
call.reject(TextToSpeechPlugin.errorUnsupportedLanguage)
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
do {
|
|
31
|
+
try implementation.speak(text, lang, rate, pitch, category, volume, voice, call)
|
|
32
|
+
} catch {
|
|
33
|
+
call.reject(error.localizedDescription)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@objc public func stop(_ call: CAPPluginCall) {
|
|
38
|
+
implementation.stop()
|
|
39
|
+
call.resolve()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@objc public func openInstall(_ call: CAPPluginCall) {
|
|
43
|
+
call.resolve()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@objc func getSupportedLanguages(_ call: CAPPluginCall) {
|
|
47
|
+
let languages = self.implementation.getSupportedLanguages()
|
|
48
|
+
call.resolve([
|
|
49
|
+
"languages": languages
|
|
50
|
+
])
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@objc func getSupportedVoices(_ call: CAPPluginCall) {
|
|
54
|
+
let allVoices = AVSpeechSynthesisVoice.speechVoices()
|
|
55
|
+
var res: [[String: Any]] = []
|
|
56
|
+
|
|
57
|
+
for voice in allVoices {
|
|
58
|
+
let lang = [
|
|
59
|
+
"default": false,
|
|
60
|
+
"lang": voice.language,
|
|
61
|
+
"localService": true,
|
|
62
|
+
"name": voice.name,
|
|
63
|
+
"voiceURI": voice.identifier
|
|
64
|
+
] as [String : Any]
|
|
65
|
+
res.append(lang)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
call.resolve([
|
|
69
|
+
"voices": res
|
|
70
|
+
])
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@objc func isLanguageSupported(_ call: CAPPluginCall) {
|
|
74
|
+
let lang = call.getString("lang") ?? ""
|
|
75
|
+
let isLanguageSupported = self.implementation.isLanguageSupported(lang)
|
|
76
|
+
call.resolve([
|
|
77
|
+
"supported": isLanguageSupported
|
|
78
|
+
])
|
|
79
|
+
}
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@capacitor-community/text-to-speech",
|
|
3
|
-
"version": "2.0
|
|
4
|
-
"description": "Capacitor plugin for synthesizing speech from text.",
|
|
5
|
-
"main": "dist/plugin.cjs.js",
|
|
6
|
-
"module": "dist/esm/index.js",
|
|
7
|
-
"types": "dist/esm/index.d.ts",
|
|
8
|
-
"unpkg": "dist/plugin.js",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
11
|
-
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
12
|
-
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
13
|
-
"verify:web": "npm run build",
|
|
14
|
-
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
15
|
-
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
16
|
-
"eslint": "eslint . --ext ts",
|
|
17
|
-
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
18
|
-
"swiftlint": "node-swiftlint",
|
|
19
|
-
"docgen": "docgen --api TextToSpeechPlugin --output-readme README.md --output-json dist/docs.json",
|
|
20
|
-
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
|
|
21
|
-
"clean": "rimraf ./dist",
|
|
22
|
-
"watch": "tsc --watch",
|
|
23
|
-
"prepublishOnly": "npm run build",
|
|
24
|
-
"release": "standard-version"
|
|
25
|
-
},
|
|
26
|
-
"author": "Robin Genz <mail@robingenz.dev>",
|
|
27
|
-
"license": "MIT",
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@capacitor/android": "4.0.1",
|
|
30
|
-
"@capacitor/cli": "4.0.1",
|
|
31
|
-
"@capacitor/core": "4.0.1",
|
|
32
|
-
"@capacitor/docgen": "0.2.0",
|
|
33
|
-
"@capacitor/ios": "4.0.1",
|
|
34
|
-
"@ionic/eslint-config": "0.3.0",
|
|
35
|
-
"@ionic/prettier-config": "1.0.1",
|
|
36
|
-
"@ionic/swiftlint-config": "1.1.2",
|
|
37
|
-
"eslint": "7.32.0",
|
|
38
|
-
"prettier": "2.3.2",
|
|
39
|
-
"prettier-plugin-java": "1.0.2",
|
|
40
|
-
"rimraf": "3.0.2",
|
|
41
|
-
"rollup": "2.77.2",
|
|
42
|
-
"standard-version": "9.5.0",
|
|
43
|
-
"swiftlint": "1.0.1",
|
|
44
|
-
"typescript": "4.1.5"
|
|
45
|
-
},
|
|
46
|
-
"peerDependencies": {
|
|
47
|
-
"@capacitor/core": "^4.0.0"
|
|
48
|
-
},
|
|
49
|
-
"files": [
|
|
50
|
-
"android/src/main/",
|
|
51
|
-
"android/build.gradle",
|
|
52
|
-
"dist/",
|
|
53
|
-
"ios/Plugin/",
|
|
54
|
-
"CapacitorCommunityTextToSpeech.podspec"
|
|
55
|
-
],
|
|
56
|
-
"repository": {
|
|
57
|
-
"type": "git",
|
|
58
|
-
"url": "git+https://github.com/capacitor-community/text-to-speech.git"
|
|
59
|
-
},
|
|
60
|
-
"bugs": {
|
|
61
|
-
"url": "https://github.com/capacitor-community/text-to-speech/issues"
|
|
62
|
-
},
|
|
63
|
-
"keywords": [
|
|
64
|
-
"capacitor",
|
|
65
|
-
"plugin",
|
|
66
|
-
"native"
|
|
67
|
-
],
|
|
68
|
-
"prettier": "@ionic/prettier-config",
|
|
69
|
-
"swiftlint": "@ionic/swiftlint-config",
|
|
70
|
-
"eslintConfig": {
|
|
71
|
-
"extends": "@ionic/eslint-config/recommended"
|
|
72
|
-
},
|
|
73
|
-
"capacitor": {
|
|
74
|
-
"ios": {
|
|
75
|
-
"src": "ios"
|
|
76
|
-
},
|
|
77
|
-
"android": {
|
|
78
|
-
"src": "android"
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@capacitor-community/text-to-speech",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "Capacitor plugin for synthesizing speech from text.",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
11
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
12
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
13
|
+
"verify:web": "npm run build",
|
|
14
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
15
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
16
|
+
"eslint": "eslint . --ext ts",
|
|
17
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
18
|
+
"swiftlint": "node-swiftlint",
|
|
19
|
+
"docgen": "docgen --api TextToSpeechPlugin --output-readme README.md --output-json dist/docs.json",
|
|
20
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
|
|
21
|
+
"clean": "rimraf ./dist",
|
|
22
|
+
"watch": "tsc --watch",
|
|
23
|
+
"prepublishOnly": "npm run build",
|
|
24
|
+
"release": "standard-version"
|
|
25
|
+
},
|
|
26
|
+
"author": "Robin Genz <mail@robingenz.dev>",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@capacitor/android": "4.0.1",
|
|
30
|
+
"@capacitor/cli": "4.0.1",
|
|
31
|
+
"@capacitor/core": "4.0.1",
|
|
32
|
+
"@capacitor/docgen": "0.2.0",
|
|
33
|
+
"@capacitor/ios": "4.0.1",
|
|
34
|
+
"@ionic/eslint-config": "0.3.0",
|
|
35
|
+
"@ionic/prettier-config": "1.0.1",
|
|
36
|
+
"@ionic/swiftlint-config": "1.1.2",
|
|
37
|
+
"eslint": "7.32.0",
|
|
38
|
+
"prettier": "2.3.2",
|
|
39
|
+
"prettier-plugin-java": "1.0.2",
|
|
40
|
+
"rimraf": "3.0.2",
|
|
41
|
+
"rollup": "2.77.2",
|
|
42
|
+
"standard-version": "9.5.0",
|
|
43
|
+
"swiftlint": "1.0.1",
|
|
44
|
+
"typescript": "4.1.5"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@capacitor/core": "^4.0.0"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"android/src/main/",
|
|
51
|
+
"android/build.gradle",
|
|
52
|
+
"dist/",
|
|
53
|
+
"ios/Plugin/",
|
|
54
|
+
"CapacitorCommunityTextToSpeech.podspec"
|
|
55
|
+
],
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "git+https://github.com/capacitor-community/text-to-speech.git"
|
|
59
|
+
},
|
|
60
|
+
"bugs": {
|
|
61
|
+
"url": "https://github.com/capacitor-community/text-to-speech/issues"
|
|
62
|
+
},
|
|
63
|
+
"keywords": [
|
|
64
|
+
"capacitor",
|
|
65
|
+
"plugin",
|
|
66
|
+
"native"
|
|
67
|
+
],
|
|
68
|
+
"prettier": "@ionic/prettier-config",
|
|
69
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
70
|
+
"eslintConfig": {
|
|
71
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
72
|
+
},
|
|
73
|
+
"capacitor": {
|
|
74
|
+
"ios": {
|
|
75
|
+
"src": "ios"
|
|
76
|
+
},
|
|
77
|
+
"android": {
|
|
78
|
+
"src": "android"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|