From 73ca1e6935d4269df4aad5da923dc01a61aafc43 Mon Sep 17 00:00:00 2001 From: grabowski Date: Mon, 27 Oct 2025 13:09:09 +0700 Subject: [PATCH] Fix file path bug in resample_audio.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed from os.rename() to shutil.copy2() when creating backups. This prevents the "No such file or directory" error that occurred when trying to write the resampled file after the original was renamed. Now the script: - Copies original to .backup (instead of renaming) - Reads from .backup file - Writes resampled audio to original filename 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- resample_audio.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/resample_audio.py b/resample_audio.py index 4e3c414..9caac14 100644 --- a/resample_audio.py +++ b/resample_audio.py @@ -8,6 +8,7 @@ import wave import numpy as np import os import json +import shutil from scipy import signal def load_config(): @@ -126,16 +127,20 @@ def main(): # Create backup backup_path = input_path + '.backup' + source_path = input_path + if not os.path.exists(backup_path): - os.rename(input_path, backup_path) + # Copy to backup instead of rename, so original still exists + shutil.copy2(input_path, backup_path) print(f" Backup created: {filename}.backup") + source_path = backup_path else: - input_path = backup_path print(f" Using existing backup") + source_path = backup_path # Resample output_path = os.path.join(sounds_dir, filename) - if resample_wav(input_path, output_path, target_rate): + if resample_wav(source_path, output_path, target_rate): print(f" ✓ Successfully resampled to {target_rate}Hz") else: print(f" ✗ Failed to resample, restoring backup")