From eb5733f5a537d16b64d9c314ca9903c3a6341297 Mon Sep 17 00:00:00 2001 From: Lauras5 Date: Mon, 11 Sep 2023 18:31:54 -0700 Subject: [PATCH] needs to be float type for load to work --- .gitignore | 1 + src/capture_audio.py | 3 ++- src/logging_config.py | 3 ++- src/process_audio.py | 8 ++++---- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 16d5987..2eedbdb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /data /logs +src/paths.py # Python __pycache__/ diff --git a/src/capture_audio.py b/src/capture_audio.py index 2d33bb8..bb6ddb5 100644 --- a/src/capture_audio.py +++ b/src/capture_audio.py @@ -4,6 +4,7 @@ import time import sys +from paths import AUDIO_PATH from logging_config import logger # duration in seconds @@ -47,5 +48,5 @@ def capture_audio_to_file(output_file, duration=5, sample_rate=44100, channels=1 # test if __name__ == "__main__": timestr = time.strftime("%Y%m%d_%H%M") - out_filename = f"../data/audio_samples/recorded_audio_{timestr}.wav" + out_filename = f"{AUDIO_PATH}/recorded_audio_{timestr}.wav" capture_audio_to_file(out_filename, duration=5) diff --git a/src/logging_config.py b/src/logging_config.py index 0886f8e..3a145b9 100644 --- a/src/logging_config.py +++ b/src/logging_config.py @@ -1,9 +1,10 @@ import logging import sys import traceback +from paths import DIR_PATH logging.basicConfig( - filename='./logs/error.log', + filename=f'{DIR_PATH}logs/error.log', level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s' ) diff --git a/src/process_audio.py b/src/process_audio.py index c489953..8d02624 100644 --- a/src/process_audio.py +++ b/src/process_audio.py @@ -1,14 +1,14 @@ import librosa import librosa.display +import numpy as np import matplotlib.pyplot as plt from logging_config import logger - +from paths import AUDIO_PATH def process_audio_file(audio_file): try: # Load the audio file - y, sr = librosa.load(audio_file) - + y, sr = librosa.load(audio_file, dtype=np.float32) # Extract audio features (e.g., MFCCs) mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=40) @@ -32,5 +32,5 @@ def process_audio_file(audio_file): if __name__ == "__main__": - recorded_audio_file = "../data/audio_samples/recorded_audio_20230911_1655.wav" + recorded_audio_file = f"{AUDIO_PATH}recorded_audio_20230911_1655.wav" process_audio_file(recorded_audio_file)