parse ogg file in java without decoding - java

I have a .spx file (an Ogg file with Speex-encoded audio). I would like to use Java to pull the Speex-encoded bytes out of the Ogg container.
The problem is, it seems all of the Java libraries I can find (JSpeex, JOrbis) are written with the assumption that I would also like to decode the audio into raw pcm, which I do not.
Is there a generic Ogg format reader library out there for Java? On the other hand, is it possible to use parts of JSpeex or JOrbis to do what I want?

I could not find an Ogg library in Java after some shallow searching.
But if you are willing to implement Ogg parsing from scratch, the words straight from the horse's mouth are readily available:
Ogg bitstream overview
Ogg logical bitstream and framing spec
(Top page: https://www.xiph.org/vorbis/doc/)

I have not worked with Ogg file with Speex-encoded audio but once I have worked on a use case where I wanted to extract opus packets from ogg opus file, without being decoded to pcm audio. You can find that solution in this answer
https://stackoverflow.com/a/65320789/10110652
This piece of code also works for ogg file with vorbis encoding, so may be this might help with speex encoding as well. Do let me know if this works for you.
Happy Coding!!!❤

Related

merge some ogg audio files using java programming language

I have some .ogg sound files that must be merged together.But the problem is in that the java only support .wav extension (as I used AudioSystem and AudioInputStream).
I've searched among different pages for converting and I've not found a better way than.
Do you know a better way other than using Command line tool?
I think you may have to inspect and tinker with the source code. This can be obtained from various libraries that have JOrbis and other files needed for ogg playback and encoding (there are several on github).
For a project where I needed to load decompressed ogg files (that were originally wav) into memory, I used source code from the example OggPlayer (usually included in the package) and intercepted the bytes before they were written to a SourceDataLine. You can maybe also find a hook in example code that compresses wav to ogg and then link the two parts.

Lossy audio encoding java

What (stable) encoding libraries exist that can encode an uncompressed or lossless audio file to a common lossy format such as aac, mp3 or ogg?
If it is possible to do this without a library, that would be a valid option, too!
Vorbis-java is my recommendation, because it is free and avoids the patent / licensing issues you may come across with aac or mp3.
LAMEOnJ is a Java api for mp3 en/decoding, but you'll need to get the LAME library separately, due to the licensing concerns.

Is it possible (and how) to determine the endianness of an AIFF audio file?

I work on an audio Importer in JAVA (used in a drum sequencer) and I have the following problem with importing AIFF files:
I have 2 AIFF files of the same type (24bit, 44100kHz, mono), one is created on a Mac, the other is created with wavelab on a windows computer. Both files are uncompressed PCM, both are FORM == AIFF.
The AIFF from the Mac is BigEndian (as it should be),
the AIFF from Wavelab (windows) is LittleEndian.
Both files can be played back properly in Wavelab (Windows) as well as in Quicktime (Windows).
How can these tools detect the endianness of these files? In any way it must be possible, otherwise at least one of the files would sound just like noise (that's what happen in my application).
Is there some hidden information within the file header or any other way to determine the endianness of the AIFF file?
Any suggestions?
Thanks a lot
A quick googling says, AIFF files are big endian.
However according to Wikipedia there is another format called AIFF-C that compresses data. Apple uses little endian these days and created a fake compression method named sowt that essentially means "no compression but little endian". You might have to check for that.
Apart from that, plain AIFF provides no way to check for endianness. A standard AIFF that is encoded in little endian seems to violate the specification.

Java library for extracting audio information from MP3 files

Is there any freely available library (other than java media framework) that I can use to extract the bit rate (eg. 128 kbps, VBR) and the audio quality (eg 44.1KHz, Stereo) from a MP3 file?
I would like a standalone library that I can incorporate into my application jar, to be deployed on older Macs too that have only Java 1.5 available and I can't get them upgraded or add any big Java library to.
Just to clarify: I will not play, transcode or do anything of the sort with the audio stream itself, I am interested in the metadata only.
I confess I do not know much about MP3 files, but you can see from the format specification that all the informations needed are in the 32 bits long header of the file.
You could open the MP3 with a FileInputStream, read the first 4 bytes of the file and, using some simple binary masks, retrieve the informations you need. IMHO using a specialized library for that is a bit of an overkill.
Take a look at JAudioTagger, plain simple and easy to use, the data you are looking for is into MP3AudioHeader class, with methods like getBitRate()
You can use the LAMEOnJ library:
http://openinnowhere.sourceforge.net/lameonj/
This java library is light but you must have the LAMELib installed on target computer.
I'm not a java programmer, but i'm pretty sure you could read the mp3 file into a byte array then see http://www.mp3-tech.org/programmer/frame_header.html for frame info.
This format specification shows you what's contained the MPEG (mp3) header. You can write code to retrieve this header.

Recording audio in OGG

Is audio recording in the OGG format possible?
Yes. However, first, you need to decide what codec to use. ogg is a container format like avi or mkv or mp4 - just knowing the container doesn't tell you everything about the format. If you want vorbis, there are some pure java encoding libraries (eg vorbis-java) out there (not sure how polished they are!) or you can use JNI to bind one of the many C libraries. If you want some other codec, perhaps better suited to voice (speex? something else?) please specify.

Categories