@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.
Files changed (36) hide show
  1. package/CapacitorCommunityTextToSpeech.podspec +1 -1
  2. package/LICENSE +1 -1
  3. package/README.md +169 -113
  4. package/android/build.gradle +14 -8
  5. package/android/src/main/AndroidManifest.xml +3 -5
  6. package/android/src/main/java/com/getcapacitor/community/tts/SpeakResultCallback.java +6 -0
  7. package/android/src/main/java/com/getcapacitor/community/tts/TextToSpeech.java +98 -180
  8. package/android/src/main/java/com/getcapacitor/community/tts/TextToSpeechPlugin.java +130 -0
  9. package/android/src/main/res/.gitkeep +0 -0
  10. package/dist/docs.json +194 -0
  11. package/dist/esm/definitions.d.ts +70 -17
  12. package/dist/esm/definitions.js +1 -0
  13. package/dist/esm/definitions.js.map +1 -1
  14. package/dist/esm/index.d.ts +3 -1
  15. package/dist/esm/index.js +9 -1
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/web.d.ts +7 -9
  18. package/dist/esm/web.js +48 -76
  19. package/dist/esm/web.js.map +1 -1
  20. package/dist/plugin.cjs.js +57 -75
  21. package/dist/plugin.cjs.js.map +1 -1
  22. package/dist/plugin.js +59 -75
  23. package/dist/plugin.js.map +1 -1
  24. package/ios/Plugin/Info.plist +1 -1
  25. package/ios/Plugin/TextToSpeech.swift +81 -0
  26. package/ios/Plugin/{Plugin.h → TextToSpeechPlugin.h} +0 -0
  27. package/ios/Plugin/{Plugin.m → TextToSpeechPlugin.m} +2 -3
  28. package/ios/Plugin/TextToSpeechPlugin.swift +64 -0
  29. package/package.json +36 -21
  30. package/CHANGELOG.md +0 -46
  31. package/android/src/main/java/com/getcapacitor/community/tts/Constant.java +0 -8
  32. package/android/src/main/res/layout/bridge_layout_main.xml +0 -15
  33. package/android/src/main/res/values/colors.xml +0 -3
  34. package/android/src/main/res/values/strings.xml +0 -3
  35. package/android/src/main/res/values/styles.xml +0 -3
  36. package/ios/Plugin/Plugin.swift +0 -119
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '11.0'
14
+ s.ios.deployment_target = '12.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.swift_version = '5.1'
17
17
  end
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) COPYRIGHT_YEAR COPYRIGHT_HOLDER
3
+ Copyright (c) 2021 Robin Genz
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  </p>
7
7
 
8
8
  <p align="center">
9
- <img src="https://img.shields.io/maintenance/yes/2021?style=flat-square" />
9
+ <img src="https://img.shields.io/maintenance/yes/2022?style=flat-square" />
10
10
  <a href="https://github.com/capacitor-community/text-to-speech/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/text-to-speech/CI/master?style=flat-square" /></a>
11
11
  <a href="https://www.npmjs.com/package/@capacitor-community/text-to-speech"><img src="https://img.shields.io/npm/l/@capacitor-community/text-to-speech?style=flat-square" /></a>
12
12
  <br>
@@ -30,134 +30,190 @@ npm install @capacitor-community/text-to-speech
30
30
  npx cap sync
