@iternio/react-native-tts 4.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 (32) hide show
  1. package/README.md +268 -0
  2. package/TextToSpeech.podspec +21 -0
  3. package/android/build.gradle +41 -0
  4. package/android/src/main/AndroidManifest.xml +2 -0
  5. package/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java +538 -0
  6. package/android/src/main/java/net/no_mad/tts/TextToSpeechPackage.java +31 -0
  7. package/index.d.ts +118 -0
  8. package/index.js +127 -0
  9. package/ios/TextToSpeech/TextToSpeech.h +20 -0
  10. package/ios/TextToSpeech/TextToSpeech.m +285 -0
  11. package/ios/TextToSpeech.xcodeproj/project.pbxproj +276 -0
  12. package/ios/TextToSpeech.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  13. package/ios/TextToSpeech.xcodeproj/project.xcworkspace/xcuserdata/anton.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  14. package/ios/TextToSpeech.xcodeproj/xcuserdata/anton.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +5 -0
  15. package/ios/TextToSpeech.xcodeproj/xcuserdata/anton.xcuserdatad/xcschemes/TextToSpeech.xcscheme +80 -0
  16. package/ios/TextToSpeech.xcodeproj/xcuserdata/anton.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
  17. package/package.json +27 -0
  18. package/windows/README.md +25 -0
  19. package/windows/RNTTS/PropertySheet.props +16 -0
  20. package/windows/RNTTS/RNTTS.cpp +224 -0
  21. package/windows/RNTTS/RNTTS.def +3 -0
  22. package/windows/RNTTS/RNTTS.h +75 -0
  23. package/windows/RNTTS/RNTTS.vcxproj +163 -0
  24. package/windows/RNTTS/RNTTS.vcxproj.filters +33 -0
  25. package/windows/RNTTS/ReactPackageProvider.cpp +15 -0
  26. package/windows/RNTTS/ReactPackageProvider.h +16 -0
  27. package/windows/RNTTS/ReactPackageProvider.idl +9 -0
  28. package/windows/RNTTS/packages.config +4 -0
  29. package/windows/RNTTS/pch.cpp +1 -0
  30. package/windows/RNTTS/pch.h +11 -0
  31. package/windows/RNTTS62.sln +254 -0
  32. package/windows/RNTTS63.sln +226 -0
