0% found this document useful (0 votes)
17 views9 pages

Sound Processing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views9 pages

Sound Processing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Sound

processing
Learning Objectives:
- use commands of the Wave library to process
sound files.
Discussion:

Name the physical


characteristics of the
What is sound in sound Wave library in Pyhon
nature?
Try and
analyze
the piece
of code
wave.open()
This function opens a file to read/write audio data. The
function needs two parameters - first the file name and
second the mode. The mode can be 'wb' for writing audio
data or 'rb' for reading.
obj = wave.open('sound.wav','wb')
Wave_write object has following methods
close() Close the file if it was opened by wave.
setnchannels() Set the number of channels. 1 for Mono 2 for stereo channels
setsampwidth() Set the sample width to n bytes.
setframerate() Set the frame rate to n.
setnframes() Set the number of frames to n.

setcomptype() Set the compression type and description. At the moment, only
compression type NONE is supported, meaning no compression.

setparams() accepts parameter tuple (nchannels, sampwidth, framerate, nframes,


comptype, compname)
tell() Retrieves current position in the file
writeframesraw() Write audio frames, without correcting.
writeframes() Write audio frames and make sure they are correct.
Wave_read object methods

close() Close the stream if it was opened by wave module.


getnchannels() Returns number of audio channels (1 for mono, 2 for stereo).
getsampwidth() Returns sample width in bytes.
getframerate() Returns sampling frequency.
getnframes() Returns number of audio frames.
getcomptype() Returns compression type ('NONE' is the only supported type).

getparams() Returns a namedtuple() (nchannels, sampwidth, framerate, nframes,


comptype, compname), equivalent to output of the get*() methods.

readframes(n) Reads and returns at most n frames of audio, as a bytes object.


rewind() Rewind the file pointer to the beginning of the audio stream.
Following code reads some of the parameters of WAV file.
Useful links

• https://www.tutorialspoint.com/read-and-write-wav-files-using-python-wa
ve
• https://www.youtube.com/watch?v=n2FKsPt83_A&t=120s&ab_channel=A
ssemblyAI

• 10 Python Libraries for Audio Processing (clouddevs.com)

• https://www.bzfar.org/publ/algorithms_programming/a
lgorithms/python_wave_library_sound_processing/56-
1-0-203

You might also like