我已经编写了一个将音频文件转录为文本的代码,但我的问题是我想将音频文件拆分成片然后我想逐个转录那个音频文件请帮我解决这个问题
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;
}
}
答案 0 :(得分:1)
要以智能方式破坏音频文件,您可以考虑使用由Lium group开发的这种diarization工具。
http://www-lium.univ-lemans.fr/diarization/doku.php/welcome
此工具将为您提供一个* .seg文件,其中包含转换时间。然后,使用ffmpeg或类似方法剪切文件。