Sec 4 - Audio Signal Acquisition - Read&Write Wave - Plot
Sec 4 - Audio Signal Acquisition - Read&Write Wave - Plot
• Audio formats
• Signal parameters
• Wave module
• Plot waveform
• Microphone recording
• Load mp3
Audio processing basics - Audio formats
MP3 (not hi-res):
• Popular,
• lossy compressed format
• ensures small file size but is far from the best sound quality.
• Convenient for storing music on phones and iPods.
WAV (hi-res):
• The standard format in which all CDs are encoded.
• Great sound quality but it's uncompressed, meaning huge file sizes
(especially for hi-res files).
• It has poor metadata support (that is, album artwork, artist and song
title information).
Audio processing basics - Signal parameters
obj =wave.open("example_WAV.wav",'rb’)
frames=obj.readframes(-1)
Audio processing basics - Signal parameters
https://docs.python.org/3/library/wave.html
Audio processing basics - Wave module
readframes(n) :
•If n is positive, it reads up to n frames.
•If n is larger than the available frames, it reads only what's available.
•If n is -1 or omitted, it reads all remaining frames.
frames=obj.readframes(-1)
print(len(frames))
obj.close()
obj_new=wave.open("example_WAV_new.wav","wb")
obj_new.setnchannels(2)
obj_new.setsampwidth(2)
obj_new.setframerate(44100)
obj_new.writeframes(frames) Why is len(frames) ≠ obj.getnframes()?
obj_new.close()
Audio processing basics – task
• Write a python code for reading wave file, then display it’s properties and
calculate the time duration of your file.
• For a stereo, 16-bit, 44.1 kHz WAV file, determine number of frames in one
second and the total size of the audio file.