Uploaded by Omar ElKashouty

Audio report

advertisement
If you've used computer audio in almost any capacity you've likely come
across both MP3 and WAV file formats. You probably know that these
formats are audio file formats, but do you know which one is better?
Better, of course, is a relative term. Whether you want to use an MP3 or
WAV depends on what you will be using it for. In this post, we'll talk
about the difference between WAV and MP3 files. We'll talk a little bit
about the formats themselves, so you can understand how they work.
Then we'll talk about which situations you may want to use each in. Is
WAV better than MP3? Is MP3 better than WAV? At the end of this
post, you'll know.
Choosing Between MP3 vs. WAV Files
Before we can examine the difference between an MP3 file and a WAV
file, we need to take a look at the difference between compressed data
and uncompressed data. Then we'll be able to discuss which one MP3 is
and which one WAV is. From there, we can look at when each of those
formats is the best option and whether it is reasonbe to convert WAV to
MP3 and vice versa.
Compressed vs. Uncompressed Data
Although our data storage capacities are increasing all of the time,
computer files are always a trade-off between quality and size.
Uncompressed files will give the highest quality, but are often large.
Compression doesn't always involve loss of quality but in order to get
the smallest size possible, quality must drop in some way. In the world
of computer audio, there is no shortage of competing file formats. The
most popular choice is between WAV or MP3. WAV files being the
most popular uncompressed audio option and MP3 being the most
popular compressed audio format. What exactly is the effect of
compression on the audio though? Can you just convert to WAV and
magically get the quality back? Let's briefly take a look at each of the
formats before diving into when to use them.
About the WAV File Format
The Waveform Audio file format, often called WAV or WAVE because
of its file extension, was created by Microsoft and IBM back in 1991.
The format can technically support compressed audio but is most
commonly used to encode LPCM (Linear Pulse Code Modulation) data.
Two tracks of LPCM data is what CDs use to store the two stereo
channels that make up their audio. CDs are stored with 16-bit data
recorded at 44.1khz. Although LPCM data is not compressed, it's quality
can be increased by increasing the sampling rate or the bit depth of the
recorded data. Professional musicians will often use 48khz data recorded
with 24-bits during the mixing portion of their production. Some will go
as high as 96khz, although as you go higher, the quality to size trade-off
begins to diminish. In order for you to understand what these numbers
mean, let's take a look at what sampling rate and bit depth mean in
relation to audio files.


Sampling Rate - The sampling rate of an audio file is the number
of times per second the audio data is captured. Increasing this
number increases the precision of the data as time goes on.
Bit Depth - This is the maximum size of the numbers that can be
used to store each entry. Increasing this number increases the
precision of the data at any given moment in time.
From this information, you can see that a WAV file's size is a product of
its sampling rate, bit depth, length, and the number of tracks it contains.
Most audio files are mono (1 track) or stereo (2 tracks), although
surround sound systems can have significantly more tracks of data.
About the MP3 File Format
The MP3 file format was first released in 1993 by the Moving Pictures
Experts Group, who at the time were most famous for the MPEG video
file format. MP3 is the compressed option between MP3 and WAV.
More specifically MP3 is a lossy compression format. This means that
data from the audio file is thrown out in order to make the file size
smaller. A file format could throw out all of the frequencies in an audio
file that the human ear is incapable of perceiving and shrink the file
some, but MP3 goes further.
MP3 files rely on something called audio masking. The perception of
some frequencies is masked when certain other frequencies are present.
This phenomenon was first discovered in 1984, long before computers
were even a thing. By getting rid of this data where the human
perception is lowered (but not eliminated), MP3s can lower the size of
the file with a small loss in quality. By changing how much of the data
gets eliminated, the trade-off of quality and size can be controlled.
MP3 file quality is measured in bitrate. This is the amount of data that is
allowed per second of audio. The smaller the bitrate, the more data must
be lost. The files can take advantage of intelligent algorithms that will
vary the bitrate as the file is encoded. This means that data can be
preserved when deleting it would lower the quality too much, and
discarded in the parts of the file that would not suffer as much.
Which Is Better?
Now that we've discussed the formats, which formats when the WAV
vs. MP3 battle and when? It should be obvious that WAV files will have
the highest quality. If you absolutely want the highest quality available,
go with WAV. MP3 files, especially those encoded at reasonable
bitrates, can sound almost indistinguishable from the larger files,
however. For most final use scenarios, MP3 files are fine unless you are
the pickiest of audiophiles.
Outside of final use scenarios, however, WAV files begin to be the best
choice. If you compress an audio track to MP3, load it in to be mixed
with another track, and then compress that to MP3, you've compressed
the data twice. In other words, you've degraded the quality twice. If
someone else then loads that track in, makes changes, and saves the file
out as an MP3, the quality is degraded further. This repeats each time the
process repeats. For this reason, an uncompressed format like WAV is
the far better choice for audio files that are still in the editing process.
Once an audio file has been degraded, converting it back to WAV will
not restore the quality.
A source code to convert from Wav to Mp3 (Python) :
Install the module pydub. This is an audio manipulation module for Python. This
module can open many multimedia audio and video formats. You can install this
module with pip.
pip install pydub
You can convert an mp3 file (src) to a wav file (dst) by changing the variable
names.
The mp3 file must exist in the same directory as the program (.py). If you want to
use custom directories, add a path to the filename .
from os import path
from pydub import AudioSegment
# files
src = "transcript.mp3"
dst = "test.wav"
# convert wav to mp3
sound = AudioSegment.from_mp3(src)
sound.export(dst, format="wav")
Run with :
python3 convert.py
Another Code (Python) :
# import required modules
import subprocess
# convert wav to mp3 file
subprocess.call(['ffmpeg', '-i', 'hello.wav',
'converted_to_mp3_file.mp3']
Student name : Omar Adel Fouad Mohamed
Student ID : 213099
Under the supervision of : Dr-Ahmed Youness
Download