-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Makes Google and Wav2Vec2 audio transcription not dependent of FFmpeg anymore #1267
Comments
I wasn't able to find a mplayer option to split audios. Closing. If anyone knows how, please let me know. |
I am going to take a look and see if I find a way to use MPlayer instead of FFmpeg to split large WAV audios. |
Thank you @tc-wleite for looking into this! I searched for an option for that in mplayer manual 2 times in the past, but didn't find an obvious option for that... |
Some time ago I thought about breaking WAV files manually. I think splitting the raw audio data would be easy since we always convert to PCM mono 16Khz 16 bits per sample little endian. But possibly a header with some WAV metadata would need to be added to each chunk, not sure... |
Yes, there is a WAV header, not that hard, but not trivial. There are several fonts about it:
Of course if mplayer is able to do the job, it would be great. |
Ok, I think I found a simple solution, using only Java code. |
In case someone wants to check the idea, here is the standalone program: import java.io.*;
import javax.sound.sampled.*;
public class WavSplit {
public static void main(String[] args) throws Exception {
int partDurationInSeconds = 60;
AudioInputStream ais = AudioSystem.getAudioInputStream(new File("in.wav"));
int bytesPerFrame = ais.getFormat().getFrameSize();
int framesPerPart = Math.round(ais.getFormat().getFrameRate() * partDurationInSeconds);
byte[] partBytes = new byte[framesPerPart * bytesPerFrame];
int numBytesRead = 0;
int seq = 0;
while ((numBytesRead = ais.readNBytes(partBytes, 0, partBytes.length)) > 0) {
ByteArrayInputStream bais = new ByteArrayInputStream(partBytes, 0, numBytesRead);
AudioInputStream audioInputStream = new AudioInputStream(bais, ais.getFormat(), numBytesRead);
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, new File(String.format("out-%03d.wav", ++seq)));
audioInputStream.close();
}
ais.close();
}
} |
By the way, I found a solution with MPlayer to extract a part of the audio (e.g. cut from the beginning until 60s), but that would require multiple calls to achieve what we are looking for. |
Great! Thank you @tc-wleite! A java only solution is much better!!! |
Code above seems to work fine with a few WAVs I tested here. Headers are properly created in front of each part, with same values, except those related to data size, of course. There are a few WAVs here where byte 16 changed from 0x12 to 0x10, which is good, i.e., the audio was converted to PCM, what is needed by us. PS1: bytes 40-43 also changed, which I also believe is related to conversion to PCM. |
Once I asked in the MPlayer forum and the aswer was:
|
Ffmpeg is used to break audios longer than 1min and must be set on PATH explicitly by user. Maybe we can use the already embedded mplayer to break large audios, removing that external dependency.
If anyone already knows the mplayer command for that, please let me know.
The text was updated successfully, but these errors were encountered: