File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed
android/src/main/java/com/speech Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import java.util.UUID
44import java.util.Locale
55import android.os.Build
66import android.os.Bundle
7+ import android.content.Intent
78import android.content.Context
89import android.speech.tts.Voice
910import 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) {
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 > ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments