1

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;
    }

}

1 Answers1

1

To break audio files in a smart manner, you might consider diarization tools, such as this one developed by Lium group.

http://www-lium.univ-lemans.fr/diarization/doku.php/welcome

This tool will give you a *.seg file with transition times in it. Then, use ffmpeg or similar to cut the files.

astooooooo
  • 362
  • 2
  • 13
  • There's still a meaty part of the question: how do you use a .seg file with ffmeg to cut the audio? – Joel Shor Apr 26 '18 at 12:02
  • @JoelShor you can write a script to call ffmpeg with parameters described in this SO answer (https://stackoverflow.com/a/42827058/5317732) – astooooooo Apr 26 '18 at 12:18