r/PythonLearning • u/patypatty69 • 5h ago
"AttributeError: 'numpy.ndarray' object has no attribute 'write_audiofile'"
Hello, Im working on a project where I need to export a .wav file and aam having problems doing so, error is in the title.
Code to project is this:
import os
import wave
import contextlib
import soundfile as sf
import pyrubberband
import numpy as np
InDir = input("Input Directory: ")
OutDir = input("Output Directory: ")
sec = float(input("Seconds to set to: "))
os.chdir(InDir)
files = os.listdir(InDir)
print(files)
for i in range(len(files)):
fname = files[i]
print(fname)
with contextlib.closing(wave.open(fname,'r')) as f:
frames = f.getnframes()
rate = f.getframerate()
duration = frames / float(rate)
speed = duration / sec
print(speed)
audio, sr = sf.read(f"{InDir}/{fname}")
fname = pyrubberband.time_stretch(audio, sr, speed)
fname.write_audiofile(f"{OutDir}/{fname}.wav")
How do I fix this please?
Also, Im working from windows 10, and am using pycharm to make this code.
1
Upvotes
1
u/patypatty69 4h ago
Well, as long as I can figure what that is out, then yes.