Python Forum
From theory to practice
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
From theory to practice
#11
A .wav file (as well as most other audio and images actually) consists of two main parts, a header and the actual data.  For a .wav file  the 'header' is 44 bytes (0 - 43) and the data is the remainder of the file (bytes 44 - end).  The 'header' is further divided into 'file' and 'format' bytes (chunks). The following is something I wrote to 'read' that information.  It's some what long as I included a lot of comments. It only requires the built-in struct module.  This is based on the information provided here: .WAV format.  Hope this help you in understanding what's going on 'under the hood'

the output:
Output:
C:\Python36\python.exe C:/Python/Sound/read_wave.py .WAV File information for  SineWave_440Hz.wav ===============================================================================  File ID: RIFF  File Size: 264644  File Type: WAVE  File Format: fmt   Length of Format Data: 16 Type of Format: PCM (Uncompressed)  Number of Channels: 1  Sample Rate: 44100  Byte Rate: 88200  Block Align: 2 Bits Per Sample: 16  Data Header: data  Size of Data Section: 264600 Process finished with exit code 0
I did not include the actual data, but concept remains the same.  Just 'seek(44), read the appropriate bits per sample (i.e . 8, 16, 24, 32) then unpack it.  Writing the file is pretty much just the reverse, except you 'pack' instead of 'unpack'.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Messages In This Thread
From theory to practice - by bertibott - Feb-24-2017, 01:12 PM
RE: From theory to practice - by stranac - Feb-24-2017, 01:51 PM
RE: From theory to practice - by zivoni - Feb-24-2017, 02:19 PM
RE: From theory to practice - by bertibott - Feb-24-2017, 03:53 PM
RE: From theory to practice - by zivoni - Feb-24-2017, 04:55 PM
RE: From theory to practice - by Mekire - Feb-24-2017, 04:36 PM
RE: From theory to practice - by bertibott - Feb-24-2017, 04:51 PM
RE: From theory to practice - by zivoni - Feb-24-2017, 05:22 PM
RE: From theory to practice - by Mekire - Feb-24-2017, 05:07 PM
RE: From theory to practice - by bertibott - Feb-24-2017, 05:46 PM
RE: From theory to practice - by sparkz_alot - Feb-24-2017, 08:32 PM
RE: From theory to practice - by zivoni - Feb-24-2017, 09:37 PM
RE: From theory to practice - by sparkz_alot - Feb-25-2017, 12:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  .xls processing with Pandas - my struggle moving from theory to practical use prolle 0 1,562 May-21-2020, 06:57 PM
Last Post: prolle
  Help with Data Match Theory randor 2 2,042 Dec-25-2019, 05:57 PM
Last Post: randor

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020