package/README.md ADDED
@@ -0,0 +1,268 @@
1
+ # React Native TTS
2
+
3
+ React Native TTS is a text-to-speech library for [React Native](https://facebook.github.io/react-native/) on iOS, Android and Windows.
4
+
5
+ ## Documentation
6
+
7
+ - [Install](#install)
8
+ - [Usage](#usage)
9
+ - [License](#license)
10
+ - [Example project](#example)
11
+
12
+ ## Install
13
+
14
+ ```shell
15
+ npm install --save react-native-tts
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ### Imports
21
+
22
+ ```js
23
+ import Tts from 'react-native-tts';
24
+ ```
25
+
26
+ #### Windows
27
+
28
+ 1. In `windows/myapp.sln` add the `RNTTS` project to your solution:
29
+
30
+ - Open the solution in Visual Studio 2019
31
+ - Right-click Solution icon in Solution Explorer > Add > Existing Project
32
+ - Select `node_modules\react-native-tts\windows\RNTTS\RNTTS.vcxproj`
33
+
34
+ 2. In `windows/myapp/myapp.vcxproj` add a reference to `RNTTS` to your main application project. From Visual Studio 2019:
35
+
36
+ - Right-click main application project > Add > Reference...
37
+ - Check `RNTTS` from Solution Projects.
38
+
39
+ 3. In `pch.h` add `#include "winrt/RNTTS.h"`.
40
+
41
+ 4. In `app.cpp` add `PackageProviders().Append(winrt::RNTTS::ReactPackageProvider());` before `InitializeComponent();`.
42
+
43
+ ### Speaking
44
+
45
+ Add utterance to TTS queue and start speaking. Returns promise with utteranceId.
46
+
47
+ ```js
48
+ Tts.speak('Hello, world!');
49
+ ```
50
+
51
+ Additionally, speak() allows to pass platform-specific options.
52
+
53
+ ```js
54
+ // IOS
55
+ Tts.speak('Hello, world!', {
56
+ iosVoiceId: 'com.apple.ttsbundle.Moira-compact',
57
+ rate: 0.5,
58
+ });
59
+ // Android
60
+ Tts.speak('Hello, world!', {
61
+ androidParams: {
62
+ KEY_PARAM_PAN: -1,
63
+ KEY_PARAM_VOLUME: 0.5,
64
+ KEY_PARAM_STREAM: 'STREAM_MUSIC',
65
+ },
66
+ });
67
+ ```
68
+
69
+ For more detail on `androidParams` properties, please take a look at [official android documentation](https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine.html). Please note that there are still unsupported key with this wrapper library such as `KEY_PARAM_SESSION_ID`. The following are brief summarization of currently implemented keys:
70
+
71
+ - `KEY_PARAM_PAN` ranges from `-1` to `+1`.
72
+
73
+ - `KEY_PARAM_VOLUME` ranges from `0` to `1`, where 0 means silence. Note that `1` is a default value for Android.
74
+
75
+ - For `KEY_PARAM_STREAM` property, you can currently use one of `STREAM_ALARM`, `STREAM_DTMF`, `STREAM_MUSIC`, `STREAM_NOTIFICATION`, `STREAM_RING`, `STREAM_SYSTEM`, `STREAM_VOICE_CALL`,
76
+
77
+ The supported options for IOS are:
78
+
79
+ - `iosVoiceId` which voice to use, check [voices()](#list-voices) for available values
80
+ - `rate` which speech rate this line should be spoken with. Will override [default rate](#set-default-speech-rate) if set for this utterance.
81
+
82
+ Stop speaking and flush the TTS queue.
83
+
84
+ ```js
85
+ Tts.stop();
86
+ ```
87
+
88
+ ### Waiting for initialization
89
+
90
+ On some platforms it could take some time to initialize TTS engine, and Tts.speak() will fail to speak until the engine is ready.
91
+
92
+ To wait for successfull initialization you could use getInitStatus() call.
93
+
94
+ ```js
95
+ Tts.getInitStatus().then(() => {
96
+ Tts.speak('Hello, world!');
97
+ });
98
+ ```
99
+
100
+ ### Ducking
101
+
102
+ Enable lowering other applications output level while speaking (also referred to as "ducking").
103
+
104
+ *(not supported on Windows)*
105
+
106
+ ```js
107
+ Tts.setDucking(true);
108
+ ```
109
+
110
+ ### List Voices
111
+
112
+ Returns list of available voices
113
+
114
+ *(not supported on Android API Level < 21, returns empty list)*
115
+
116
+ ```js
117
+ Tts.voices().then(voices => console.log(voices));
118
+
119
+ // Prints:
120
+ //
121
+ // [ { id: 'com.apple.ttsbundle.Moira-compact', name: 'Moira', language: 'en-IE', quality: 300 },
122
+ // ...
123
+ // { id: 'com.apple.ttsbundle.Samantha-compact', name: 'Samantha', language: 'en-US' } ]
124
+ ```
125
+
126
+ |Voice field|Description|
127
+ |-----|-------|
128
+ |id |Unique voice identifier (e.g. `com.apple.ttsbundle.Moira-compact`)|
129
+ |name |Name of the voice *(iOS only)*|
130
+ |language|BCP-47 language code (e.g. 'en-US')|
131
+ |quality|Voice quality (300 = normal, 500 = enhanced/very high)|
132
+ |latency|Expected synthesizer latency (100 = very low, 500 = very high) *(Android only)*|
133
+ |networkConnectionRequired|True when the voice requires an active network connection *(Android only)*|
134
+ |notInstalled|True when the voice may need to download additional data to be fully functional *(Android only)*|
135
+
136
+
137
+ ### Set default Language
138
+
139
+ ```js
140
+ Tts.setDefaultLanguage('en-IE');
141
+ ```
142
+
143
+ ### Set default Voice
144
+
145
+ Sets default voice, pass one of the voiceId as reported by a call to Tts.voices()
146
+
147
+ *(not available on Android API Level < 21)*
148
+
149
+ ```js
150
+ Tts.setDefaultVoice('com.apple.ttsbundle.Moira-compact');
151
+ ```
152
+
153
+ ### Set default Speech Rate
154
+
155
+ Sets default speech rate. The rate parameter is a float where where 0.01 is a slowest rate and 0.99 is the fastest rate.
156
+
157
+ ```js
158
+ Tts.setDefaultRate(0.6);
159
+ ```
160
+
161
+ There is a significant difference to how the rate value is interpreted by iOS, Android and Windows native TTS APIs. To provide unified cross-platform behaviour, translation is applied to the rate value. However, if you want to turn off the translation, you can provide optional `skipTransform` parameter to `Tts.setDefaultRate()` to pass rate value unmodified.
162
+
163
+ Do not translate rate parameter:
164
+
165
+ ```js
166
+ Tts.setDefaultRate(0.6, true);
167
+ ```
168
+
169
+ ### Set default Pitch
170
+
171
+ Sets default pitch. The pitch parameter is a float where where 1.0 is a normal pitch. On iOS min pitch is 0.5 and max pitch is 2.0. On Windows, min pitch is 0.0 and max pitch is 2.0.
172
+
173
+ ```js
174
+ Tts.setDefaultPitch(1.5);
175
+ ```
176
+
177
+ ### Controls the iOS silent switch behavior
178
+
179
+ Platforms: iOS
180
+
181
+ - "inherit" (default) - Use the default behavior
182
+ - "ignore" - Play audio even if the silent switch is set
183
+ - "obey" - Don't play audio if the silent switch is set
184
+
185
+ ```js
186
+ Tts.setIgnoreSilentSwitch("ignore");
187
+ ```
188
+
189
+ ### Events
190
+
191
+ Subscribe to TTS events
192
+
193
+ ```js
194
+ Tts.addEventListener('tts-start', (event) => console.log("start", event));
195
+ Tts.addEventListener('tts-progress', (event) => console.log("progress", event));
196
+ Tts.addEventListener('tts-finish', (event) => console.log("finish", event));
197
+ Tts.addEventListener('tts-cancel', (event) => console.log("cancel", event));
198
+ ```
199
+
200
+ ### Support for multiple TTS engines
201
+
202
+ Platforms: Android
203
+
204
+ Functions to list available TTS engines and set an engine to use.
205
+
206
+ ```js
207
+ Tts.engines().then(engines => console.log(engines));
208
+ Tts.setDefaultEngine('engineName');
209
+ ```
210
+
211
+ ### Install (additional) language data
212
+
213
+ Shows the Android Activity to install additional language/voice data.
214
+
215
+ ```js
216
+ Tts.requestInstallData();
217
+ ```
218
+
219
+ ## Troubleshooting
220
+
221
+ ### No text to speech engine installed on Android
222
+
223
+ On Android, it may happen that the Text-to-Speech engine is not (yet) installed on the phone.
224
+ When this is the case, `Tts.getInitStatus()` returns an error with code `no_engine`.
225
+ You can use the following code to request the installation of the default Google Text to Speech App.
226
+ The app will need to be restarted afterwards before the changes take affect.
227
+
228
+ ```js
229
+ Tts.getInitStatus().then(() => {
230
+ // ...
231
+ }, (err) => {
232
+ if (err.code === 'no_engine') {
233
+ Tts.requestInstallEngine();
234
+ }
235
+ });
236
+ ```
237
+
238
+ ## Example
239
+
240
+ There is an example project which shows use of react-native-tts on Android/iOS/Windows: https://github.com/themostaza/react-native-tts-example
241
+
242
+ ## License
243
+
244
+ The MIT License (MIT)
245
+ =====================
246
+
247
+ Copyright © `2016` `Anton Krasovsky`
248
+
249
+ Permission is hereby granted, free of charge, to any person
250
+ obtaining a copy of this software and associated documentation
251
+ files (the “Software”), to deal in the Software without
252
+ restriction, including without limitation the rights to use,
253
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
254
+ copies of the Software, and to permit persons to whom the
255
+ Software is furnished to do so, subject to the following
256
+ conditions:
257
+
258
+ The above copyright notice and this permission notice shall be
259
+ included in all copies or substantial portions of the Software.
260
+
261
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
262
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
263
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
264
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
265
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
266
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
267
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
268
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "TextToSpeech"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+
10
+ s.homepage = package["homepage"]
11
+
12
+ s.license = package["license"]
13
+ s.authors = package["author"]
14
+ s.platform = :ios, "9.0"
15
+
16
+ s.source = { :git => "https://github.com/Iternio-Planning-AB/react-native-tts.git" }
17
+
18
+ s.source_files = "ios/TextToSpeech/*.{h,m}"
19
+
20
+ s.dependency 'React-Core'
21
+ end
@@ -0,0 +1,41 @@
1
+ def safeExtGet(prop, fallback) {
2
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
3
+ }
4
+
5
+ buildscript {
6
+ // The Android Gradle plugin is only required when opening the android folder stand-alone.
7
+ // This avoids unnecessary downloads and potential conflicts when the library is included as a
8
+ // module dependency in an application project.
9
+ // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
10
+ if (project == rootProject) {
11
+ repositories {
12
+ google()
13
+ }
14
+
15
+ dependencies {
16
+ classpath 'com.android.tools.build:gradle:1.3.1'
17
+ }
18
+ }
19
+ }
20
+
21
+ apply plugin: 'com.android.library'
22
+
23
+ android {
24
+ compileSdkVersion safeExtGet('compileSdkVersion', 26)
25
+ buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')
26
+
27
+ defaultConfig {
28
+ minSdkVersion safeExtGet('minSdkVersion', 16)
29
+ targetSdkVersion safeExtGet('targetSdkVersion', 26)
30
+ versionCode 1
31
+ versionName "1.0"
32
+ }
33
+ }
34
+
35
+ repositories {
36
+ mavenCentral()
37
+ }
38
+
39
+ dependencies {
40
+ implementation 'com.facebook.react:react-native:+'
41
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.no_mad.tts">
2
+ </manifest>