Coloca o codigo ai da classe MBrolaSynthesizer.java
J
justiceira
Seria esse aqui olha, eu pensei que poderia ser esse caminho do aquivo exe, sera que é isso?
packagebr.furb.api.furbspeech.synth;importjava.io.File;importjava.io.IOException;importjava.net.URL;importbr.furb.api.furbspeech.FurbSpeech;importbr.furb.api.furbspeech.util.ComponentUtils;importbr.furb.api.furbspeech.util.OSNotSupportedException;publicclassMBrolaSynthesizerimplementsSynthesizer{/** * BR1 voice. Downloaded from Mbrola project web site. */publicstaticfinalFileVOICE_BR1=newFile(ComponentUtils.getClearDirAbsolutePath(FurbSpeech.class.getClassLoader().getResource("synthesizer/mbrola/br1").getFile()));/** * BR2 voice. Downloaded from Mbrola project web site. */publicstaticfinalFileVOICE_BR2=newFile(ComponentUtils.getClearDirAbsolutePath(FurbSpeech.class.getClassLoader().getResource("synthesizer/mbrola/br2").getFile()));/** * BR3 voice. Downloaded from Mbrola project web site. */publicstaticfinalFileVOICE_BR3=newFile(ComponentUtils.getClearDirAbsolutePath(FurbSpeech.class.getClassLoader().getResource("synthesizer/mbrola/br3").getFile()));privateFilevoiceName;publicvoidsetVoice(FilevoiceName){this.voiceName=voiceName;}publicvoidsynthesize(FileinputFile,FileoutputFile){// should set the default voice?if(voiceName==null){voiceName=VOICE_BR1;}StringcmdLine="<mbrola-bin> -e <voice> <input> <output>";cmdLine=cmdLine.replace("<mbrola-bin>",getPreparedFilePath(getMBrolaAppAbsolutePath())).replace("<voice>",getPreparedFilePath(voiceName.getAbsolutePath())).replace("<input>",getPreparedFilePath(inputFile.getAbsolutePath())).replace("<output>",getPreparedFilePath(outputFile.getAbsolutePath()));try{//FurbSpeech.getLogger().debug("Executing command: " + cmdLine);Runtime.getRuntime().exec(cmdLine).waitFor();}catch(IOExceptione){//FurbSpeech.getLogger().fatal("I/O excetion in the external MBrola application.", e);thrownewRuntimeException(e);}catch(InterruptedExceptione){//FurbSpeech.getLogger().fatal("Error while the current thread waits for the end of the mbrola applation process.", e);thrownewRuntimeException(e);}}privateStringgetPreparedFilePath(StringfilePath){StringosName=(String)System.getProperties().get("os.name");if(osName.toLowerCase().indexOf("windows")>-1){return"\"".concat(filePath).concat("\"");}else{returnfilePath.replaceAll(" ","\\ ");}}privateStringgetMBrolaAppAbsolutePath(){Stringbin=null;StringosName=(String)System.getProperties().get("os.name");if(osName.toLowerCase().indexOf("windows")>-1){bin="mbrola.exe";}elseif(osName.toLowerCase().indexOf("linux")>-1){bin="mbrola-linux-i386";}elseif(osName.toLowerCase().indexOf("mac")>-1){bin="mbrola-darwin-ppc";}if(bin!=null){URLmbrolaBin=MBrolaSynthesizer.class.getClassLoader().getResource("synthesizer/mbrola/"+bin);returnnewFile(ComponentUtils.getClearDirAbsolutePath(mbrolaBin.getFile())).getAbsolutePath();}else{thrownewOSNotSupportedException();}}publicFilegetVoice(){returnvoiceName;}}
P
Pedro_GTI
desculpe, falei errado, poste o codigo desta SynthesizerFactory.java
J
justiceira
Tudo bem Pedro_GTI, ja valeu só por estar tentando me ajudar
packagebr.furb.api.furbspeech.synth;publicclassSynthesizerFactory{publicstaticSynthesizergetSynthesizer(){// TODO: in the future, when I have more implementations of synthesizers, // I'll need to check some config file to know which constructor to invoke. returnnewMBrolaSynthesizer();}}
P
Pedro_GTI
Esse erro ocorre quando? Vc fez alterações no código, depois que postou a exceção?
J
justiceira
Acrescentei esta linha em negrito, inclusive a primeira mensagem aparece,
Esse é o main do FurbSpeech.java
publicstaticvoidmain(String[]args){System.out.println("Aplicativo iniciado...");[b]Fileaudio=newFurbSpeech().text("Rua antônio da veiga").to().speech();[/b]System.out.println("Finalizando.....");}
aqui é onde recebo este texto, incluisve coloquei esta mensagem para ver se executa e executou
publicFurbSpeechtext(Stringtext){
this.text=text;System.out.println("texto pego");///LINHA ADICIONADA PRA TESTESreturnthis;
}
aqui é onde comeca a parte da leitura, esta tambem executa
Aplicativo iniciado...
texto pego
criado arquivo
Exception in thread "main" java.lang.ExceptionInInitializerError
at br.furb.api.furbspeech.synth.SynthesizerFactory.getSynthesizer(SynthesizerFactory.java:26)
at br.furb.api.furbspeech.FurbSpeech.speech(FurbSpeech.java:120)
at br.furb.api.furbspeech.FurbSpeech.main(FurbSpeech.java:48)
Caused by: java.lang.NullPointerException
at br.furb.api.furbspeech.synth.MBrolaSynthesizer.<clinit>(MBrolaSynthesizer.java:35)
... 3 more
pmlm
O que está nesta linha?
at br.furb.api.furbspeech.synth.MBrolaSynthesizer.(MBrolaSynthesizer.java:35)
P
Pedro_GTI
Mostre a implementacao do metodo to() dentro de FurbSpeech
Adiciona o código da classe FurbSpeech.java (Mas ja estou sentindo o cheiro do erro)
J
justiceira
Nossa que bom, espero que vc me ajude a achar pq nem sei mais o que fazer nisso
packagebr.furb.api.furbspeech;importjava.io.File;importjava.io.FileWriter;importjava.io.IOException;importbr.furb.api.furbspeech.comp.Text;importbr.furb.api.furbspeech.synth.Synthesizer;importbr.furb.api.furbspeech.synth.SynthesizerFactory;importbr.furb.api.furbspeech.util.ComponentUtils;publicclassFurbSpeech{publicstaticvoidmain(String[]args){System.out.println("Aplicativo iniciado...");Fileaudio=newFurbSpeech().text("Rua antônio da veiga").to().speech();System.out.println("Finalizando.....");}privatestaticfinalStringDEFAULT_OUTPUT_FILENAME="speech.wav";//private static Logger logger;privateStringtext;privateFilevoiceFile;privateStringfileName;publicFurbSpeech(){super();}/** * Defines the text of the operation. * @param text * @return */publicFurbSpeechtext(Stringtext){this.text=text;System.out.println("texto pego");///LINHA ADICIONADA PRA TESTESreturnthis;}/** * Defines the voice to be used by sinthesizer application. * @param voiceFile * @return */publicFurbSpeechwithVoice(FilevoiceFile){this.voiceFile=voiceFile;System.out.println("voz tratada");///LINHA ADICIONADA PRA TESTESreturnthis;}/** * Defines the default output WAV filename. * @return */publicFurbSpeechto(){fileName=DEFAULT_OUTPUT_FILENAME;System.out.println("criado arquivo");///LINHA ADICIONADA PRA TESTESreturnthis;}/** * Defines the output WAV filename. * @param outputType * @param fileName Relative to the user project binary directory. * @return */publicFurbSpeechto(StringfileName){this.fileName=fileName.startsWith("/")?fileName.substring(1):fileName;returnthis;}/** * Speech the text based on previous defined text, output file and voice. */publicFilespeech(){checkAttributes();Texttext=newText(this.text);text.parsePhrases(ComponentUtils.BASE_FREQUENCY,ComponentUtils.BASE_TIME);Stringoutput=text.showPhrases();FilesynthInput=writeOutputInTheFile(output);FileoutputSpeechFile=newFile(ComponentUtils.getClearDirAbsolutePath(FurbSpeech.class.getClassLoader().getResource("output").getFile()+"/"+this.fileName));Synthesizersynthesizer=SynthesizerFactory.getSynthesizer();if(voiceFile!=null){synthesizer.setVoice(voiceFile);}synthesizer.synthesize(synthInput,outputSpeechFile);System.out.println("Lendo?");returnoutputSpeechFile;}privateFilewriteOutputInTheFile(Stringoutput){//FurbSpeech.getLogger().debug("Creating output directory");FileoutputDir=newFile(ComponentUtils.getClearDirAbsolutePath(FurbSpeech.class.getClassLoader().getResource(".").getFile()).concat("/output/"));outputDir.mkdir();FilefileOutput=newFile(ComponentUtils.getClearDirAbsolutePath(FurbSpeech.class.getClassLoader().getResource("output").getFile())+"/output.pho");try{if(!fileOutput.exists()){fileOutput.createNewFile();//FurbSpeech.getLogger().debug("Empty .pho file created");}FileWriterfw=newFileWriter(fileOutput);fw.write(output);fw.close();//FurbSpeech.getLogger().debug(".pho contents added with success");returnfileOutput;}catch(IOExceptione){//FurbSpeech.getLogger().error("I/O error writting .pho file", e);returnnull;}}privatevoidcheckAttributes(){if(this.text==null){thrownewIllegalStateException("The text must be previously defined. Before this invocation, call the method text(String)");}if(this.fileName==null){thrownewIllegalStateException("The output WAV file name must be previously defined. Before this invocation, call the method to() or to(String)");}}}
J
justiceira
Nao pmlm, aparentemente nada nesta linha esta recebendo null
P
Pedro_GTI
Bota um break point dentro do método speech(), e acompanha o fluxo, dentro dele deve ter alguma coisa dano trela, não da pra saber olhando, debuga ai pra ver…
pmlm
Aparentemente? Ou de certeza?
J
justiceira
voiceFile esta recebendo null pois nao continua apartir da linha em negrito
publicFilespeech(){checkAttributes();Texttext=newText(this.text);text.parsePhrases(ComponentUtils.BASE_FREQUENCY,ComponentUtils.BASE_TIME);Stringoutput=text.showPhrases();FilesynthInput=writeOutputInTheFile(output);FileoutputSpeechFile=newFile(ComponentUtils.getClearDirAbsolutePath(FurbSpeech.class.getClassLoader().getResource("output").getFile()+"/"+this.fileName));[b]Synthesizersynthesizer=SynthesizerFactory.getSynthesizer();[/b]if(voiceFile!=null){synthesizer.setVoice(voiceFile);}synthesizer.synthesize(synthInput,outputSpeechFile);System.out.println("Lendo?");//adicionada para testesreturnoutputSpeechFile;}
J
justiceira
Obrigada pmlm e Pedro_GTI
desculpem a gafe
o erro era por cauda disso
public static final File VOICE_BR1 = new File(ComponentUtils.getClearDirAbsolutePath(FurbSpeech.class.getClassLoader().getResource(“resources/synthesizer/mbrola/br1”).getFile()));
o caminho estava mesmo errado,
Bom o audio ainda nao funciona, o arquivo nao esta sendo criado de maneira nenhuma,
mas estou tentando aqui, quem sabe é algo que esta passando despercebido, vou ter q ver