List of usage examples for java.lang Process getOutputStream
public abstract OutputStream getOutputStream();
From source file:marytts.tools.voiceimport.HTKLabeler.java
/** * Feature Extraction for HTK Training //w w w .j av a 2s .c o m * @throws Exception */ private void featureExtraction() throws Exception { String hcopy = getProp(HTKDIR) + File.separator + "HCopy"; File htkFile = new File(hcopy); if (!htkFile.exists()) { throw new RuntimeException("File " + htkFile.getAbsolutePath() + " does not exist"); } String configFile = getProp(HTDIR) + File.separator + "config" + File.separator + "featEx.conf"; String listFile = getProp(HTDIR) + File.separator + "etc" + File.separator + "featEx.list"; Runtime rtime = Runtime.getRuntime(); //get a shell Process process = rtime.exec("/bin/bash"); //get an output stream to write to the shell PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); System.out.println("( cd " + getProp(HTDIR) + "; " + hcopy + " -T 1 -C " + configFile + " -S " + listFile + " > log_featureExtraction.txt" + "; exit )\n"); pw.print("( cd " + getProp(HTDIR) + "; " + hcopy + " -T 1 -C " + configFile + " -S " + listFile + " > log_featureExtraction.txt" + "; exit )\n"); pw.flush(); //shut down pw.close(); process.waitFor(); // check exit value if (process.exitValue() != 0) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); throw new MaryConfigurationException(errorReader.readLine()); } }
From source file:ch.kostceco.tools.kostval.validation.modulejp2.impl.ValidationAvalidationAModuleImpl.java
@Override public boolean validate(File valDatei, File directoryOfLogfile) throws ValidationAjp2validationException { // Start mit der Erkennung // Eine JP2 Datei (.jp2) muss mit ....jP ...ftypjp2 // [0000000c6a5020200d0a870a] beginnen if (valDatei.isDirectory()) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_A_JP2_ISDIRECTORY)); return false; } else if ((valDatei.getAbsolutePath().toLowerCase().endsWith(".jp2"))) { FileReader fr = null;//from w w w . j a v a 2 s. c om try { fr = new FileReader(valDatei); BufferedReader read = new BufferedReader(fr); // wobei hier nur die ersten 10 Zeichen der Datei ausgelesen werden // 1 00 010203 // 2 0c 04 // 3 6a 05 // 4 50 06 // 5 20 0708 // 6 0d 09 // 7 0a 10 // Hex 00 in Char umwandeln String str1 = "00"; int i1 = Integer.parseInt(str1, 16); char c1 = (char) i1; // Hex 0c in Char umwandeln String str2 = "0c"; int i2 = Integer.parseInt(str2, 16); char c2 = (char) i2; // Hex 6a in Char umwandeln String str3 = "6a"; int i3 = Integer.parseInt(str3, 16); char c3 = (char) i3; // Hex 50 in Char umwandeln String str4 = "50"; int i4 = Integer.parseInt(str4, 16); char c4 = (char) i4; // Hex 20 in Char umwandeln String str5 = "20"; int i5 = Integer.parseInt(str5, 16); char c5 = (char) i5; // Hex 0d in Char umwandeln String str6 = "0d"; int i6 = Integer.parseInt(str6, 16); char c6 = (char) i6; // Hex 0a in Char umwandeln String str7 = "0a"; int i7 = Integer.parseInt(str7, 16); char c7 = (char) i7; // auslesen der ersten 10 Zeichen der Datei int length; int i; char[] buffer = new char[10]; length = read.read(buffer); for (i = 0; i != length; i++) ; /* die beiden charArrays (soll und ist) mit einander vergleichen IST = c1c1c1c2c3c4c5c5c6c7 */ char[] charArray1 = buffer; char[] charArray2 = new char[] { c1, c1, c1, c2, c3, c4, c5, c5, c6, c7 }; if (Arrays.equals(charArray1, charArray2)) { /* hchstwahrscheinlich ein JP2 da es mit 0000000c6a5020200d0a respektive ....jP .. * beginnt */ } else { // TODO: Droid-Erkennung, damit Details ausgegeben werden knnen String nameOfSignature = getConfigurationService().getPathToDroidSignatureFile(); if (nameOfSignature == null) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(MESSAGE_XML_CONFIGURATION_ERROR_NO_SIGNATURE)); return false; } // existiert die SignatureFile am angebenen Ort? File fnameOfSignature = new File(nameOfSignature); if (!fnameOfSignature.exists()) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(MESSAGE_XML_CA_DROID)); return false; } Droid droid = null; try { /* kleiner Hack, weil die Droid libraries irgendwo ein System.out drin haben, welche den * Output stren Util.switchOffConsole() als Kommentar markieren wenn man die * Fehlermeldung erhalten mchte */ Util.switchOffConsole(); droid = new Droid(); droid.readSignatureFile(nameOfSignature); } catch (Exception e) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_CANNOT_INITIALIZE_DROID)); return false; } finally { Util.switchOnConsole(); } File file = valDatei; String puid = ""; IdentificationFile ifile = droid.identify(file.getAbsolutePath()); for (int x = 0; x < ifile.getNumHits(); x++) { FileFormatHit ffh = ifile.getHit(x); FileFormat ff = ffh.getFileFormat(); puid = ff.getPUID(); } getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_A_JP2_INCORRECTFILE, puid)); return false; } } catch (Exception e) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_A_JP2_INCORRECTFILE)); return false; } } else { // die Datei endet nicht mit jp2 -> Fehler getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_A_JP2_INCORRECTFILEENDING)); return false; } // Ende der Erkennung boolean isValid = false; // TODO: Erledigt - Initialisierung Jpylyzer -> existiert Jpylyzer? String pathToJpylyzerExe = "resources" + File.separator + "jpylyzer" + File.separator + "jpylyzer.exe"; File fJpylyzerExe = new File(pathToJpylyzerExe); if (!fJpylyzerExe.exists()) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_A_JP2_JPYLYZER_MISSING)); } pathToJpylyzerExe = "\"" + pathToJpylyzerExe + "\""; try { File report; Document doc = null; try { // jpylyzer-Befehl: pathToJpylyzerExe valDatei > valDatei.jpylyzer-log.xml String outputPath = directoryOfLogfile.getAbsolutePath(); String outputName = File.separator + valDatei.getName() + ".jpylyzer-log.xml"; String pathToJpylyzerReport = outputPath + outputName; File output = new File(pathToJpylyzerReport); Runtime rt = Runtime.getRuntime(); Process proc = null; try { report = output; // falls das File bereits existiert, z.B. von einem vorhergehenden Durchlauf, lschen wir // es if (report.exists()) { report.delete(); } /* Das redirect Zeichen verunmglicht eine direkte eingabe. mit dem geschachtellten Befehl * gehts: cmd /c\"urspruenlicher Befehl\" */ String command = "cmd /c \"" + pathToJpylyzerExe + " \"" + valDatei.getAbsolutePath() + "\" > \"" + output.getAbsolutePath() + "\"\""; proc = rt.exec(command.toString().split(" ")); // .split(" ") ist notwendig wenn in einem Pfad ein Doppelleerschlag vorhanden ist! // Warte, bis proc fertig ist proc.waitFor(); } catch (Exception e) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_A_JP2_SERVICEFAILED, e.getMessage())); return false; } finally { if (proc != null) { closeQuietly(proc.getOutputStream()); closeQuietly(proc.getInputStream()); closeQuietly(proc.getErrorStream()); } } if (report.exists()) { // alles io } else { // Datei nicht angelegt... getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_A_JP2_NOREPORT)); return false; } // Ende Jpylyzer direkt auszulsen // TODO: Erledigt - Ergebnis auslesen BufferedInputStream bis = new BufferedInputStream(new FileInputStream(pathToJpylyzerReport)); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(bis); doc.normalize(); NodeList nodeLstI = doc.getElementsByTagName("isValidJP2"); // Node isValidJP2 enthlt im TextNode das Resultat TextNode ist ein ChildNode for (int s = 0; s < nodeLstI.getLength(); s++) { Node resultNode = nodeLstI.item(s); StringBuffer buf = new StringBuffer(); NodeList children = resultNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node textChild = children.item(i); if (textChild.getNodeType() != Node.TEXT_NODE) { continue; } buf.append(textChild.getNodeValue()); } String result = buf.toString(); // Das Resultat ist False oder True if (result.equalsIgnoreCase("True")) { // valid isValid = true; } else { // invalide getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_A_JP2_JPYLYZER_FAIL)); isValid = false; } } } catch (Exception e) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); return false; } // TODO: Erledigt: Fehler Auswertung if (!isValid) { // Invalide JP2-Datei int isignatureBox = 0; int ifileTypeBox = 0; int iimageHeaderBox = 0; int ibitsPerComponentBox = 0; int icolourSpecificationBox = 0; int ipaletteBox = 0; int icomponentMappingBox = 0; int ichannelDefinitionBox = 0; int iresolutionBox = 0; int itileParts = 0; int isiz = 0; int icod = 0; int iqcd = 0; int icoc = 0; int icom = 0; int iqcc = 0; int irgn = 0; int ipoc = 0; int iplm = 0; int ippm = 0; int itlm = 0; int icrg = 0; int iplt = 0; int ippt = 0; int ixmlBox = 0; int iuuidBox = 0; int iuuidInfoBox = 0; int iunknownBox = 0; int icontainsImageHeaderBox = 0; int icontainsColourSpecificationBox = 0; int icontainsBitsPerComponentBox = 0; int ifirstJP2HeaderBoxIsImageHeaderBox = 0; int inoMoreThanOneImageHeaderBox = 0; int inoMoreThanOneBitsPerComponentBox = 0; int inoMoreThanOnePaletteBox = 0; int inoMoreThanOneComponentMappingBox = 0; int inoMoreThanOneChannelDefinitionBox = 0; int inoMoreThanOneResolutionBox = 0; int icolourSpecificationBoxesAreContiguous = 0; int ipaletteAndComponentMappingBoxesOnlyTogether = 0; int icodestreamStartsWithSOCMarker = 0; int ifoundSIZMarker = 0; int ifoundCODMarker = 0; int ifoundQCDMarker = 0; int iquantizationConsistentWithLevels = 0; int ifoundExpectedNumberOfTiles = 0; int ifoundExpectedNumberOfTileParts = 0; int ifoundEOCMarker = 0; NodeList nodeLstTest = doc.getElementsByTagName("tests"); // Node test enthlt alle invaliden tests for (int s = 0; s < nodeLstTest.getLength(); s++) { Node testNode = nodeLstTest.item(s); NodeList children = testNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node textChild = children.item(i); if (textChild.getNodeType() == Node.ELEMENT_NODE) { if (textChild.getNodeName().equals("signatureBox")) { isignatureBox = isignatureBox + 1; } else if (textChild.getNodeName().equals("fileTypeBox")) { ifileTypeBox = ifileTypeBox + 1; } else if (textChild.getNodeName().equals("jp2HeaderBox")) { NodeList childrenII = textChild.getChildNodes(); for (int j = 0; j < childrenII.getLength(); j++) { Node textChildII = childrenII.item(j); if (textChildII.getNodeType() == Node.ELEMENT_NODE) { if (textChildII.getNodeName().equals("imageHeaderBox")) { iimageHeaderBox = iimageHeaderBox + 1; } else if (textChildII.getNodeName().equals("bitsPerComponentBox")) { ibitsPerComponentBox = ibitsPerComponentBox + 1; } else if (textChildII.getNodeName().equals("colourSpecificationBox")) { icolourSpecificationBox = icolourSpecificationBox + 1; } else if (textChildII.getNodeName().equals("paletteBox")) { ipaletteBox = ipaletteBox + 1; } else if (textChildII.getNodeName().equals("componentMappingBox")) { icomponentMappingBox = icomponentMappingBox + 1; } else if (textChildII.getNodeName().equals("channelDefinitionBox")) { ichannelDefinitionBox = ichannelDefinitionBox + 1; } else if (textChildII.getNodeName().equals("resolutionBox")) { iresolutionBox = iresolutionBox + 1; } else if (textChildII.getNodeName().equals("containsImageHeaderBox")) { icontainsImageHeaderBox = icontainsImageHeaderBox + 1; } else if (textChildII.getNodeName() .equals("containsColourSpecificationBox")) { icontainsColourSpecificationBox = icontainsColourSpecificationBox + 1; } else if (textChildII.getNodeName() .equals("containsBitsPerComponentBox")) { icontainsBitsPerComponentBox = icontainsBitsPerComponentBox + 1; } else if (textChildII.getNodeName() .equals("firstJP2HeaderBoxIsImageHeaderBox")) { ifirstJP2HeaderBoxIsImageHeaderBox = ifirstJP2HeaderBoxIsImageHeaderBox + 1; } else if (textChildII.getNodeName() .equals("noMoreThanOneImageHeaderBox")) { inoMoreThanOneImageHeaderBox = inoMoreThanOneImageHeaderBox + 1; } else if (textChildII.getNodeName() .equals("noMoreThanOneBitsPerComponentBox")) { inoMoreThanOneBitsPerComponentBox = inoMoreThanOneBitsPerComponentBox + 1; } else if (textChildII.getNodeName().equals("noMoreThanOnePaletteBox")) { inoMoreThanOnePaletteBox = inoMoreThanOnePaletteBox + 1; } else if (textChildII.getNodeName() .equals("noMoreThanOneComponentMappingBox")) { inoMoreThanOneComponentMappingBox = inoMoreThanOneComponentMappingBox + 1; } else if (textChildII.getNodeName() .equals("noMoreThanOneChannelDefinitionBox")) { inoMoreThanOneChannelDefinitionBox = inoMoreThanOneChannelDefinitionBox + 1; } else if (textChildII.getNodeName().equals("noMoreThanOneResolutionBox")) { inoMoreThanOneResolutionBox = inoMoreThanOneResolutionBox + 1; } else if (textChildII.getNodeName() .equals("colourSpecificationBoxesAreContiguous")) { icolourSpecificationBoxesAreContiguous = icolourSpecificationBoxesAreContiguous + 1; } else if (textChildII.getNodeName() .equals("paletteAndComponentMappingBoxesOnlyTogether")) { ipaletteAndComponentMappingBoxesOnlyTogether = ipaletteAndComponentMappingBoxesOnlyTogether + 1; } } continue; } } else if (textChild.getNodeName().equals("contiguousCodestreamBox")) { NodeList childrenIII = textChild.getChildNodes(); for (int k = 0; k < childrenIII.getLength(); k++) { Node textChildIII = childrenIII.item(k); if (textChildIII.getNodeType() == Node.ELEMENT_NODE) { if (textChildIII.getNodeName().equals("tileParts")) { itileParts = itileParts + 1; } else if (textChildIII.getNodeName().equals("siz")) { isiz = isiz + 1; } else if (textChildIII.getNodeName().equals("cod")) { icod = icod + 1; } else if (textChildIII.getNodeName().equals("qcd")) { iqcd = iqcd + 1; } else if (textChildIII.getNodeName().equals("coc")) { icoc = icoc + 1; } else if (textChildIII.getNodeName().equals("com")) { icom = icom + 1; } else if (textChildIII.getNodeName().equals("qcc")) { iqcc = iqcc + 1; } else if (textChildIII.getNodeName().equals("rgn")) { irgn = irgn + 1; } else if (textChildIII.getNodeName().equals("poc")) { ipoc = ipoc + 1; } else if (textChildIII.getNodeName().equals("plm")) { iplm = iplm + 1; } else if (textChildIII.getNodeName().equals("ppm")) { ippm = ippm + 1; } else if (textChildIII.getNodeName().equals("tlm")) { itlm = itlm + 1; } else if (textChildIII.getNodeName().equals("crg")) { icrg = icrg + 1; } else if (textChildIII.getNodeName().equals("plt")) { iplt = iplt + 1; } else if (textChildIII.getNodeName().equals("ppt")) { ippt = ippt + 1; } else if (textChildIII.getNodeName() .equals("codestreamStartsWithSOCMarker")) { icodestreamStartsWithSOCMarker = icodestreamStartsWithSOCMarker + 1; } else if (textChildIII.getNodeName().equals("foundSIZMarker")) { ifoundSIZMarker = ifoundSIZMarker + 1; } else if (textChildIII.getNodeName().equals("foundCODMarker")) { ifoundCODMarker = ifoundCODMarker + 1; } else if (textChildIII.getNodeName().equals("foundQCDMarker")) { ifoundQCDMarker = ifoundQCDMarker + 1; } else if (textChildIII.getNodeName() .equals("quantizationConsistentWithLevels")) { iquantizationConsistentWithLevels = iquantizationConsistentWithLevels + 1; } else if (textChildIII.getNodeName() .equals("foundExpectedNumberOfTiles")) { ifoundExpectedNumberOfTiles = ifoundExpectedNumberOfTiles + 1; } else if (textChildIII.getNodeName() .equals("foundExpectedNumberOfTileParts")) { ifoundExpectedNumberOfTileParts = ifoundExpectedNumberOfTileParts + 1; } else if (textChildIII.getNodeName().equals("foundEOCMarker")) { ifoundEOCMarker = ifoundEOCMarker + 1; } } continue; } } else if (textChild.getNodeName().equals("xmlBox")) { ixmlBox = ixmlBox + 1; } else if (textChild.getNodeName().equals("uuidBox")) { iuuidBox = iuuidBox + 1; } else if (textChild.getNodeName().equals("uuidInfoBox")) { iuuidInfoBox = iuuidInfoBox + 1; } else if (textChild.getNodeName().equals("unknownBox")) { iunknownBox = iunknownBox + 1; } } continue; } continue; } if (isignatureBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_A_JP2_SIGNATURE)); } if (ifileTypeBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_A_JP2_FILETYPE)); } if (iimageHeaderBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_IMAGE)); } if (ibitsPerComponentBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_BITSPC)); } if (icolourSpecificationBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_COLOUR)); } if (ipaletteBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_PALETTE)); } if (icomponentMappingBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_MAPPING)); } if (ichannelDefinitionBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_CHANNEL)); } if (iresolutionBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_RESOLUTION)); } if (icontainsImageHeaderBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_NOIHB)); } if (icontainsColourSpecificationBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_NOCSB)); } if (icontainsBitsPerComponentBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_NBPCB)); } if (ifirstJP2HeaderBoxIsImageHeaderBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_IHBNF)); } if (inoMoreThanOneImageHeaderBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_IHBMO)); } if (inoMoreThanOneBitsPerComponentBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_OBPCMO)); } if (inoMoreThanOnePaletteBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_OPBMO)); } if (inoMoreThanOneComponentMappingBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_CMBMO)); } if (inoMoreThanOneChannelDefinitionBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_CDBMO)); } if (inoMoreThanOneResolutionBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_RBMO)); } if (icolourSpecificationBoxesAreContiguous >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_CSBNC)); } if (ipaletteAndComponentMappingBoxesOnlyTogether >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B_JP2) + getTextResourceService().getText(ERROR_XML_B_JP2_PACMB)); } if (icodestreamStartsWithSOCMarker >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_SOC)); } if (ifoundSIZMarker >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_FSIZ)); } if (ifoundCODMarker >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_FCOD)); } if (ifoundQCDMarker >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_FQCD)); } if (iquantizationConsistentWithLevels >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_PQCD)); } if (ifoundExpectedNumberOfTiles >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_NOTILES)); } if (ifoundExpectedNumberOfTileParts >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_NOTILESPART)); } if (ifoundEOCMarker >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_EOC)); } if (itileParts >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_TILEPARTS)); } if (isiz >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_SIZ)); } if (icod >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_COD)); } if (iqcd >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_QCD)); } if (icom >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_COM)); } if (icoc >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_COC)); } if (irgn >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_RGN)); } if (iqcc >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_QCC)); } if (ipoc >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_POC)); } if (iplm >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_PLM)); } if (ippm >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_PPM)); } if (itlm >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_TLM)); } if (icrg >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_CRG)); } if (iplt >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_PLT)); } if (ippt >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_C_JP2) + getTextResourceService().getText(ERROR_XML_C_JP2_PPT)); } if (ixmlBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_JP2) + getTextResourceService().getText(ERROR_XML_D_JP2_XML)); } if (iuuidBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_JP2) + getTextResourceService().getText(ERROR_XML_D_JP2_UUID)); } if (iuuidInfoBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_JP2) + getTextResourceService().getText(ERROR_XML_D_JP2_UUIDINFO)); } if (iunknownBox >= 1) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_D_JP2) + getTextResourceService().getText(ERROR_XML_D_JP2_UNKNOWN)); } } } catch (Exception e) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_A_JP2) + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); } return isValid; }
From source file:marytts.tools.voiceimport.HTKLabeler.java
/** * create phone master label file (Not used?) * @throws Exception/*from w w w . j a v a 2s. c o m*/ */ private void createPhoneMLFile() throws Exception { String hled = getProp(HTKDIR) + File.separator + "HLEd"; File htkFile = new File(hled); if (!htkFile.exists()) { throw new RuntimeException("File " + htkFile.getAbsolutePath() + " does not exist"); } String dict = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.dict"; String phoneMLF = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phones.mlf"; String wordsMLF = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.words.mlf"; String mkphoneLED = getProp(HTDIR) + File.separator + "config" + File.separator + "mkphone0.led"; Runtime rtime = Runtime.getRuntime(); //get a shell Process process = rtime.exec("/bin/bash"); //get an output stream to write to the shell PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); System.out.println("( " + hled + " -l '*' -d " + dict + " -i " + phoneMLF + " " + mkphoneLED + " " + wordsMLF + "; exit )\n"); pw.print("( " + hled + " -l '*' -d " + dict + " -i " + phoneMLF + " " + mkphoneLED + " " + wordsMLF //+"; " + "; exit )\n"); pw.flush(); //shut down pw.close(); process.waitFor(); // check exit value if (process.exitValue() != 0) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); throw new MaryConfigurationException(errorReader.readLine()); } }
From source file:marytts.tools.voiceimport.HTKLabeler.java
/** * delete sp repetition on htk.phones3.mlf * @throws Exception/*from ww w. j a v a2 s . c om*/ */ private void delete_multiple_sp_in_PhoneMLFile(String filein, String fileout) throws Exception { String hled = getProp(HTKDIR) + File.separator + "HLEd"; File htkFile = new File(hled); if (!htkFile.exists()) { throw new RuntimeException("File " + htkFile.getAbsolutePath() + " does not exist"); } //String phoneMLF3 = getProp(HTDIR)+File.separator // +"etc"+File.separator+"htk.phones3.mlf"; // String phoneMLFtmpin = getProp(HTDIR)+File.separator // +"etc"+File.separator+"htk.phones3_tmp_in.mlf"; //String phoneMLFtmpout = getProp(HTDIR)+File.separator // +"etc"+File.separator+"htk.phones3_tmp_out.mlf"; String mkphoneLED = getProp(HTDIR) + File.separator + "config" + File.separator + "mkphone1.led"; Runtime rtime = Runtime.getRuntime(); //get a shell Process process = rtime.exec("/bin/bash"); //get an output stream to write to the shell PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); System.out.println("( " + hled + " -l '*' -i " + fileout + " " + mkphoneLED + " " + filein + "; exit )\n"); pw.print("( " + hled + " -l '*' -i " + fileout + " " + mkphoneLED + " " + filein //+"; " + "; exit )\n"); pw.flush(); //shut down pw.close(); process.waitFor(); process.exitValue(); }
From source file:marytts.tools.voiceimport.HTKLabeler.java
/** * Initialize HTK Training process// w ww .java 2 s .c o m * @throws Exception */ private void initialiseHTKTrain() throws Exception { String hcompv = getProp(HTKDIR) + File.separator + "HCompV"; File htkFile = new File(hcompv); if (!htkFile.exists()) { throw new RuntimeException("File " + htkFile.getAbsolutePath() + " does not exist"); } String configFile = getProp(HTDIR) + File.separator + "config" + File.separator + "htkTrain.conf"; String listFile = getProp(HTDIR) + File.separator + "etc" + File.separator + "htkTrain.list"; Runtime rtime = Runtime.getRuntime(); //get a shell Process process = rtime.exec("/bin/bash"); //get an output stream to write to the shell PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); System.out.println("( cd " + getProp(HTDIR) + " ; mkdir hmm/hmm-dummy ; " + " mkdir hmm/hmm-final ; " + hcompv + " " + HTK_SO + " -C " + configFile + " -f 0.01 -m -S " + listFile + " -M " + getProp(HTDIR) + File.separator + "hmm/hmm-dummy " + getProp(HTDIR) + File.separator + "config" + File.separator + "htk.proto" + " > log_initialiseHTKTrain.txt" + "; exit )\n"); pw.print("( cd " + getProp(HTDIR) + " ; mkdir hmm/hmm-dummy ; " + " mkdir hmm/hmm-final ; " + hcompv + " " + HTK_SO + " -C " + configFile + " -f 0.01 -m -S " + listFile + " -M " + getProp(HTDIR) + File.separator + "hmm/hmm-dummy " + getProp(HTDIR) + File.separator + "config" + File.separator + "htk.proto" + " > log_initialiseHTKTrain.txt" + "; exit )\n"); pw.flush(); //shut down pw.close(); process.waitFor(); // check exit value if (process.exitValue() != 0) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); throw new MaryConfigurationException(errorReader.readLine()); } }
From source file:marytts.tools.voiceimport.HTKLabeler.java
/** * Setup the HTK directory/*from w ww . j a v a2s. c o m*/ * @throws IOException, InterruptedException * @throws MaryConfigurationException */ private void setup() throws IOException, InterruptedException, MaryConfigurationException { htk.mkdir(); File lab = new File(htk.getAbsolutePath() + "/lab"); //call setup of HTK in this directory Runtime rtime = Runtime.getRuntime(); //get a shell Process process = rtime.exec("/bin/bash"); //get an output stream to write to the shell PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); //go to htk directory and setup Directory Structure pw.print("( cd " + htk.getAbsolutePath() + "; mkdir -p hmm" + "; mkdir -p etc" + "; mkdir -p feat" + "; mkdir -p config" + "; mkdir -p lab" + "; mkdir -p htk-full/lab" + "; mkdir -p htk-full/wrd" + "; exit )\n"); pw.flush(); //shut down pw.close(); process.waitFor(); // check exit value if (process.exitValue() != 0) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); throw new MaryConfigurationException(errorReader.readLine()); } // TODO: temporary: at the moment fix path to load the dictionary lexicon = new FSTLookup(new FileInputStream( "/home/fabio/voice_building_5_0/marytts-it/marytts-lang-it/src/main/resources/marytts/language/it/lexicon/it_lexicon.fst"), "it_lexicon.fst"); /* System.out.print("Starting builtin MARY TTS..."); Mary.startup(); System.out.println(" MARY TTS started."); e poi */ }
From source file:marytts.tools.voiceimport.HTKLabeler.java
/** * Create HMMs for each phone from Global HMMs * @throws Exception// w w w . j a v a2 s. c o m */ private void createTrainFile() throws Exception { String script; String hmmDir = getProp(HTDIR) + File.separator + "hmm" + File.separator; /**TODO: * Replace below 'gawk' script with Java method. */ script = "mkdir hmm/hmm0\n" + "head -3 hmm/hmm-dummy/htk > hmm/hmm0/hmmdefs\n" + "for s in `cat etc/htk.phone.list`\n" + "do\n" + "echo \"~h \\\"$s\\\"\" >> hmm/hmm0/hmmdefs\n" + "gawk '/BEGINHMM/,/ENDHMM/ { print $0 }' hmm/hmm-dummy/htk >> hmm/hmm0/hmmdefs\n" + "done\n"; // creating list of training files File file = new File(getProp(HTDIR) + File.separator + "etc" + File.separator + "htkTrainScript.sh"); PrintWriter pw = new PrintWriter(new FileWriter(file)); pw.println(script); pw.flush(); pw.close(); Runtime rtime = Runtime.getRuntime(); //get a shell Process process = rtime.exec("/bin/bash"); //get an output stream to write to the shell pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); System.out.println("( cd " + getProp(HTDIR) + "; sh etc" + File.separator + "htkTrainScript.sh" + " > log_htkTrainScript.txt" + "; exit )\n"); pw.print("( cd " + getProp(HTDIR) + "; sh etc" + File.separator + "htkTrainScript.sh" + " > log_htkTrainScript.txt" + "; exit )\n"); pw.flush(); //shut down pw.close(); process.waitFor(); // check exit value if (process.exitValue() != 0) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); throw new MaryConfigurationException(errorReader.readLine()); } PrintWriter macroFile = new PrintWriter( new FileOutputStream(new File(hmmDir + "hmm0" + File.separator + "macros"))); macroFile.println("~o\n" + "<VecSize> 13\n" + "<" + Train_FEAT + ">"); macroFile.println( FileUtils.getFileAsString(new File(hmmDir + "hmm-dummy" + File.separator + "vFloors"), "ASCII")); macroFile.flush(); macroFile.close(); }
From source file:marytts.tools.voiceimport.HTKLabeler.java
private void htkExtraModels() throws Exception { String hlstats = getProp(HTKDIR) + File.separator + "HLStats"; String hbuild = getProp(HTKDIR) + File.separator + "HBuild"; File htkFile = new File(hlstats); if (!htkFile.exists()) { throw new RuntimeException("File " + htkFile.getAbsolutePath() + " does not exist"); }//from w ww .j a v a 2 s. com String configFile = getProp(HTDIR) + File.separator + "config" + File.separator + "htkTrain.conf"; String bigFile = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phones.big"; String phoneList = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phone.list"; String phoneMlf = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phones.mlf"; String phoneDict = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phone.dict"; String phoneAugDict = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.aug.phone.dict"; String phoneAugList = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.aug.phone.list"; String netFile = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phones.net"; Runtime rtime = Runtime.getRuntime(); //get a shell Process process = rtime.exec("/bin/bash"); //get an output stream to write to the shell PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); System.out.println("( cd " + getProp(HTDIR) + "; " + hlstats + " -T 1 -C " + configFile + " -b " + bigFile + " -o " + phoneList + " " + phoneMlf + " > log_hlstats.txt" + "; exit )\n"); pw.println("( cd " + getProp(HTDIR) + "; " + hlstats + " -T 1 -C " + configFile + " -b " + bigFile + " -o " + phoneList + " " + phoneMlf + " > log_hlstats.txt" + "; exit )\n"); pw.flush(); //shut down pw.close(); process.waitFor(); // check exit value if (process.exitValue() != 0) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); throw new MaryConfigurationException(errorReader.readLine()); } String fileDict = FileUtils.getFileAsString(new File(phoneDict), "ASCII"); PrintWriter augPhoneDict = new PrintWriter(new FileWriter(phoneAugDict)); augPhoneDict.println("!ENTER sil"); augPhoneDict.print(fileDict); augPhoneDict.println("!EXIT sil"); augPhoneDict.flush(); augPhoneDict.close(); String fileList = FileUtils.getFileAsString(new File(phoneList), "ASCII"); PrintWriter augPhoneList = new PrintWriter(new FileWriter(phoneAugList)); augPhoneList.println("!ENTER"); augPhoneList.print(fileList); augPhoneList.println("!EXIT"); augPhoneList.flush(); augPhoneList.close(); rtime = Runtime.getRuntime(); //get a shell process = rtime.exec("/bin/bash"); //get an output stream to write to the shell pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); System.out.println("( cd " + getProp(HTDIR) + "; " + hbuild + " -T 1 -C " + configFile + " -n " + bigFile + " " + phoneAugList + " " + netFile + " > log_hbuild.txt" + "; exit )\n"); pw.println("( cd " + getProp(HTDIR) + "; " + hbuild + " -T 1 -C " + configFile + " -n " + bigFile + " " + phoneAugList + " " + netFile + " > log_hbuild.txt" + "; exit )\n"); pw.flush(); //shut down pw.close(); process.waitFor(); // check exit value if (process.exitValue() != 0) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); throw new MaryConfigurationException(errorReader.readLine()); } }
From source file:marytts.tools.voiceimport.HTKLabeler.java
/** * Force Align database for Automatic labels * @throws Exception/*from w ww .j ava2s . c o m*/ */ private void hviteAligning() throws Exception { String hvite = getProp(HTKDIR) + File.separator + "HVite"; // -A -D -V -T 1 "; // to add -A -D -V -T 1 in every function File htkFile = new File(hvite); if (!htkFile.exists()) { throw new RuntimeException("File " + htkFile.getAbsolutePath() + " does not exist"); } String configFile = getProp(HTDIR) + File.separator + "config" + File.separator + "htkTrain.conf"; String listFile = getProp(HTDIR) + File.separator + "etc" + File.separator + "htkTrain.list"; // Virtual sp change_ phoneList should be a member? // Without sp: /*String phoneList = getProp(HTDIR)+File.separator +"etc"+File.separator+"htk.phone2.list";*/ // Whit sp: String phoneList = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phone3.list"; String hmmDef = getProp(HTDIR) + File.separator + "hmm" + File.separator + "hmm-final" + File.separator + "hmmdefs"; String macros = getProp(HTDIR) + File.separator + "hmm" + File.separator + "hmm-final" + File.separator + "macros"; // Virtual sp change_ phoneMlf should be a member? // Without sp: /*String phoneMlf = getProp(HTDIR)+File.separator +"etc"+File.separator+"htk.phones2.mlf";*/ // Whit sp: String phoneMlf = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phones3.mlf"; String alignedMlf = getProp(HTDIR) + File.separator + "aligned.mlf"; String phoneDict = getProp(HTDIR) + File.separator + "etc" + File.separator + "htk.phone.dict"; String labDir = getProp(HTDIR) + File.separator + "lab"; Runtime rtime = Runtime.getRuntime(); //get a shell Process process = rtime.exec("/bin/bash"); //get an output stream to write to the shell //when no sp use (-m)! PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); System.out.println("( cd " + getProp(HTDIR) + "; " + hvite + " " + HTK_SO + " -b sil -l " + labDir + " -o W -C " + configFile + " -a -H " + macros + " -H " + hmmDef + " -i " + alignedMlf + " -t 250.0 -y lab" + " -I " + phoneMlf + " -S " + listFile + " " + phoneDict + " " + phoneList + " > log_hviteAligning.txt" + "; exit )\n"); pw.println("( cd " + getProp(HTDIR) + "; " + hvite + " " + HTK_SO + " -b sil -l " + labDir + " -o W -C " + configFile + " -a -H " + macros + " -H " + hmmDef + " -i " + alignedMlf + " -t 250.0 -y lab" + " -I " + phoneMlf + " -S " + listFile + " " + phoneDict + " " + phoneList + " > log_hviteAligning.txt" + "; exit )\n"); pw.flush(); //shut down pw.close(); process.waitFor(); // check exit value if (process.exitValue() != 0) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); throw new MaryConfigurationException(errorReader.readLine()); } }
From source file:marytts.tools.voiceimport.HTKLabeler.java
private void saveHTKWordDictionary() throws Exception { String dict0 = outputDir + File.separator + "htk.words0.dict"; String dict = outputDir + File.separator + "htk.words.dict"; PrintWriter wordDictOut = new PrintWriter(new FileOutputStream(new File(dict0))); HTKdictionary.add("sil sil"); HTKdictionary.add("ssil ssil"); HTKdictionary.add("sp sp"); Iterator<String> itr = HTKdictionary.iterator(); while (itr.hasNext()) { wordDictOut.println(itr.next()); }//w w w.jav a 2s. co m wordDictOut.flush(); wordDictOut.close(); String fileded = getProp(HTDIR) + File.separator + "config" + File.separator + "dict.ded"; PrintWriter dedDictOut = new PrintWriter(new FileOutputStream(new File(fileded))); dedDictOut.println("AS sp"); dedDictOut.println("MP sil sil sp"); dedDictOut.println("MP ssil ssil sp"); dedDictOut.println("MP sp sp sp"); dedDictOut.flush(); dedDictOut.close(); Runtime rtime = Runtime.getRuntime(); //get a shell Process process = rtime.exec("/bin/bash"); //get an output stream to write to the shell //when no sp use (-m)! String hdman = getProp(HTKDIR) + File.separator + "HDMan"; PrintWriter pw = new PrintWriter(new OutputStreamWriter(process.getOutputStream())); String cmd = "( cd " + getProp(HTDIR) + "; " + hdman + " -g " + fileded + " " + dict + " " + dict0 + "; exit )\n"; System.out.println(cmd); pw.println(cmd); pw.flush(); //shut down pw.close(); process.waitFor(); // check exit value if (process.exitValue() != 0) { BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); throw new MaryConfigurationException(errorReader.readLine()); } }