I have written a code that will transcribe audio file to text but my problem is i want to split the audio file into pieces and then i want to transcribe that break audio file one by one please help me with this
StreamSpeechRecognizer recognizer;
try
{
recognizer = new StreamSpeechRecognizer( configuration);
java.io.InputStream stream = AppRunner.class.getResourceAsStream(splitFile(new File("/com/dsquare/Arabtec_Construction_INDIA_Private_Limited_convert.wav")));
System.out.println(stream);
stream.skip(44);
// Simple recognition with generic model
recognizer.startRecognition(stream);
SpeechResult result;
while ((result = recognizer.getResult()) != null)
{
System.out.format("Hypothesis: %s\n", result.getHypothesis());
System.out.println("List of recognized words and their times:");
for (WordResult r : result.getWords())
{
System.out.println(r);
}
// System.out.println("Best 3 hypothesis:");
for (String s : result.getNbest(3))
{
System.out.println(s);
}
recognizer.stopRecognition();
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
public static String splitFile(File f) throws IOException {
int partCounter = 1;//I like to name parts from 001, 002, 003, ...
//you can change it to 0 if you want 000, 001, ...
int sizeOfFiles = 1024 * 1024;// 1MB
byte[] buffer = new byte[sizeOfFiles];
try (BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(f))) {//try-with-resources to ensure closing stream
String name = f.getName();
int tmp = 0;
while ((tmp = bis.read(buffer)) > 0) {
//write each chunk of data into separate file with different number in name
File newFile = new File(f.getParent(), name + "."
+ String.format("%03d", partCounter++));
try (FileOutputStream out = new FileOutputStream(newFile)) {
out.write(buffer, 0, tmp);//tmp is chunk size
}
}
}
return null;
}
}