0% found this document useful (0 votes)
9 views

Programming 1 Term 7 Lesson

Uploaded by

abenovsanzhar
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)
9 views

Programming 1 Term 7 Lesson

Uploaded by

abenovsanzhar
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/ 24

SOUND PROCESSING

12. 6.3.1 USE COMMANDS OF THE WAVE LIBRARY TO PROCESS


SOUND FILES
WAVE LIBRARY

• The wave module provides a convenient interface to the WAV audio


format. It does not support compression/decompression, but it does
support mono/stereo.
• To open a *.wav file, use the function open()
• wave.open(filename, mode=None)
• filename - *.wav file which is in the *.py file directory.
WAVE LIBRARY

• mode='rb' - режим только


для чтения.
mode = 'wb' - режим
только записи.
WAVE LIBRARY

• Download
• in.wav

wave.close() - close *.wav


file.
• source.close()
dest.close()
WAVE LIBRARY

• to pass parameters from read file to write file use...


Audio sampling is the process of transforming a
musical source into a digital file. Digital audio
recording does this by taking samples of the audio
source along the soundwaves at regular intervals.
• An audio frame, or sample, contains
amplitude (loudness) information at
that particular point in time. To produce
sound, tens of thousands of frames are
played in sequence to produce
frequencies.
WAVE LIBRARY

• Frames of *.wav file


• To get all the frames from an audio file, use
the getnframes() function
WAVE LIBRARY

• Read frames in *.wav file


• wave.readframes(wave.getnframes()) # read all frames from *.wav
file.
WAVE LIBRARY

• Get information about wav-file


• You can use:
STRUCT LIBRARY

• struct library — Interpret bytes as packed binary data


• The pack() and unpack() methods. Packing and unpacking data.
• struct.pack(format, v1, v2, ...)
Return a bytes object containing the values v1, v2, … packed according to the
format string format. Allows you to pack audio fragment frames into a file.
• struct.unpack(format, buffer)
Unpack from the buffer according to string format. Allows you to extract audio
fragment frames to a file. The result is a tuple even if it contains exactly one
item.
TASK " COUNT FRAMES "

Output count frames of file in.wav.


TASK 1

Task "Copy *.wav file" Download in.wav.


Open in program file in.wav and create copy to out.wav.
WORKING ON GOOGLE COLAB
ANSWER:

setparams(tuple)

The tuple should be (nchannels, sampwidth, framerate,


nframes, comptype, compname), with values valid for the
set*() methods. Sets all parameters

getparams()

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


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

writeframes(data)

Write audio frames and make sure nframes is correct. It will


raise an error if the output stream is not seekable and the total
number of frames that have been written after data has been
written does not match the previously set value for nframes.
https://docs.python.org/3/library/wave.html
TASK " HALF SOUND "

Output the first half part of file in.wav.


TASK " REVERSE SOUND "

• Output to the out.wav reverse of file in.wav.


TASK " SPEED UP TWICE "

• Write a program to speed up a file in.wav


twice.
TASK " SLOW DOWN TWICE "

• Write a program to slow down the sound


twice of file in.wav.

You might also like