0

Working from a previous question asked. The main objective is reading a .wav file and specifically skipping the RIFF and other containers and focusing strictly on the data portion of the .wav file contents. The running example is encountering an error for:

AttributeError: 'numpy.ndarray' object has no attribute 'append'

  1. Stemming from a traceback of: new_data = data.append(np.zeros(2 * sr))

However, when changing the below file to try and fix this issue, such as new_data.astype(np.int16), still running into issues.

# ''' From Imports ''' #
from scipy.io.wavfile import write
# ''' Imports ''' #
import numpy as np

# ''' Filename IN '''
fn = 'example.wav'
# ''' Byte Length ''' #
bl = np.fromfile(fn, dtype=np.int32, count=1, offset=40)[0]
# ''' Offset ''' #
data = np.fromfile(fn, dtype=np.int16, count=bl // np.dtype(np.int16).itemsize, offset=44)
# ''' Sample Rate ''' #
sr = np.fromfile(fn, dtype=np.int32, count=1, offset=24)[0]
# ''' New .WAV ''' #
with open('out.wav', 'a') as fout:
    # ''' Appending Two Seconds of 0.0's
    # >> AttributeError: 'numpy.ndarray' object has no attribute 'append'
    # ''' #
    new_data = data.append(np.zeros(2 * sr))
    write(fout, sr, new_data)

# ''' Close File ''' #
fout.close()
# ''' End ''' #

A possible solution approach may be done by replacing the data completely, as such, is this correct?:

By using: write(fout, sr, np.zeros(2 * sr).astype(np.int16)).

Any approaches to fix this solution? Referenced Question: https://stackoverflow.com/a/67455735/8813179

ABC
  • 2,068
  • 1
  • 10
  • 21

1 Answers1

1

ndarray doesn't have a method append, use numpy.append(arr1, arr2)

numpy.append

Phani Pavan
  • 354
  • 3
  • 8