Python, Cómo dividir un archivo .wav en múltiples archivos .wav
Tengo un archivo .wav de varios minutos de duración que me gustaría dividir en diferentes archivos .wav de 10 segundos.
Este es mi código de Python hasta ahora:
import wave
import math
def main(filename, time):
read = wave.open(filename, 'r')
#get sample rate
frameRate = read.getframerate()
#get number of frames
numFrames = read.getnframes()
#get duration
duration = numFrames/frameRate
#get all frames as a string of bytes
frames = read.readframes(numFrames)
#get 1 frame as a string of bytes
oneFrame = read.readframes(1)
#framerate*time == numframesneeded
numFramesNeeded=frameRate*time
#numFramesNeeded*oneFrame=numBytes
numBytes = numFramesNeeded*oneFrame
#splice frames to get a list strings each representing a 'time' length
#wav file
x=0
wavList=[]
while x+time<=duration:
curFrame= frames[x:x+time]
x=x+time
wavList.append(curFrame)
Imprimir "wavList" produce:
['\ x00 \ x00 \ x00 \ x00 \ xff \ xff \ x00 \ x00 \ x00 \ x00', '\ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00', '\ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 ',' \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 ',' \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 ']
Sé que esta es una lista de marcos. ¿Cómo hago un archivo wav para cada elemento en esta lista (el primer archivo .wav sería '\ x00 \ x00 \ x00 \ x00 \ xff \ xff \ x00 \ x00 \ x00 \ x00')? Pythonwave
El módulo no está claro sobre el uso de marcos para crear archivos .wav.
EDITAR: Esta es una pregunta duplicada de¿Cómo empalmar un archivo de audio (formato wav) en empalmes de 1 segundo en python? Sin embargo, si alguien tiene una respuesta que no requierepydub
Me gustaría mucho verlo.