Fix file path bug in resample_audio.py
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user