Open Kayda opened 4 weeks ago
This likely no longer works because of changes in Python 3. I've written a version that works with Python 3.x:
`#this code unpacks and repacks data from:
import wave import math import struct
fileName = "test.wav" #file to be imported (change this) print("Converting " + fileName)
w = wave.open(fileName, 'rb')#updated to bytes in python3
samplewidth = w.getsampwidth() print("Sample width in bytes: " + str(samplewidth))
framerate = w.getframerate() print ("Frame rate / sampling frequency (target: 44100): " + str(framerate))
numframes = w.getnframes() print ("Total number of frames in .WAV file: " + str(numframes))
numchannels = w.getnchannels() print ("Channels (1-mono, 2-stereo): " + str(numchannels)) offset = numchannels * samplewidth #how many bytes to skip to separate the channels
print("Progress")
frame = w.readframes(numframes) framelist = list(frame) print (".")
monochannelbytes1 = framelist[:numframes:offset] #first of two-byte pair per channel monochannelbytes2 = framelist[1:numframes:offset] #second of two-byte pair per channel print (".")
byte2shift = [i*2**8 for i in monochannelbytes2] print (".")
combinedmonochannel = [x + y for x, y in zip(monochannelbytes1,byte2shift)] print (".")
audiotext = [x - 216 if x > 215 else 0 if x == 2**15 else x for x in combinedmonochannel] print (".")
import csv #python library for creating csv files from python data types
textfilename = fileName[:-3] + "txt" #replace wav with txt with open(textfilename, 'w') as f:
textfile = csv.writer(f)
# Write data to the CSV file
textfile.writerow(audiotext)
f.close() print ("---------") print ("wav2txt complete for " + textfilename)`
I understand this is quite an old repo, but I don't seem to be able to convert the .wav to a text file. the command line pops up and then disappeard but I'm not getting any confirmation or error showing. And no .txt file is appearing.