Skip to content

Commit 7539da7

Browse files
3288: Use main branch react-native-tts and patch deprecated jcenter and new react native architecture support
ak1394/react-native-tts#278 ak1394/react-native-tts#288
1 parent 78f0040 commit 7539da7

File tree

3 files changed

+150
-3
lines changed

3 files changed

+150
-3
lines changed

native/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"lint": "yarn stylelint && eslint --cache --cache-location ../.eslintcache .",
3838
"stylelint": "stylelint --config stylelint.config.js \"src/**/*.{ts,tsx,css}\"",
3939
"license-crawler": "npm-license-crawler -onlyDirectDependencies -json ./src/assets/licenses.json",
40-
"postinstall": "yarn license-crawler",
40+
"postinstall": "patch-package && yarn license-crawler",
4141
"ts:check": "tsc --build",
4242
"prettier:check": "yarn prettier --ignore-path ../.prettierignore --check .",
4343
"prettier:write": "yarn prettier --ignore-path ../.prettierignore --write .",
@@ -89,7 +89,7 @@
8989
"react-native-safe-area-context": "^5.6.1",
9090
"react-native-screens": "^4.18.0",
9191
"react-native-svg": "^15.14.0",
92-
"react-native-tts": "HemantRMali/react-native-tts#patch-1",
92+
"react-native-tts": "^4.1.1",
9393
"react-native-url-polyfill": "^3.0.0",
9494
"react-navigation-header-buttons": "^13.0.0",
9595
"rrule": "^2.8.1",
@@ -120,6 +120,7 @@
120120
"commander": "^14.0.1",
121121
"cross-env": "^10.1.0",
122122
"npm-license-crawler": "^0.2.1",
123+
"patch-package": "^8.0.0",
123124
"postinstall-postinstall": "^2.1.0",
124125
"react-native-svg-transformer": "^1.5.0",
125126
"react-test-renderer": "19.1.1"
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
diff --git a/node_modules/react-native-tts/android/build.gradle b/node_modules/react-native-tts/android/build.gradle
2+
index dbbe046..ab08997 100644
3+
--- a/node_modules/react-native-tts/android/build.gradle
4+
+++ b/node_modules/react-native-tts/android/build.gradle
5+
@@ -3,12 +3,18 @@ def safeExtGet(prop, fallback) {
6+
}
7+
8+
buildscript {
9+
- repositories {
10+
- jcenter()
11+
- }
12+
+ // The Android Gradle plugin is only required when opening the android folder stand-alone.
13+
+ // This avoids unnecessary downloads and potential conflicts when the library is included as a
14+
+ // module dependency in an application project.
15+
+ // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
16+
+ if (project == rootProject) {
17+
+ repositories {
18+
+ google()
19+
+ }
20+
21+
- dependencies {
22+
- classpath 'com.android.tools.build:gradle:1.3.1'
23+
+ dependencies {
24+
+ classpath 'com.android.tools.build:gradle:1.3.1'
25+
+ }
26+
}
27+
}
28+
29+
diff --git a/node_modules/react-native-tts/ios/TextToSpeech/TextToSpeech.m b/node_modules/react-native-tts/ios/TextToSpeech/TextToSpeech.m
30+
index 1e769cc..3ea3767 100644
31+
--- a/node_modules/react-native-tts/ios/TextToSpeech/TextToSpeech.m
32+
+++ b/node_modules/react-native-tts/ios/TextToSpeech/TextToSpeech.m
33+
@@ -38,9 +38,9 @@ -(instancetype)init
34+
return self;
35+
}
36+
37+
-+ (BOOL)requiresMainQueueSetup
38+
++ (bool)requiresMainQueueSetup
39+
{
40+
- return YES;
41+
+ return true;
42+
}
43+
44+
RCT_EXPORT_METHOD(speak:(NSString *)text
45+
@@ -94,7 +94,7 @@ + (BOOL)requiresMainQueueSetup
46+
resolve([NSNumber numberWithUnsignedLong:utterance.hash]);
47+
}
48+
49+
-RCT_EXPORT_METHOD(stop:(BOOL *)onWordBoundary resolve:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject)
50+
+RCT_EXPORT_METHOD(stop:(bool *)onWordBoundary resolve:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject)
51+
{
52+
AVSpeechBoundary boundary;
53+
54+
@@ -104,12 +104,12 @@ + (BOOL)requiresMainQueueSetup
55+
boundary = AVSpeechBoundaryImmediate;
56+
}
57+
58+
- BOOL stopped = [self.synthesizer stopSpeakingAtBoundary:boundary];
59+
+ bool stopped = [self.synthesizer stopSpeakingAtBoundary:boundary];
60+
61+
resolve([NSNumber numberWithBool:stopped]);
62+
}
63+
64+
-RCT_EXPORT_METHOD(pause:(BOOL *)onWordBoundary resolve:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject)
65+
+RCT_EXPORT_METHOD(pause:(bool *)onWordBoundary resolve:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject)
66+
{
67+
AVSpeechBoundary boundary;
68+
69+
@@ -119,20 +119,20 @@ + (BOOL)requiresMainQueueSetup
70+
boundary = AVSpeechBoundaryImmediate;
71+
}
72+
73+
- BOOL paused = [self.synthesizer pauseSpeakingAtBoundary:boundary];
74+
+ bool paused = [self.synthesizer pauseSpeakingAtBoundary:boundary];
75+
76+
resolve([NSNumber numberWithBool:paused]);
77+
}
78+
79+
RCT_EXPORT_METHOD(resume:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject)
80+
{
81+
- BOOL continued = [self.synthesizer continueSpeaking];
82+
+ bool continued = [self.synthesizer continueSpeaking];
83+
84+
resolve([NSNumber numberWithBool:continued]);
85+
}
86+
87+
88+
-RCT_EXPORT_METHOD(setDucking:(BOOL *)ducking
89+
+RCT_EXPORT_METHOD(setDucking:(bool *)ducking
90+
resolve:(RCTPromiseResolveBlock)resolve
91+
reject:(__unused RCTPromiseRejectBlock)reject)
92+
{
93+
@@ -178,7 +178,7 @@ + (BOOL)requiresMainQueueSetup
94+
}
95+
96+
RCT_EXPORT_METHOD(setDefaultRate:(float)rate
97+
- skipTransform:(BOOL *)skipTransform // not used, compatibility with Android native module signature
98+
+ skipTransform:(bool *)skipTransform // not used, compatibility with Android native module signature
99+
resolve:(RCTPromiseResolveBlock)resolve
100+
reject:(RCTPromiseRejectBlock)reject)
101+
{
102+
@@ -232,7 +232,7 @@ + (BOOL)requiresMainQueueSetup
103+
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance
104+
{
105+
if(_ducking) {
106+
- [[AVAudioSession sharedInstance] setActive:YES error:nil];
107+
+ [[AVAudioSession sharedInstance] setActive:true error:nil];
108+
}
109+
110+
[self sendEventWithName:@"tts-start" body:@{@"utteranceId":[NSNumber numberWithUnsignedLong:utterance.hash]}];
111+
@@ -241,7 +241,7 @@ -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUttera
112+
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance
113+
{
114+
if(_ducking) {
115+
- [[AVAudioSession sharedInstance] setActive:NO error:nil];
116+
+ [[AVAudioSession sharedInstance] setActive:false error:nil];
117+
}
118+
119+
[self sendEventWithName:@"tts-finish" body:@{@"utteranceId":[NSNumber numberWithUnsignedLong:utterance.hash]}];
120+
@@ -250,7 +250,7 @@ -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtter
121+
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didPauseSpeechUtterance:(AVSpeechUtterance *)utterance
122+
{
123+
if(_ducking) {
124+
- [[AVAudioSession sharedInstance] setActive:NO error:nil];
125+
+ [[AVAudioSession sharedInstance] setActive:false error:nil];
126+
}
127+
128+
[self sendEventWithName:@"tts-pause" body:@{@"utteranceId":[NSNumber numberWithUnsignedLong:utterance.hash]}];
129+
@@ -259,7 +259,7 @@ -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didPauseSpeechUttera
130+
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didContinueSpeechUtterance:(AVSpeechUtterance *)utterance
131+
{
132+
if(_ducking) {
133+
- [[AVAudioSession sharedInstance] setActive:YES error:nil];
134+
+ [[AVAudioSession sharedInstance] setActive:true error:nil];
135+
}
136+
137+
[self sendEventWithName:@"tts-resume" body:@{@"utteranceId":[NSNumber numberWithUnsignedLong:utterance.hash]}];
138+
@@ -276,7 +276,7 @@ -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer willSpeakRangeOfSpee
139+
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didCancelSpeechUtterance:(AVSpeechUtterance *)utterance
140+
{
141+
if(_ducking) {
142+
- [[AVAudioSession sharedInstance] setActive:NO error:nil];
143+
+ [[AVAudioSession sharedInstance] setActive:false error:nil];
144+
}
145+
146+
[self sendEventWithName:@"tts-cancel" body:@{@"utteranceId":[NSNumber numberWithUnsignedLong:utterance.hash]}];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"prettier:write": "prettier --write .",
3333
"ts:check": "tsc --build",
3434
"ts:check:ci": "yarn node --max-old-space-size=1536 $(yarn bin tsc) --build",
35-
"postinstall": "patch-package"
35+
"postinstall": "yarn workspace native patch-package"
3636
},
3737
"resolutions": {
3838
"luxon": "3.7.2",

0 commit comments

Comments
 (0)