*/
private @Nullable GoogleTTSConfig config;
- /**
- * Status flag
- */
- private boolean initialized;
-
private final Gson gson = new GsonBuilder().create();
private final ConfigurationAdmin configAdmin;
private final OAuthFactory oAuthFactory;
void setConfig(GoogleTTSConfig config) {
this.config = config;
+ if (oAuthService != null) {
+ oAuthFactory.ungetOAuthService(GoogleTTSService.SERVICE_PID);
+ oAuthService = null;
+ }
+
String clientId = config.clientId;
String clientSecret = config.clientSecret;
if (clientId != null && !clientId.isEmpty() && clientSecret != null && !clientSecret.isEmpty()) {
+ final OAuthClientService oAuthService = oAuthFactory.createOAuthClientService(GoogleTTSService.SERVICE_PID,
+ GCP_TOKEN_URI, GCP_AUTH_URI, clientId, clientSecret, GCP_SCOPE, false);
+ this.oAuthService = oAuthService;
try {
- final OAuthClientService oAuthService = oAuthFactory.createOAuthClientService(
- GoogleTTSService.SERVICE_PID, GCP_TOKEN_URI, GCP_AUTH_URI, clientId, clientSecret, GCP_SCOPE,
- false);
- this.oAuthService = oAuthService;
getAccessToken();
- initialized = true;
initVoices();
} catch (AuthenticationException | CommunicationException e) {
logger.warn("Error initializing Google Cloud TTS service: {}", e.getMessage());
- oAuthService = null;
- initialized = false;
+ oAuthFactory.ungetOAuthService(GoogleTTSService.SERVICE_PID);
+ this.oAuthService = null;
voices.clear();
}
} else {
- oAuthService = null;
- initialized = false;
voices.clear();
}
}
}
+ public void dispose() {
+ if (oAuthService != null) {
+ oAuthFactory.ungetOAuthService(GoogleTTSService.SERVICE_PID);
+ oAuthService = null;
+ }
+ voices.clear();
+ }
+
/**
* Fetches the OAuth2 tokens from Google Cloud Platform if the auth-code is set in the configuration. If successful
* the auth-code will be removed from the configuration.
return audio;
} catch (AuthenticationException | CommunicationException e) {
logger.warn("Error initializing Google Cloud TTS service: {}", e.getMessage());
- oAuthService = null;
- initialized = false;
+ if (oAuthService != null) {
+ oAuthFactory.ungetOAuthService(GoogleTTSService.SERVICE_PID);
+ oAuthService = null;
+ }
voices.clear();
} catch (FileNotFoundException e) {
logger.warn("Could not write file {} to cache: {}", audioFileInCache, e.getMessage());
}
boolean isInitialized() {
- return initialized;
+ return oAuthService != null;
}
}