@capacitor-community/text-to-speech 1.1.2 → 2.0.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.
@@ -1,81 +1,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, _ 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
- synthesizer.speak(utterance)
40
- }
41
-
42
- @objc public func stop() {
43
- synthesizer.stopSpeaking(at: .immediate)
44
- }
45
-
46
- @objc public func getSupportedLanguages() -> [String] {
47
- return Array(AVSpeechSynthesisVoice.speechVoices().map {
48
- return $0.language
49
- })
50
- }
51
-
52
- @objc public func isLanguageSupported(_ lang: String) -> Bool {
53
- let voice = AVSpeechSynthesisVoice(language: lang)
54
- return voice != nil
55
- }
56
-
57
- // Adjust rate for a closer match to other platform.
58
- @objc private func adjustRate(_ rate: Float) -> Float {
59
- let baseRate = AVSpeechUtteranceDefaultSpeechRate
60
- if rate == 1 {
61
- return baseRate
62
- }
63
- if rate > baseRate {
64
- return baseRate + (rate * 0.025)
65
- }
66
- return rate / 2
67
- }
68
-
69
- @objc private func resolveCurrentCall() {
70
- do {
71
- try AVAudioSession.sharedInstance().setActive(false)
72
- } catch {
73
- CAPLog.print(error.localizedDescription)
74
- }
75
- guard let call = calls.first else {
76
- return
77
- }
78
- call.resolve()
79
- calls.removeFirst()
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, _ 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
+ synthesizer.speak(utterance)
40
+ }
41
+
42
+ @objc public func stop() {
43
+ synthesizer.stopSpeaking(at: .immediate)
44
+ }
45
+
46
+ @objc public func getSupportedLanguages() -> [String] {
47
+ return Array(AVSpeechSynthesisVoice.speechVoices().map {
48
+ return $0.language
49
+ })
50
+ }
51
+
52
+ @objc public func isLanguageSupported(_ lang: String) -> Bool {
53
+ let voice = AVSpeechSynthesisVoice(language: lang)
54
+ return voice != nil
55
+ }
56
+
57
+ // Adjust rate for a closer match to other platform.
58
+ @objc private func adjustRate(_ rate: Float) -> Float {
59
+ let baseRate = AVSpeechUtteranceDefaultSpeechRate
60
+ if rate == 1 {
61
+ return baseRate
62
+ }
63
+ if rate > baseRate {
64
+ return baseRate + (rate * 0.025)
65
+ }
66
+ return rate / 2
67
+ }
68
+
69
+ @objc private func resolveCurrentCall() {
70
+ do {
71
+ try AVAudioSession.sharedInstance().setActive(false)
72
+ } catch {
73
+ CAPLog.print(error.localizedDescription)
74
+ }
75
+ guard let call = calls.first else {
76
+ return
77
+ }
78
+ call.resolve()
79
+ calls.removeFirst()
80
+ }
81
+ }
@@ -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,64 @@
1
- import Foundation
2
- import Capacitor
3
-
4
- /**
5
- * Please read the Capacitor iOS Plugin Development Guide
6
- * here: https://capacitorjs.com/docs/plugins/ios
7
- */
8
- @objc(TextToSpeechPlugin)
9
- public class TextToSpeechPlugin: CAPPlugin {
10
- private static let errorUnsupportedLanguage = "This language is not supported."
11
-
12
- private let implementation = TextToSpeech()
13
-
14
- @objc public func speak(_ call: CAPPluginCall) {
15
- let text = call.getString("text") ?? ""
16
- let lang = call.getString("lang") ?? "en-US"
17
- let rate = call.getFloat("rate") ?? 1.0
18
- let pitch = call.getFloat("pitch") ?? 1.0
19
- let volume = call.getFloat("volume") ?? 1.0
20
- let category = call.getString("category") ?? "ambient"
21
-
22
- let isLanguageSupported = implementation.isLanguageSupported(lang)
23
- guard isLanguageSupported else {
24
- call.reject(TextToSpeechPlugin.errorUnsupportedLanguage)
25
- return
26
- }
27
-
28
- do {
29
- try implementation.speak(text, lang, rate, pitch, category, volume, call)
30
- } catch {
31
- call.reject(error.localizedDescription)
32
- }
33
- }
34
-
35
- @objc public func stop(_ call: CAPPluginCall) {
36
- implementation.stop()
37
- call.resolve()
38
- }
39
-
40
- @objc public func openInstall(_ call: CAPPluginCall) {
41
- call.resolve()
42
- }
43
-
44
- @objc func getSupportedLanguages(_ call: CAPPluginCall) {
45
- let languages = self.implementation.getSupportedLanguages()
46
- call.resolve([
47
- "languages": languages
48
- ])
49
- }
50
-
51
- @objc func getSupportedVoices(_ call: CAPPluginCall) {
52
- call.resolve([
53
- "voices": []
54
- ])
55
- }
56
-
57
- @objc func isLanguageSupported(_ call: CAPPluginCall) {
58
- let lang = call.getString("lang") ?? ""
59
- let isLanguageSupported = self.implementation.isLanguageSupported(lang)
60
- call.resolve([
61
- "supported": isLanguageSupported
62
- ])
63
- }
64
- }
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ /**
5
+ * Please read the Capacitor iOS Plugin Development Guide
6
+ * here: https://capacitorjs.com/docs/plugins/ios
7
+ */
8
+ @objc(TextToSpeechPlugin)
9
+ public class TextToSpeechPlugin: CAPPlugin {
10
+ private static let errorUnsupportedLanguage = "This language is not supported."
11
+
12
+ private let implementation = TextToSpeech()
13
+
14
+ @objc public func speak(_ call: CAPPluginCall) {
15
+ let text = call.getString("text") ?? ""
16
+ let lang = call.getString("lang") ?? "en-US"
17
+ let rate = call.getFloat("rate") ?? 1.0
18
+ let pitch = call.getFloat("pitch") ?? 1.0
19
+ let volume = call.getFloat("volume") ?? 1.0
20
+ let category = call.getString("category") ?? "ambient"
21
+
22
+ let isLanguageSupported = implementation.isLanguageSupported(lang)
23
+ guard isLanguageSupported else {
24
+ call.reject(TextToSpeechPlugin.errorUnsupportedLanguage)
25
+ return
26
+ }
27
+
28
+ do {
29
+ try implementation.speak(text, lang, rate, pitch, category, volume, call)
30
+ } catch {
31
+ call.reject(error.localizedDescription)
32
+ }
33
+ }
34
+
35
+ @objc public func stop(_ call: CAPPluginCall) {
36
+ implementation.stop()
37
+ call.resolve()
38
+ }
39
+
40
+ @objc public func openInstall(_ call: CAPPluginCall) {
41
+ call.resolve()
42
+ }
43
+
44
+ @objc func getSupportedLanguages(_ call: CAPPluginCall) {
45
+ let languages = self.implementation.getSupportedLanguages()
46
+ call.resolve([
47
+ "languages": languages
48
+ ])
49
+ }
50
+
51
+ @objc func getSupportedVoices(_ call: CAPPluginCall) {
52
+ call.resolve([
53
+ "voices": []
54
+ ])
55
+ }
56
+
57
+ @objc func isLanguageSupported(_ call: CAPPluginCall) {
58
+ let lang = call.getString("lang") ?? ""
59
+ let isLanguageSupported = self.implementation.isLanguageSupported(lang)
60
+ call.resolve([
61
+ "supported": isLanguageSupported
62
+ ])
63
+ }
64
+ }
package/package.json CHANGED
@@ -1,81 +1,81 @@
1
- {
2
- "name": "@capacitor-community/text-to-speech",
3
- "version": "1.1.2",
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 && 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": "3.4.0",
30
- "@capacitor/cli": "3.4.0",
31
- "@capacitor/core": "3.4.0",
32
- "@capacitor/docgen": "0.0.18",
33
- "@capacitor/ios": "3.4.0",
34
- "@ionic/eslint-config": "0.3.0",
35
- "@ionic/prettier-config": "1.0.1",
36
- "@ionic/swiftlint-config": "1.1.2",
37
- "eslint": "7.11.0",
38
- "prettier": "2.2.0",
39
- "prettier-plugin-java": "1.0.0",
40
- "rimraf": "3.0.2",
41
- "rollup": "2.32.0",
42
- "standard-version": "9.1.0",
43
- "swiftlint": "1.0.1",
44
- "typescript": "4.0.3"
45
- },
46
- "peerDependencies": {
47
- "@capacitor/core": "^3.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.0.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
+ }