Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Encoding audio data
#1
Hello, I want to be able to read the contents of a .wav file, decode it into a list of ints, analyse it/modify it, and then encode it and save it back as another .wav file. I can load and decode it so far, but I can't figure out how to encode it again. I was thinking something like
int.to_bytes()
Here's my code:
#!/usr/bin/env python3

import wave, pyaudio, soundfile

filename = 'testfile.wav'
file = wave.open(filename, 'rb')
c, ss, fr, f, ct, cn = file.getparams()
frames = file.readframes(c * ss * f)
data = []
for i in range(len(frames)):
    item = int.from_bytes(frames[i:i + 1], byteorder='little', signed=True)
    data.append(item)
-707
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Who converts data when writing to a database with an encoding different from utf8? AlekseyPython 1 2,362 Mar-04-2019, 08:26 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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