Javatpoint Logo

java code for converting audio to text and video to audio

By: kulkar*** On: Thu Aug 21 15:50:03 IST 2014     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
There is any Java API's for Converting audio to text, Video to audio, Image to PDF, Captured photo to PDf. So if there is any API's then tell me or Send me....Up0Down

 
you should ask on question in one link that is helpful.

try this java code for converting audio to text

import com.sun.speech.freetts.FreeTTS;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.SingleFileAudioPlayer;
import java.io.FileInputStream;

public class Voice{

void call(String msg){
System.out.println("U r here");
Voice voice;
FreeTTS freetts;
System.out.println("---------************");
VoiceManager vm=VoiceManager.getInstance();
System.out.println("--------------////");
voice=vm.getVoice("kevin16");
System.setProperty("com.sun.speech.freetts.voice.defaultAudioPlayer", "com.sun.speech.freetts.audio.SingleFileAudioPlayer");
FileInputStream fis ;
SingleFileAudioPlayer sfap;
if(voice==null)
System.out.println("voice is null");
System.out.println("---0---");
if(voice!=null)
{
voice.allocate();
}
System.out.println("---1---");
freetts=new FreeTTS(voice);
String text = new String(msg);
byte b[] = text.getBytes();
if(b==null)
{
System.out.println("no byte array");
System.exit(1);
}
try
{
sfap = (SingleFileAudioPlayer)voice.getDefaultAudioPlayer();
sfap.write(b);


}
catch(Exception e)
{

}
voice.speak(msg);
voice.deallocate();

System.out.println("---------?????-----------");
try {
System.out.println("inside copy try block");
String command="copy \"C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.18\\bin\\freetts.wav\" \"C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.18\\webapps\"";
System.out.println("copying file from "+command);
Runtime.getRuntime().exec("cmd.exe /c"+command);
System.out.println("file copied");
} catch (Exception e) {
e.printStackTrace();
}

System.out.println("---2---");

System.out.println("calling wav file");
//AePlayWave aw=new AePlayWave("C:/Program Files/Apache Software Foundation/Apache Tomcat 6.0.18/bin/freetts.wav");


System.out.println("---last---");

}
Main(){

}

Main(String str){

System.out.println("Inside main");

}
public static void main(String[] args)throws Exception {

}

}

Image Created0Down

By: [email protected] On: Fri Aug 22 18:14:39 IST 2014 Question Reputation0 Answer Reputation392 Belt Series Points0 392User Image
Are You Satisfied :0Yes0No
 

java code to convert video to audio....



import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.ICodec;

public class convert {
public static void main(String args[]){
IMediaReader reader = ToolFactory.makeReader("F:/input.mkv");
IMediaWriter writer = ToolFactory.makeWriter("F:/output.mp3", reader);
int sampleRate = 44100;
int channels = 1;
writer.addAudioStream(0, 0, ICodec.ID.CODEC_ID_MP3, channels, sampleRate);
while (reader.readPacket() == null);

}
}

------------------------------------------------

java code to convert pdf to image file

public class PdfService {

public static void main(String[] args) {

System.out.println("Test of Convert to PNG");
convertPDFtoImage(args[0]);
}

public static void convertPDFtoImage(String PDFFileName) {

try {

PDFDocument document = new PDFDocument();
File baseFile = new File(PDFFileName);
document.load(baseFile);

String df = new SimpleDateFormat("MM-dd-yy").format(new Date());

Path path = Paths.get(PDFFileName);
String filenameWithExtension = path.getFileName().toString();
String filename = FilenameUtils.removeExtension(filenameWithExtension);

String dirname = filename + "-" + df;

Path dir = Paths.get("C:\\Media\\" + dirname);
Files.createDirectory(dir);

movePDFToDirectory(baseFile, dirname, filenameWithExtension);

SimpleRenderer renderer = new SimpleRenderer();

renderer.setResolution(150);

List<Image> images = renderer.render(document);

try {

System.out.println("Begin converting PDF...");

for (int i = 0; i < images.size(); i++) {
ImageIO.write((RenderedImage) images.get(i), "jpeg", new File("C:\\Media\\" + dirname + "\\" + filename + "_" + (i + 1) + ".jpeg"));
}

System.out.println("PDF converted to image(s) successfully.");


} catch (IOException e) {
System.out.println("ERROR: " + e.getMessage());
}

} catch (Exception e) {
System.out.println("ERROR: " + e.getMessage());
}
}

public static void movePDFToDirectory(File originalFile, String directory, String filename) {
InputStream inStream = null;
OutputStream outStream = null;

try{


File newFile = new File("C:\\Media\\" + directory + "\\" + filename);

inStream = new FileInputStream(originalFile);
outStream = new FileOutputStream(newFile);

byte[] buffer = new byte[1024];

int length;
//copy the file content in bytes
while ((length = inStream.read(buffer)) > 0){

outStream.write(buffer, 0, length);

}

inStream.close();
outStream.close();

System.out.println("Original PDF has been copied successfully!");

}catch(IOException e){
e.printStackTrace();
}

}
}
Image Created0Down

By: [email protected] On: Fri Aug 22 18:15:49 IST 2014 Question Reputation0 Answer Reputation392 Belt Series Points0 392User Image
Are You Satisfied :0Yes0No
 
text to audio using freetts

import com.sun.speech.freetts.*;
/**
*
* @author Dvs
*/
public class audio {
private audio()
{
Voice voice;
VoiceManager vm =VoiceManager.getInstance();
voice=vm.getVoice("kevin16");
voice.setPitch((float)(57));
voice.setPitchShift((float)(2.5));
voice.setPitchRange((float)(10));
FreeTTS tts = new FreeTTS(voice);
tts.setAudioFile("C:\\Users\\Windows\\Desktop\\FileReader\\test.wav");
tts.startup();
voice.allocate();
try
{
voice.speak("hello this is test");

}catch(Exception e){}
voice.deallocate();
tts.shutdown();
}
public static void main(String args[])
{
new audio();
}
}
Image Created0Down

By: [email protected] On: Sun Nov 15 20:16:40 IST 2015 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
Image Created0Down

By: [email protected] On: Sun Sep 25 13:30:42 IST 2016 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
Image Created0Down

By: [email protected] On: Tue May 02 23:00:30 IST 2017 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
Hi,
I am not able to convert Mp3 file into a text file. I need to retrieve all the words out of Mp3 file, I have used your above mentioned code but unable to execute it, please elaborate it as well. thanks in advance.
Image Created0Down

By: [email protected] On: Thu Feb 22 12:24:15 IST 2018 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No