spectrographic
spectrographic copied to clipboard
AttributeError: 'PosixPath' object has no attribute 'write'
as you stated in the readme file: in the standalone dir, i used this code:
python spectrographic.py --image ./source.png --min_freq 10000 --max_freq 20000 --duration 10 --save sound.wav --play
and i am able to hear the output audio successfully, but after the audio playback finishes, i receive this error in terminal:
Traceback (most recent call last): File "spectrographic.py", line 457, in <module> run() File "spectrographic.py", line 453, in run main(sys.argv[1:]) File "spectrographic.py", line 447, in main sg.save(wav_file=args.save_file) File "spectrographic.py", line 173, in save wavio.write(wav_file, self.sound_array, self.SAMPLE_RATE) File "/home/mohamed/.local/lib/python3.8/site-packages/wavio.py", line 390, in write w.writeframes(wavdata) File "/usr/lib/python3.8/wave.py", line 438, in writeframes self.writeframesraw(data) File "/usr/lib/python3.8/wave.py", line 427, in writeframesraw self._ensure_header_written(len(data)) File "/usr/lib/python3.8/wave.py", line 468, in _ensure_header_written self._write_header(datasize) File "/usr/lib/python3.8/wave.py", line 472, in _write_header self._file.write(b'RIFF') AttributeError: 'PosixPath' object has no attribute 'write' Exception ignored in: <function Wave_write.__del__ at 0x7fd831e82820> Traceback (most recent call last): File "/usr/lib/python3.8/wave.py", line 327, in __del__ self.close() File "/usr/lib/python3.8/wave.py", line 445, in close self._ensure_header_written(0) File "/usr/lib/python3.8/wave.py", line 468, in _ensure_header_written self._write_header(datasize) File "/usr/lib/python3.8/wave.py", line 472, in _write_header self._file.write(b'RIFF') AttributeError: 'PosixPath' object has no attribute 'write'
Replace:
def parse_args(args):
...
parser.add_argument(
"-s",
"--save",
dest="save_file",
help="Path to .wav file in which to save the SpectroGraphic.",
action="store",
default=Path("SoundGraphic.wav"),
to
default="SoundGraphic.wav",