Skip to content

Commit

Permalink
fixed sample rate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjoyce committed Apr 4, 2024
1 parent fa4aead commit e0f9664
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
27 changes: 27 additions & 0 deletions config-48hz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
audio_visualization:
audio_visual_span: 1
cmap: magma
max_spectrogram_width: 65000
playhead_position: 0.5 # Centered horizontally
playhead_rgba: [255,255,255,192] # white, slightly transparent
playhead_width: 2 # Assuming pixels for thick
playhead_section_rgba : [0,0,0,0]
seconds_in_view: 300
profiling_chunk_duration: 900
mel_spectrogram:
db_high: 0
db_low: -80
f_high: 22000
f_low: 20
hop_length: 512
n_fft: 2048
n_mels: 400
video:
frame_rate: 30
height: 200
width: 800
overlays:
frequency_axis:
freq_hz : [100, 1000, 3000, 5000, 8000]
axis_position: 0.5 # Centered horizontally
axis_rgba: [255,255,255,192] # white, slightly transparent
13 changes: 10 additions & 3 deletions melspec-to-video.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def load_and_resample_mono(params: Params) -> Tuple[np.ndarray, int]:
start_time = params.get("start_time", 0)
duration = params.get("duration", None)
audio_fsp = params["input"]
sample_rate = params["sr"]
sample_rate = params.get("sr", None)

# Determine the total duration of the audio file if duration is not explicitly provided
if duration is None:
Expand Down Expand Up @@ -198,7 +198,8 @@ def profile_audio(params: Params) -> dict[str, Any]:

audio_fsp = params["input"]
logging.info(f"Audio file in: {audio_fsp}")
target_sr = params["sr"]

target_sr = params.get("sr", None)
logging.info(f"Target Sample Rate: {target_sr}")

# Configuration for Mel spectrogram
Expand Down Expand Up @@ -268,7 +269,9 @@ def generate_spectrograms(
max_spectrogram_width = audiovis.get("max_spectrogram_width", 1000)
logging.info(f"max_spectrogram_width: {max_spectrogram_width}")

target_sample_rate = params["sr"]
target_sample_rate = params.get("sr", None)
if not target_sample_rate:
target_sample_rate = project["audio_metadata"].get("sample_rate", 22050)

samples_per_pixel = (audiovis["seconds_in_view"] * target_sample_rate) / video[
"width"
Expand Down Expand Up @@ -752,6 +755,7 @@ def main():
"--sr",
help="Audio sample rate. Overrides the source sample rate.",
type=int,
default=None,
)

parser.add_argument(
Expand All @@ -771,6 +775,9 @@ def main():
default="output.mp4",
)

# we default bool args to None, so they are falsy but not == False
# if it was False the defautl behavioir or argparse, it would always overwrite config yaml

parser.add_argument(
"--overwrite",
action="store_true",
Expand Down

0 comments on commit e0f9664

Please sign in to comment.