31
31
  ```
32
32
 
33
- On **iOS**, no further steps are needed.
33
+ ### Android
34
34
 
35
- On **Android**, register the plugin in your main activity:
35
+ According to the [Android documentation](https://developer.android.com/reference/android/speech/tts/TextToSpeech), apps targeting **Android 11** should declare [TextToSpeech.Engine.INTENT_ACTION_TTS_SERVICE](https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#INTENT_ACTION_TTS_SERVICE) in the queries elements of their manifest:
36
36
 
37
- ```java
38
- import com.getcapacitor.community.tts.TextToSpeech;
37
+ ```xml
38
+ <queries>
39
+ <intent>
40
+ <action android:name="android.intent.action.TTS_SERVICE" />
41
+ </intent>
42
+ </queries>
43
+ ```
44
+
45
+ [Here](https://github.com/robingenz/capacitor-plugin-demo/commit/b7dc6c6d6652be9356d354df1faeb6a40e442797) you can find an example commit.
39
46
 
40
- public class MainActivity extends BridgeActivity {
47
+ ## Configuration
48
+
49
+ No configuration required for this plugin.
41
50
 
42
- @Override
43
- public void onCreate(Bundle savedInstanceState) {
44
- super.onCreate(savedInstanceState);
51
+ ## Demo
45
52
 
46
- // Initializes the Bridge
47
- this.init(
48
- savedInstanceState,
49
- new ArrayList<Class<? extends Plugin>>() {
53
+ A working example can be found here: [robingenz/capacitor-plugin-demo](https://github.com/robingenz/capacitor-plugin-demo)
50
54
 
51
- {
52
- // Additional plugins you've installed go here
53
- // Ex: add(TotallyAwesomePlugin.class);
54
- add(TextToSpeech.class);
55
- }
56
- }
57
- );
58
- }
59
- }
55
+ ## Usage
56
+
57
+ ```typescript
58
+ import { TextToSpeech } from '@capacitor-community/text-to-speech';
59
+
60
+ const speak = async () => {
61
+ await TextToSpeech.speak({
62
+ text: 'This is a sample text.',
63
+ lang: 'en_US',
64
+ rate: 1.0,
65
+ pitch: 1.0,
66
+ volume: 1.0,
67
+ category: 'ambient',
68
+ });
69
+ };
70
+
71
+ const stop = async () => {
72
+ await TextToSpeech.stop();
73
+ };
74
+
75
+ const getSupportedLanguages = async () => {
76
+ const languages = await TextToSpeech.getSupportedLanguages();
77
+ };
78
+
79
+ const getSupportedVoices = async () => {
80
+ const voices = await TextToSpeech.getSupportedVoices();
81
+ };
82
+
83
+ const isLanguageSupported = async (lang: string) => {
84
+ const isSupported = await TextToSpeech.isLanguageSupported({ lang });
85
+ };
60
86
  ```
61
87
 
62
- ## Configuration
88
+ ## API
63
89
 
64
- No configuration required for this plugin.
90
+ <docgen-index>
65
91
 
66
- ## Supported methods
92
+ * [`speak(...)`](#speak)
93
+ * [`stop()`](#stop)
94
+ * [`getSupportedLanguages()`](#getsupportedlanguages)
95
+ * [`getSupportedVoices()`](#getsupportedvoices)
96
+ * [`isLanguageSupported(...)`](#islanguagesupported)
97
+ * [`openInstall()`](#openinstall)
98
+ * [Interfaces](#interfaces)
67
99
 
68
- | Name | Android | iOS | Web |
69
- | :-------------------- | :------ | :-- | :-- |
70
- | speak | ✅ | ✅ | ✅ |
71
- | stop | ✅ | ✅ | ✅ |
72
- | getSupportedLanguages | ✅ | ✅ | ✅ |
73
- | openInstall | ✅ | ✅ | ❌ |
74
- | setPitchRate | ✅ | ✅ | ❌ |
75
- | setSpeechRate | ✅ | ✅ | ❌ |
100
+ </docgen-index>
76
101
 
77
- ## Usage
102
+ <docgen-api>
103
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
104
+
105
+ ### speak(...)
78
106
 
79
107
  ```typescript
80
- // Must import the package once to make sure the web support initializes
81
- import '@capacitor-community/text-to-speech';
82
-
83
- import { Plugins } from '@capacitor/core';
84
-
85
- const { TextToSpeech } = Plugins;
86
-
87
- /**
88
- * Platform: Android/iOS/Web
89
- * This method will trigger text to speech engine and play desired text.
90
- * @param text - desired text to play in speech
91
- * locale - supported locale (can be obtained by calling getSupportedLanguages())
92
- * speechRate - speech rate (1.0 is the normal speech rate, lower values slow down the speech, greater values accelerate it)
93
- * pitchRate - pitch rate (1.0 is the normal pitch rate, smaller value lowers the tone and greater value increases it)
94
- * volume - volume of the synthesis (0 - 1)
95
- * voice - index of the voice (can be obtained by calling getSupportedVoices()) (Android/Web Only)
96
- * @returns void
97
- */
98
- TextToSpeech.speak({
99
- text: 'This is a sample text.',
100
- locale: 'en_US',
101
- speechRate: 1.0,
102
- pitchRate: 1,
103
- volume: 1.0,
104
- voice: 10,
105
- category: 'ambient',
106
- });
107
-
108
- /**
109
- * Platform: Android/iOS/Web
110
- * This method will stop the engine if it's in the middle of playback.
111
- * @param none
112
- * @returns void
113
- */
114
- TextToSpeech.stop();
115
-
116
- /**
117
- * Platform: Android/iOS/Web
118
- * This method will return list of supported languages.
119
- * @param none
120
- * @returns languages - list of available languages
121
- */
122
- TextToSpeech.getSupportedLanguages();
123
-
124
- /**
125
- * Platform: Android/iOS/Web
126
- * This method will return list of supported voices.
127
- * @param none
128
- * @returns voices - list of available voices
129
- */
130
- TextToSpeech.getSupportedVoices();
131
-
132
- /**
133
- * Platform: Android/iOS
134
- * This method will trigger the platform TextToSpeech engine to start the activity that installs the resource files on the device that are required for TTS to be operational.
135
- * @param none
136
- * @returns void
137
- */
138
- TextToSpeech.openInstall();
139
-
140
- /**
141
- * * Platform: Android/iOS
142
- * This method will change the pitch rate while the text is being played.
143
- * @param pitchRate - rate of the pitch (1.0 is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it)
144
- * @returns void
145
- */
146
- TextToSpeech.setPitchRate({
147
- pitchRate: 1.5,
148
- });
149
-
150
- /**
151
- * * Platform: Android/iOS
152
- * This method will change the speech rate while the text is being played.
153
- * @param speechRate - speech rate (1.0 is the normal speech rate, lower values slow down the speech, greater values accelerate it)
154
- * @returns void
155
- */
156
- TextToSpeech.setSpeechRate({
157
- speechRate: 0.5,
158
- });
108
+ speak(options: TTSOptions) => Promise<void>
159
109
  ```
160
110
 
111
+ Starts the TTS engine and plays the desired text.
112
+
113
+ | Param | Type |
114
+ | ------------- | ------------------------------------------------- |
115
+ | **`options`** | <code><a href="#ttsoptions">TTSOptions</a></code> |
116
+
117
+ --------------------
118
+
119
+
120
+ ### stop()
121
+
122
+ ```typescript
123
+ stop() => Promise<void>
124
+ ```
125
+
126
+ Stops the TTS engine.
127
+
128
+ --------------------
129
+
130
+
131
+ ### getSupportedLanguages()
132
+
133
+ ```typescript
134
+ getSupportedLanguages() => Promise<{ languages: string[]; }>
135
+ ```
136
+
137
+ Returns a list of supported BCP 47 language tags.
138
+
139
+ **Returns:** <code>Promise&lt;{ languages: string[]; }&gt;</code>
140
+
141
+ --------------------
142
+
143
+
144
+ ### getSupportedVoices()
145
+
146
+ ```typescript
147
+ getSupportedVoices() => Promise<{ voices: SpeechSynthesisVoice[]; }>
148
+ ```
149
+
150
+ Returns a list of supported voices.
151
+
152
+ **Returns:** <code>Promise&lt;{ voices: SpeechSynthesisVoice[]; }&gt;</code>
153
+
154
+ --------------------
155
+
156
+
157
+ ### isLanguageSupported(...)
158
+
159
+ ```typescript
160
+ isLanguageSupported(options: { lang: string; }) => Promise<{ supported: boolean; }>
161
+ ```
162
+
163
+ Checks if a specific BCP 47 language tag is supported.
164
+
165
+ | Param | Type |
166
+ | ------------- | ------------------------------ |
167
+ | **`options`** | <code>{ lang: string; }</code> |
168
+
169
+ **Returns:** <code>Promise&lt;{ supported: boolean; }&gt;</code>
170
+
171
+ --------------------
172
+
173
+
174
+ ### openInstall()
175
+
176
+ ```typescript
177
+ openInstall() => Promise<void>
178
+ ```
179
+
180
+ Verifies proper installation and availability of resource files on the system.
181
+
182
+ Only available for Android.
183
+
184
+ --------------------
185
+
186
+
187
+ ### Interfaces
188
+
189
+
190
+ #### TTSOptions
191
+
192
+ | Prop | Type | Description |
193
+ | -------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
194
+ | **`text`** | <code>string</code> | The text that will be synthesised when the utterance is spoken. |
195
+ | **`lang`** | <code>string</code> | The language of the utterance. Possible languages can be queried using `getSupportedLanguages`. Default: `en-US`. |
196
+ | **`rate`** | <code>number</code> | The speed at which the utterance will be spoken at. Default: `1.0`. |
197
+ | **`pitch`** | <code>number</code> | The pitch at which the utterance will be spoken at. Default: `1.0`. |
198
+ | **`volume`** | <code>number</code> | The volume that the utterance will be spoken at. Default: `1.0`. |
199
+ | **`voice`** | <code>number</code> | The index of the selected voice that will be used to speak the utterance. Possible voices can be queried using `getSupportedVoices`. Only available for Web. |
200
+ | **`category`** | <code>string</code> | Select the iOS Audio session category. Possible values: `ambient` and `playback`. Use `playback` to play audio even when the app is in the background. Only available for iOS. Default: `ambient`. |
201
+
202
+
203
+ #### SpeechSynthesisVoice
204
+
205
+ The <a href="#speechsynthesisvoice">SpeechSynthesisVoice</a> interface represents a voice that the system supports.
206
+
207
+ | Prop | Type | Description |
208
+ | ------------------ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
209
+ | **`default`** | <code>boolean</code> | Specifies whether the voice is the default voice for the current app (`true`) or not (`false`). |
210
+ | **`lang`** | <code>string</code> | BCP 47 language tag indicating the language of the voice. Example: `en-US`. |
211
+ | **`localService`** | <code>boolean</code> | Specifies whether the voice is supplied by a local (`true`) or remote (`false`) speech synthesizer service. |
212
+ | **`name`** | <code>string</code> | Human-readable name that represents the voice. Example: `Microsoft Zira Desktop - English (United States)`. |
213
+ | **`voiceURI`** | <code>string</code> | Type of URI and location of the speech synthesis service for this voice. Example: `urn:moz-tts:sapi:Microsoft Zira Desktop - English (United States)?en-US`. |
214
+
215
+ </docgen-api>
216
+
161
217
  ## Changelog
162
218
 
163
219
  See [CHANGELOG.md](https://github.com/capacitor-community/text-to-speech/blob/master/CHANGELOG.md).
@@ -1,26 +1,27 @@
1
1
  ext {
2
- junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.12'
3
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.1'
4
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.2.0'
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
5
6
  }
6
7
 
7
8
  buildscript {
8
9
  repositories {
9
10
  google()
10
- jcenter()
11
+ mavenCentral()
11
12
  }
12
13
  dependencies {
13
- classpath 'com.android.tools.build:gradle:3.6.1'
14
+ classpath 'com.android.tools.build:gradle:4.2.1'
14
15
  }
15
16
  }
16
17
 
17
18
  apply plugin: 'com.android.library'
18
19
 
19
20
  android {
20
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 29
21
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
21
22
  defaultConfig {
22
23
  minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
23
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 29
24
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
24
25
  versionCode 1
25
26
  versionName "1.0"
26
27
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -34,18 +35,23 @@ android {
34
35
  lintOptions {
35
36
  abortOnError false
36
37
  }
38
+ compileOptions {
39
+ sourceCompatibility JavaVersion.VERSION_1_8
40
+ targetCompatibility JavaVersion.VERSION_1_8
41
+ }
37
42
  }
38
43
 
39
44
  repositories {
40
45
  google()
41
- jcenter()
42
46
  mavenCentral()
47
+ jcenter()
43
48
  }
44
49
 
45
50
 
46
51
  dependencies {
47
52
  implementation fileTree(dir: 'libs', include: ['*.jar'])
48
53
  implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
49
55
  testImplementation "junit:junit:$junitVersion"
50
56
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
51
57
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
@@ -1,5 +1,3 @@
1
-
2
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
- package="com.getcapacitor.community.tts.texttospeech">
4
- </manifest>
5
-
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.getcapacitor.community.tts">
3
+ </manifest>
@@ -0,0 +1,6 @@
1
+ package com.getcapacitor.community.tts;
2
+
3
+ public interface SpeakResultCallback {
4
+ void onDone();
5
+ void onError();
6
+ }