Skip to content

Commit 0d0ce9b

Browse files
committed
feat: adding openVoiceDataInstaller for android
1 parent b840a51 commit 0d0ce9b

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

android/src/main/java/com/speech/SpeechModule.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.util.UUID
44
import java.util.Locale
55
import android.os.Build
66
import android.os.Bundle
7+
import android.content.Intent
78
import android.content.Context
89
import android.speech.tts.Voice
910
import android.media.AudioManager
@@ -553,6 +554,25 @@ class SpeechModule(reactContext: ReactApplicationContext) :
553554
initializeTTS()
554555
}
555556

557+
override fun openVoiceDataInstaller(promise: Promise) {
558+
try {
559+
val activity = currentActivity
560+
if (activity == null) {
561+
promise.reject("ACTIVITY_UNAVAILABLE", "The current activity is not available to launch the installer.")
562+
return
563+
}
564+
val installIntent = Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA)
565+
if (installIntent.resolveActivity(activity.packageManager) != null) {
566+
activity.startActivity(installIntent)
567+
promise.resolve(null)
568+
} else {
569+
promise.reject("UNSUPPORTED_OPERATION", "No activity found to handle TTS voice data installation on this device.")
570+
}
571+
} catch (e: Exception) {
572+
promise.reject("INSTALLER_ERROR", "An unexpected error occurred while trying to open the TTS voice installer.", e)
573+
}
574+
}
575+
556576
override fun invalidate() {
557577
super.invalidate()
558578
if (::synthesizer.isInitialized) {

ios/Speech.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ - (void)getAvailableVoices:(NSString *)language
185185
resolve(voicesArray);
186186
}
187187

188+
- (void)openVoiceDataInstaller:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
189+
resolve(nil);
190+
}
191+
188192
- (void)getEngines:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
189193
resolve(@[]);
190194
}

src/NativeSpeech.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export interface Spec extends TurboModule {
8989
speak: (text: string) => Promise<void>;
9090
getEngines: () => Promise<EngineProps[]>;
9191
initialize: (options: VoiceOptions) => void;
92+
openVoiceDataInstaller: () => Promise<void>;
9293
setEngine: (engineName: string) => Promise<void>;
9394
getAvailableVoices: (language: string) => Promise<VoiceProps[]>;
9495
speakWithOptions: (text: string, options: VoiceOptions) => Promise<void>;

src/Speech.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ export default class Speech {
5050
public static setEngine(engineName: string): Promise<void> {
5151
return TurboSpeech.setEngine(engineName);
5252
}
53+
/**
54+
* Opens the system UI to install or update TTS voice data.
55+
* @returns Promise<void> Resolves when the installer activity has been launched.
56+
* @throws If the installer activity cannot be opened on the device.
57+
* @platform android
58+
*/
59+
public static openVoiceDataInstaller(): Promise<void> {
60+
return TurboSpeech.openVoiceDataInstaller();
61+
}
5362
/**
5463
* Sets the global options for all subsequent speak() calls
5564
* @param options - Voice configuration options

0 commit comments

Comments
 (0)