Dividir un archivo de audio en piezas de un tamaño arbitrario.

Tengo un archivo de sonido grande (150 MB) que me gustaría dividir en archivos más pequeños de un tamaño más fácil de administrar, por ejemplo, archivos con 5 minutos de audio. Claramente, el último segmento será <= 5 minutos, y eso está bien. ¿Hay una manera de hacer este tipo de tarea fácilmente?

Se puede descargar un pequeño archivo .mp3 de muestra para este problema usando este enlace: download.linnrecords.com/test/mp3/recit.aspx.

Esto es lo que he intentado hasta ahora. Importé los datos usandoreadMP3 desdetuneR y iba a usar elcutw Función, pero no he encontrado una forma eficiente de usarlo.

library(tuneR)

sample<-readMP3("recit.mp3") 

# the file is only 9.04 seconds long (44.1 Hz, 16-bit, sterio)
# so, for this example we can cut it into 0.5 second intervals)
subsamp1<-cutw(sample, from=0, to=0.5, output="Wave")

# then I would have to do this for each interval up to:
subsampn<-cutw(sample, from=9, to=9.04, output="Wave") 
# where I have to explicitly state the maximum second (i.e. 9.04), 
# unless there is a way I don't know of to extract this information.

Este enfoque es ineficiente cuando los intervalos se reducen en comparación con la longitud total del archivo. También,sample era estereo, perosubsamp1 es mono, y prefiero no cambiar nada de los datos si es posible.

En la forma de mejorar la eficiencia, intenté ingresar vectores a lafrom yto argumentos, pero tengo un error (ver más abajo). Sin embargo, aunque hubiera funcionado, no sería una solución particularmente agradable. ¿Alguien sabe de una manera más elegante de abordar este problema usando R?

cutw(subsamp1,from=seq(0,9,0.5),to=c(seq(0.5,9.0,0.5),9.04) 
# had to explicitly supply the max second (i.e. 9.04). 
# must be a better way to extract the maximum second

Error in wave[a:b, ] : subscript out of bounds
In addition: Warning messages:
1: In if (from > to) stop("'from' cannot be superior to 'to'") :
  the condition has length > 1 and only the first element will be used
2: In if (from == 0) { :
  the condition has length > 1 and only the first element will be used
3: In a:b : numerical expression has 19 elements: only the first used

Respuestas a la pregunta(3)

Su respuesta a la pregunta