if (registrationComplete) throw new IllegalStateException("cannot register modules after registration is complete"); MaryDataType type = module.inputType(); Object o = mkm.get(type, locale, voice); List<MaryModule> l; MaryDataType.registerDataType(module.outputType());
logger.info("Handling request using the following modules:"); for (MaryModule m : neededModules) { logger.info("- " + m.name() + " (" + m.getClass().getName() + ")"); if (abortRequested) break; if (m.getState() == MaryModule.MODULE_OFFLINE) { logger.info("Starting module " + m.name()); m.startup(); assert m.getState() == MaryModule.MODULE_RUNNING; if (m.outputType() == MaryDataType.get("AUDIO")) { currentData.setAudioFileFormat(audioFileFormat); currentData.setAudio(new AppendableSequenceAudioInputStream(audioFileFormat.getFormat(), null)); if (m.outputType() == oneOutputType || m.outputType() == MaryDataType.AUDIO) { currentData.setOutputParams(outputParams); logger.info("Next module: " + m.name()); MaryData outData = null; try { outData = m.process(currentData); } catch (Exception e) { throw new Exception("Module " + m.name() + ": Problem processing the data.", e); throw new NullPointerException("Module " + m.name() + " returned null. This should not happen.");
ModuleRegistry.registerModule(m, m.getLocale(), null); && m.getState() == MaryModule.MODULE_OFFLINE) { long before = System.currentTimeMillis(); try { m.startup(); } catch (Throwable t) { throw new Exception("Problem starting module " + m.name(), t); m.powerOnSelfTest(); logger.debug("Startup times:"); for (Pair<MaryModule, Long> p : startupTimes) { logger.debug(p.getFirst().name() + ": " + p.getSecond() + " ms");
+ " is not in the standard list of modules -- will start our own, but will not be able to shut it down at the end."); mm = ModuleRegistry.instantiateModule(moduleInfo); mm.startup(); for (Iterator<MaryModule> it = preferredModules.iterator(); it.hasNext();) { MaryModule m = (MaryModule) it.next(); if (m.inputType().equals(type)) { v.add(m);
/** * Orderly shut down the MARY system. * * @throws IllegalStateException * if the MARY system is not running. */ public static void shutdown() { if (currentState != STATE_RUNNING) throw new IllegalStateException("MARY system is not running"); currentState = STATE_SHUTTING_DOWN; logger.info("Shutting down modules..."); // Shut down modules: for (MaryModule m : ModuleRegistry.getAllModules()) { if (m.getState() == MaryModule.MODULE_RUNNING) m.shutdown(); } if (MaryCache.haveCache()) { MaryCache cache = MaryCache.getCache(); try { cache.shutdown(); } catch (SQLException e) { logger.warn("Cannot shutdown cache: ", e); } } logger.info("Shutdown complete."); currentState = STATE_OFF; }
protected void processAndCompare(String basename, Locale locale) throws Exception { assert inputEnding() != null; assert outputEnding() != null; MaryData input = null; if (inputEnding().equals("txt")) { String in = loadResourceIntoString(basename + "." + inputEnding()); input = createMaryDataFromText(in, locale); } else { input = new MaryData(module.inputType(), locale); input.readFrom(this.getClass().getResourceAsStream(basename + "." + inputEnding()), null); } MaryData targetOut = new MaryData(module.outputType(), input.getLocale()); targetOut.readFrom(this.getClass().getResourceAsStream(basename + "." + outputEnding()), null); MaryData processedOut = module.process(input); try { DomUtils.compareNodes(targetOut.getDocument(), processedOut.getDocument(), true); } catch (Exception afe) { StringBuilder msg = new StringBuilder(); msg.append("XML documents are not equal\n"); msg.append("==========target:=============\n"); Document target = (Document) targetOut.getDocument().cloneNode(true); DomUtils.trimAllTextNodes(target); msg.append(DomUtils.document2String(target)).append("\n\n"); msg.append("==========processed:============\n"); Document processed = (Document) processedOut.getDocument().cloneNode(true); DomUtils.trimAllTextNodes(processed); msg.append(DomUtils.document2String(processed)).append("\n"); throw new Exception(msg.toString(), afe); } }
MaryDataType outputType = candidate.outputType(); logger.debug("Module " + candidate.name() + " converts " + sourceType.name() + " into " + outputType + " (locale " + locale + ", voice " + voice + ")");
@Test public void testSystemPreferredModuleOverride() throws Exception { List<MaryModule> mod = ModuleRegistry.getPreferredModulesForInputType(MaryDataType.TEXT); assertNotNull(mod); assert (!mod.isEmpty()); assertEquals(mod.get(0).name(), "Dummy"); } }
/** * Provide a list containing preferred modules for the specified input type * * @param wanted_input_type * the specified input type * @return the list of system wide preferred modules, null if none */ public static synchronized List<MaryModule> getPreferredModulesForInputType(MaryDataType wanted_input_type) { if (preferredModules != null) { List<MaryModule> v = new ArrayList<MaryModule>(); for (Iterator<MaryModule> it = preferredModules.iterator(); it.hasNext();) { MaryModule m = (MaryModule) it.next(); if (m.inputType().equals(wanted_input_type)) { v.add(m); } } if (v.size() > 0) return v; else return null; } return null; }
public void startup() throws Exception { super.startup(); // We depend on the Synthesis module: MaryModule synthesis; try { synthesis = ModuleRegistry.getModule(marytts.modules.Synthesis.class); } catch (NullPointerException npe) { synthesis = new Synthesis(); } assert synthesis != null; if (synthesis.getState() == MaryModule.MODULE_OFFLINE) synthesis.startup(); // load klatt rules klattRuleParams = new Properties(); klattRuleParams.load(new FileInputStream(MaryProperties.needFilename(localePrefix + ".cap.klattrulefile"))); // load phone list allophoneSet = MaryRuntimeUtils.needAllophoneSet(localePrefix + ".allophoneset"); klattDurationParams = new KlattDurationModeller.KlattDurationParams(MaryProperties.needFilename(localePrefix + ".cap.klattdurfile")); // instantiate the Map in which settings are associated with elements: // (when the objects serving as keys are not in ordinary use any more, // the key-value pairs are deleted from the WeakHashMap earlier or // later; that means we do not need to keep track of the hashmaps per // thread) prosodyMap = new WeakHashMap(); }
if (list != null) { for (MaryModule m : list) { if (!results.containsKey(m.outputType())) results.put(m.outputType(), m);
protected void processAndCompare(String basename, Locale locale) throws Exception { assert inputEnding() != null; assert outputEnding() != null; MaryData input = null; if (inputEnding().equals("txt")) { String in = loadResourceIntoString(basename + "." + inputEnding()); input = createMaryDataFromText(in, locale); } else { input = new MaryData(module.inputType(), locale); input.readFrom(this.getClass().getResourceAsStream(basename + "." + inputEnding()), null); } MaryData targetOut = new MaryData(module.outputType(), input.getLocale()); targetOut.readFrom(this.getClass().getResourceAsStream(basename + "." + outputEnding()), null); MaryData processedOut = module.process(input); try { DomUtils.compareNodes(targetOut.getDocument(), processedOut.getDocument(), true); } catch (Exception afe) { StringBuilder msg = new StringBuilder(); msg.append("XML documents are not equal\n"); msg.append("==========target:=============\n"); Document target = (Document) targetOut.getDocument().cloneNode(true); DomUtils.trimAllTextNodes(target); msg.append(DomUtils.document2String(target)).append("\n\n"); msg.append("==========processed:============\n"); Document processed = (Document) processedOut.getDocument().cloneNode(true); DomUtils.trimAllTextNodes(processed); msg.append(DomUtils.document2String(processed)).append("\n"); throw new Exception(msg.toString(), afe); } }
MaryDataType outputType = candidate.outputType(); logger.debug("Module " + candidate.name() + " converts " + sourceType.name() + " into " + outputType + " (locale " + locale + ", voice " + voice + ")");
+ " is not in the standard list of modules -- will start our own, but will not be able to shut it down at the end."); mm = ModuleRegistry.instantiateModule(moduleInfo); mm.startup(); for (Iterator<MaryModule> it = preferredModules.iterator(); it.hasNext();) { MaryModule m = (MaryModule) it.next(); if (m.inputType().equals(type)) { v.add(m);
@Test public void testSystemPreferredModuleOverride() throws Exception { List<MaryModule> mod = ModuleRegistry.getPreferredModulesForInputType(MaryDataType.TEXT); assertNotNull(mod); assert (!mod.isEmpty()); assertEquals(mod.get(0).name(), "Dummy"); } }
/** * Provide a list containing preferred modules for the specified input type * * @param wanted_input_type * the specified input type * @return the list of system wide preferred modules, null if none */ public static synchronized List<MaryModule> getPreferredModulesForInputType(MaryDataType wanted_input_type) { if (preferredModules != null) { List<MaryModule> v = new ArrayList<MaryModule>(); for (Iterator<MaryModule> it = preferredModules.iterator(); it.hasNext();) { MaryModule m = (MaryModule) it.next(); if (m.inputType().equals(wanted_input_type)) { v.add(m); } } if (v.size() > 0) return v; else return null; } return null; }
public void startup() throws Exception { super.startup(); // We depend on the Synthesis module: MaryModule synthesis; try { synthesis = ModuleRegistry.getModule(marytts.modules.Synthesis.class); } catch (NullPointerException npe) { synthesis = new Synthesis(); } assert synthesis != null; if (synthesis.getState() == MaryModule.MODULE_OFFLINE) synthesis.startup(); // load klatt rules klattRuleParams = new Properties(); klattRuleParams.load(new FileInputStream(MaryProperties.needFilename(localePrefix + ".cap.klattrulefile"))); // load phone list allophoneSet = MaryRuntimeUtils.needAllophoneSet(localePrefix + ".allophoneset"); klattDurationParams = new KlattDurationModeller.KlattDurationParams(MaryProperties.needFilename(localePrefix + ".cap.klattdurfile")); // instantiate the Map in which settings are associated with elements: // (when the objects serving as keys are not in ordinary use any more, // the key-value pairs are deleted from the WeakHashMap earlier or // later; that means we do not need to keep track of the hashmaps per // thread) prosodyMap = new WeakHashMap(); }
/** * Orderly shut down the MARY system. * * @throws IllegalStateException * if the MARY system is not running. */ public static void shutdown() { if (currentState != STATE_RUNNING) throw new IllegalStateException("MARY system is not running"); currentState = STATE_SHUTTING_DOWN; logger.info("Shutting down modules..."); // Shut down modules: for (MaryModule m : ModuleRegistry.getAllModules()) { if (m.getState() == MaryModule.MODULE_RUNNING) m.shutdown(); } if (MaryCache.haveCache()) { MaryCache cache = MaryCache.getCache(); try { cache.shutdown(); } catch (SQLException e) { logger.warn("Cannot shutdown cache: ", e); } } logger.info("Shutdown complete."); currentState = STATE_OFF; }
if (list != null) { for (MaryModule m : list) { if (!results.containsKey(m.outputType())) results.put(m.outputType(), m);
logger.info("Handling request using the following modules:"); for (MaryModule m : neededModules) { logger.info("- " + m.name() + " (" + m.getClass().getName() + ")"); if (abortRequested) break; if (m.getState() == MaryModule.MODULE_OFFLINE) { logger.info("Starting module " + m.name()); m.startup(); assert m.getState() == MaryModule.MODULE_RUNNING; if (m.outputType() == MaryDataType.get("AUDIO")) { currentData.setAudioFileFormat(audioFileFormat); currentData.setAudio(new AppendableSequenceAudioInputStream(audioFileFormat.getFormat(), null)); if (m.outputType() == oneOutputType || m.outputType() == MaryDataType.AUDIO) { currentData.setOutputParams(outputParams); logger.info("Next module: " + m.name()); MaryData outData = null; try { outData = m.process(currentData); } catch (Exception e) { throw new Exception("Module " + m.name() + ": Problem processing the data.", e); throw new NullPointerException("Module " + m.name() + " returned null. This should not happen.");